传单:从 geojson "properties" 创建图层?

Leaflet: Create layers from geojson "properties"?

我是地图新手,我已经开始按照 http://leafletjs.com 上的文档和教程创建我的地图。到目前为止一切顺利,我已经设法创建了一个地图,添加了来自 geojson.io 的大量 geosjon 数据,这些数据在弹出窗口中显示 "popupContent"。它有效。

但我不明白如何创建几个图层来对所有这些标记进行排序。我想要的是也使用 "properties" 来做到这一点。我有名为 "status" 的属性,其值为 "done"、"new" 和 "active"。

像这样:

"type": "Feature",
  "properties": {
    "popupContent": "content",
    "marker-color": "#FFFFFF",
    "title": "title of project",
    "status": "active

这可能吗?要根据 "status" 属性创建 3 层?

如果需要html文件看,说出来,我可以加上。

谢谢

您可以使用 L.geoJsonfilter option 根据要素属性创建单独的图层。只需指定一个函数,它将 return 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);