Mapbox title on markers always visible

牧云@^-^@ 提交于 2019-12-24 12:01:56

问题


In mapbox, how can I show titles on markers? I want them to be always visible not on mousover or mouse click.


回答1:


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);



回答2:


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();
    });
}


来源:https://stackoverflow.com/questions/21252330/mapbox-title-on-markers-always-visible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!