我如何提取存储在Mapbox数据集中的URL并将其添加到弹出窗口的'click'函数中?

问题描述 投票:0回答:1

我有一个功能代码,可从“描述”字段中提取数据并在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);

});
mapbox mapbox-gl-js
1个回答
0
投票

要在Popup本身内添加链接,可以将PopupPopup#setHTML标记结合使用以定义超链接。例如:

Popup#setHTML
© www.soinside.com 2019 - 2024. All rights reserved.