Mapbox.js: Bind dynamic popups with featureLayer?

المشرف العام

Administrator
طاقم الإدارة
I am building a multiple chloropleth map using v2.2.1 of Mapbox.js with featureLayer. Now I would like to add tooltips with custom content on hover event.

This code is working well to set up the featurelayer and add styles to each layer:

_this.orgLayer = L.mapbox.featureLayer(null, { pointToLayer: function (feature, latlng) { return L.circleMarker(latlng, { radius: 8, color: "#000", weight: 1, opacity: 1, fillOpacity: 0.97 }); } }) .loadURL(boundsUrl) .addTo(map) .on('ready', joinDataAndSetupMap);...// once data joined and map set up, add styles to each layer.// this gets called at initialization and again when the map is updated. _this.orgLayer.eachLayer(function(layer) { var val = layer.feature.properties.data[month]; var style = _this.getStyle(val); layer.setStyle(style); });But I'm not sure how to bind popups on hover. Could anyone suggest the best way to do this?

The documentation mentions a popupOptions option, but I can't see how to use those to specify dynamic content, or bind the popups to mouseover not click.

Maybe I need to do something inside the eachLayer loop? If so, what?



أكثر...
 
أعلى