Reputation: 55
In mapbox, how can I show titles on markers? I want them to be always visible not on mousover or mouse click.
Upvotes: 1
Views: 1710
Reputation: 10177
Use popup.addTo(map)
instead of popup.openOn(map)
.
Also, you might want to address closeOnClick
and closeButton
.
var popup = L.popup({closeButton : false, closeOnClick : false})
.setLatLng([tweet.y, tweet.x]) // Or something
.setContent(html)
.addTo(map);
Upvotes: 1
Reputation: 1524
You can open marker popups programmatically using the openPopup
method. Here's how you can do this with a bit of JavaScript, as well as a live demo.
var map = L.mapbox.map('map', 'examples.map-zr0njcqy');
// wait until the markers are loaded, so we know that `map.markerLayer.eachLayer`
// will actually go over each marker
map.markerLayer.on('ready', function(e) {
// when a user clicks the button run the `clickButton` function.
// Thanks to function hoisting in Javascript, we can define the function
// after we reference it here.
document.getElementById('open-popup').onclick = clickButton;
});
function clickButton() {
map.markerLayer.eachLayer(function(marker) {
// you can replace this test for anything else, to choose the right
// marker on which to open a popup. by default, popups are exclusive
// so opening a new one will close all of the others.
marker.openPopup();
});
}
Upvotes: 0