I'm using mapbox.js to generate a layer which contains a marker and a popup. I am, at a certain interval, programmatically zooming to that marker and displaying the popup. However, I want to disable the "closeOnClick" functionality of the popup, but if I set it after creating the the featureLayer, it has no effect. Anyone know how to properly do this? Here's my code:
eventMarkerLayer = L.mapbox.featureLayer({ //add the event marker
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [eventPt.lng,eventPt.lat]
},
properties: {
title:eventScenario.text,
'marker-color': eventColor
},
options: {
popupOptions: {
closeOnClick: false //doesn't work
}
}
}).addTo(map);
eventMarkerLayer.options.popupOptions.closeOnClick = false; //doesn't work either
eventMarkerLayer.openPopup();
Default popup behavior only allows you to open one feature at a time, so you have to add the popups manually using L.popup()
:
eventMarkerLayer = L.mapbox.featureLayer({ //add the event marker
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [eventPt.lng,eventPt.lat]
},
properties: {
popupContent: eventScenario.text, // note -- change "title" to another name
'marker-color': eventColor
}
}).addTo(map);
eventMarkerLayer.eachLayer(function(layer) {
var popup = L.popup({
closeOnClick: false, // keeps popups open
offset: L.point(0, -25) // offset so popup shows up above marker
})
.setLatLng([layer.feature.geometry.coordinates[1], layer.feature.geometry.coordinates[0]]) // L.popup takes [lat, lng]
.setContent(layer.feature.properties.popupContent); // add content from feature
map.addLayer(popup); // add to map
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.