传单:从geojson“属性”创建图层?

0 layer geojson leaflet

我刚接触地图,我已经开始按照http://leafletjs.com上的文档和教程创建我的地图。到目前为止一切顺利,我已经设法创建了一张地图,从 geojson.io 添加了大量 geosjon 数据,在弹出窗口中显示“popupContent”。它有效。

但我无法理解如何创建几个图层来对所有这些标记进行排序。我想要的是太使用“属性”来做到这一点。我有名为“status”的属性,其值为“done”、“new”和“active”。

像这样:

"type": "Feature",
  "properties": {
    "popupContent": "content",
    "marker-color": "#FFFFFF",
    "title": "title of project",
    "status": "active
Run Code Online (Sandbox Code Playgroud)

那可能吗?根据“状态”属性创建 3 个图层?

如果您需要查看 html 文件,请说出来,我可以添加它。

谢谢

nat*_*der 6

您可以使用该filter选项L.geoJson创建基于特征特性,分层。只需指定一个函数,该函数将为true您希望包含在每一层中的特征返回:

var activeLayer = L.geoJson(yourGeoJson, {
  filter: function(feature, layer) {
    return (feature.properties.status === "active");
  }
}).addTo(map);

var newLayer = L.geoJson(yourGeoJson, {
  filter: function(feature, layer) {
    return (feature.properties.status === "new");
  }
}).addTo(map);

var doneLayer = L.geoJson(yourGeoJson, {
  filter: function(feature, layer) {
    return (feature.properties.status === "done");
  }
}).addTo(map);
Run Code Online (Sandbox Code Playgroud)