Assign ID to marker in leaflet

后端 未结 7 1087
忘了有多久
忘了有多久 2020-12-23 11:47

So i try to achieve a result as on foursquare: https://foursquare.com/explore?cat=drinks&mode=url&near=Paris which is when you clik on a marker on the map, it scrol

7条回答
  •  再見小時候
    2020-12-23 12:35

    Leaflet's className option can allow one to add identifiers to objects:

    var onMouseover = function() {
      // returns all members of the specified class
      d3.selectAll(".mySpecialClass")
        .style("opacity", ".1");
    };
    
    // add desired class to pointer 
    L.circleMarker([46.85, 2.35], {className: "mySpecialClass"})
      .addTo(map).on('mouseover', onMouseover);
    
    // to select the marker(s) with a particular class, just use css selectors
    // here's a d3.js solution
    d3.selectAll(".mySpecialClass")
      .style("opacity", ".3")
    

提交回复
热议问题