我有一个功能代码,可从“描述”字段中提取数据并在mouseenter上的弹出窗口中显示数据,但是有人可以帮助我弄清楚如何提取存储在“ linkurl”中的URL并使用它来打开该URL单击图标时?弹出窗口会在图标上正确显示,但是我无法弄清楚如何将URL作为单击后的链接引入。这是我正在使用的代码:
map.on('load', function() {
// Create a popup, but don't add it to the map yet.
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
// POINTS OF INTEREST
function showPopup(e) {
// Updates the cursor to a hand (interactivity)
map.getCanvas().style.cursor = 'pointer';
// Show the popup at the coordinates with some data
popup
.setLngLat(e.features[0].geometry.coordinates)
.setHTML(checkEmpty(e.features[0].properties.description))
.addTo(map);
}
function hidePopup() {
map.getCanvas().style.cursor = '';
popup.remove();
}
function checkEmpty(info) {
return (info) ? info : "No data";
}
// CHANGE: Add layer names that need to be interactive
map.on('mouseenter', 'points-of-interest-2019', showPopup);
map.on('mouseleave', 'points-of-interest-2019', hidePopup);
});
要在Popup
本身内添加链接,可以将Popup
与Popup#setHTML
标记结合使用以定义超链接。例如:
Popup#setHTML