2017-10-06 58 views
0

我試圖模擬城市交通運動(目前我只進入車輛),但我有一個問題。複製點層仿真

發生了什麼是我試圖在地圖上模擬每個點的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

回答

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 
     ] 
     } 
    } 
    ] 
} 
+0

我不明白。我是否有一系列要點分開處理它們,或者它們如何處理?(你能舉個例子嗎?)謝謝你的回答! – EpsilonZ

+0

我來看看,謝謝! – EpsilonZ

+0

當你提到添加你的GeoJSON數據源時,你的意思是創建antoher文件並做類似的事情? map.addSource('points',{ 「type」:「geojson」, 「data」:filegeojson }); – EpsilonZ