用于模拟的复制点层

时间:2017-10-06 19:25:16

标签: javascript mapbox-gl-js turfjs

我试图模拟城市交通流量(目前我只是进入车辆),但我遇到了问题。

我在地图上尝试模拟每个点1个车的情况会发生什么,但我不知道如何复制某个图层(并且每个图层都有不同的路径),例如之一:

map.addSource('point', {
    "type": "geojson",
    "data": pointOnCircle(0)
});

map.addLayer({
    "id": "point",
    "source": "point",
    "type": "circle",
    "paint": {
        "circle-radius": 10,
        "circle-color": "#007cbf"
    }
});

我不知道我是否可以循环并生成具有不同名称的N个点或以其他方式执行。

这是我迄今为止所做的事情的视频(为了模拟它,我创建了2个不同的图层,因为我不知道如何复制它们):

https://www.youtube.com/watch?v=xWZD9aBUFlg

1 个答案:

答案 0 :(得分:0)

您应该将所有要点放在一个数据层中:

map.addSource('points', {
    "type": "geojson",
    "data": pointsOnCircle(0) // change this function to return multiple features
});

map.addLayer({
    "id": "points",
    "source": "points",
    "type": "circle",
    "paint": {
        "circle-radius": 10,
        "circle-color": "#007cbf" // possibly make this a data-driven function
    }
});

您的GeoJSON数据源如下所示:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [
          146.25,
          -37.16031654673676
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [
          138.515625,
          35.460669951495305
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [
          -81.5625,
          33.43144133557529
        ]
      }
    }
  ]
}