Leaflet/Omnivore - 带有自定义弹出窗口的多个 GPX 轨道

问题描述

我尝试在地图上显示多个 GPX 轨迹,并使用一些自定义数据将单个弹出窗口绑定到它们。但我不确定如何将诸如 IdDescription 之类的自定义属性传递给 onEachFeature

用于加载具有某些属性和 GPX 文件路径的 JSON 的代码

var tours = JSON.parse('{"tourdata":[{"tourid" : 1,"desc": "nice tour 1","gpxFileName" : "./1.gpx"},{"tourid" : 3,"desc": "nice tour 2","gpxFileName" : "./3.gpx"}]}');
for (var i = 0; i < tours.tourdata.length; i++) {
  var tour = tours.tourdata[i]; 
  var gpxLayer = omnivore.gpx(tour.gpxFileName,null,customLayer).addTo(map);  
  /*
     how can I pass here the tour.desc and tour.id?
     gpxLayer.properties.desc = tour.desc; // doesn't work
  */
}

自定义图层:

var customLayer = L.geoJson(null,{
  style: function (feature) {
    return { color: '#f00',weight: 2 };
  },onEachFeature: onEachGpxFeature
});

onEachGpxFeature:

function onEachGpxFeature(feature,layer) {
  /* how to access custom properties here? */
  var popupContent = "<p>";
  if (feature.properties) {
    if(feature.properties.name) {
      popupContent += "<br /><b>Name:</b>" + feature.properties.name;
    }
    if(feature.properties.desc) {
      popupContent += "<br /><b>Description:</b>" + feature.properties.desc;
    }
  }
  popupContent += "</p>";
  layer.bindPopup(popupContent);  
}    

我只能访问由杂食动物解析的标准 GPX 属性

这是我的完整演示代码https://plnkr.co/edit/v0BeshnKSx6sPqA1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...