想要在Mapbox中添加指向文本的链接,然后由于单击而能够放大

时间:2019-02-26 22:39:41

标签: javascript maps mapbox-gl

我怎么做

  var name = prop.Project_Name;     

我的代码部分是我可以单击的href链接,它会自动缩放,如下面的代码所示。

link.addEventListener("click", function(e){
        console.log(e)
        map.flyTo({
        center:  currentFeature.geometry.coordinates,
        zoom:16,

        });

但是我过去曾经这样做过 我很难将所有内容放在一起。使用新代码并尝试复制旧代码使我比我想要的要复杂得多。

  function renderListings(features) {
  listingEl.innerHTML = '';
  var sortedFeatures = sortedFeatures = features.sort(function (a, b) {
    if (a.properties.Project_Year < b.properties.Project_Year) {
      return 1;
    }

    if (a.properties.Project_Year > b.properties.Project_Year) {
      return -1;
    }

    return a.properties.Project_Name.localeCompare(b.properties.Project_Name);
  });

  if (sortedFeatures.length) {
    sortedFeatures.forEach(function (f) {
      var prop = f.properties;
      var name = prop.Project_Name;
      var date = prop.Project_Year;
      var link = "http://placekitten.com/200/300";
      var card = ppgcard(name, date, link);
      listingEl.innerHTML += card;
    });
  } else {
    var empty = document.createElement('p');
    empty.textContent = 'No records currently in view';
    listingEl.appendChild(empty);
    ppg_map.setFilter('point_layer', ['has', 'Project_Name']);

    var named=document.createElement('a');
    named.href='#';
    named.innerHTML=prop.Project_Name;
  }
};

0 个答案:

没有答案