从样式循环遍历图层

时间:2018-10-17 09:26:36

标签: mapbox mapbox-gl-js mapbox-gl

我正在尝试按照以下示例向我的地图添加过滤器:

https://www.mapbox.com/mapbox-gl-js/example/filter-markers/

我的层称为生产者。

但是我没有在代码中添加图层,而是在mapbox网站上添加了图层,这意味着我不能这样写才能遍历图层中的要素:

 producers.features.forEach(function(feature) { ... }

我试图做的是以下事情:

var producers = map.getLayer('producers');

            producers.features.forEach(function (feature) { ... }

geojson文件中的功能如下:

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [
      11.9670171,
      57.7072326
    ]
  },
  "properties": {
    "marker-symbol": "symbol",
    "imageurl": "imageurl",
    "type": "type",
    "kWh": "number",
    "area":  "Place",
    "description": "description",
    "buttonurl":  "url"
  }

我尝试了所有不同版本来访问图层中的不同功能:

producers.features.feature.producers.forEach(function (feature)
producers.features.feature.forEach(function (feature)
producers.features.producers.forEach(function (feature)
producers.features.forEach(function (feature)

但是每次尝试都会导致这种错误:

  

TypeError:producers.features未定义

有人知道我在做什么错吗?

0 个答案:

没有答案