标记上的Mapbox标题始终可见

时间:2014-01-21 08:02:10

标签: mapbox

在地图框中,如何在标记上显示标题?我希望它们在mousover或鼠标点击时始终可见。

2 个答案:

答案 0 :(得分:0)

您可以使用openPopup方法以编程方式打开标记弹出窗口。以下是使用JavaScript和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();
    });
}

答案 1 :(得分:0)

使用popup.addTo(map)代替popup.openOn(map)

此外,您可能希望解决closeOnClickcloseButton

var popup = L.popup({closeButton : false, closeOnClick : false})
    .setLatLng([tweet.y, tweet.x])  // Or something
    .setContent(html)
    .addTo(map);
相关问题