Hide/Show layerGroups in Leaflet with own Buttons

前端 未结 2 565
孤街浪徒
孤街浪徒 2021-01-02 06:41

I have a leaflet map with several markers in it. I\'ve put these markers in \"Layer Groups\" to be able to show and hide the marker-categories. These are my markers:

<
2条回答
  •  醉话见心
    2021-01-02 07:01

    First you need a link for each layer

    
    

    Then, for each link you can write a handler like this (example with jQuery)

    $("#restaurants").click(function(event) {
        event.preventDefault();
        if(map.hasLayer(restaurants)) {
            $(this).removeClass('selected');
            map.removeLayer(restaurants);
        } else {
            map.addLayer(restaurants);        
            $(this).addClass('selected');
       }
    });
    

    You have an example here http://jsfiddle.net/FranceImage/c5Yfb/

提交回复
热议问题