2015-12-17 70 views
0

因此,我的腳本文件夾中有兩個單獨的geoJSON文件,一個用於繪製邊界線,另一個用於放置標記。每個GeoJSON的文件有不同的內容,例如:在Mapbox中添加多個geoJSON文件

var putMarkers = { 
    type: 'Feature', 
    "geometry": { "type": "Point", "coordinates": [-77.03, 38.90]}, 
    "properties": { 
     "image": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Cherry_Blossoms_and_Washington_Monument.jpg/320px-Cherry_Blossoms_and_Washington_Monument.jpg", 
    "url": "https://en.wikipedia.org/wiki/Washington,_D.C.", 
    "marker-symbol": "star", 
    "marker-color": "#ff8888", 
    "marker-size": "large", 
    "city": "Washington, D.C." 
    } 
} 

和另一個問題:

var states = {"type":"FeatureCollection","features":[ 
{"type":"Feature","id":"01","properties":{"name":"Alabama"},"geometry":{"type":"Polygon","coordinates":[[[-87.359296,35.00118],[-85.606675,34.984749],[-85.431413,34.124869],[-85.184951,32.859696],[-85.069935,32.580372],[-84.960397,32.421541],[-85.004212,32.322956],[-84.889196,32.262709],[-85.058981,32.13674],[-85.053504,32.01077],[-85.141136,31.840985],[-85.042551,31.539753],[-85.113751,31.27686],[-85.004212,31.003013],[-85.497137,30.997536],[-87.600282,30.997536],[-87.633143,30.86609],[-87.408589,30.674397],[-87.446927,30.510088],[-87.37025,30.427934],[-87.518128,30.280057],[-87.655051,30.247195],[-87.90699,30.411504],[-87.934375,30.657966],[-88.011052,30.685351],[-88.10416,30.499135],[-88.137022,30.318396],[-88.394438,30.367688],[-88.471115,31.895754],[-88.241084,33.796253],[-88.098683,34.891641],[-88.202745,34.995703],[-87.359296,35.00118]]]}}} 

把一個GeoJSON的這種格式的作品,

var geoJson = L.mapbox.featureLayer(states).addTo(map); 

但你如何添加其他以GeoJSON ?

回答

0

,只要你想你可以添加儘可能多的featurelayers:

var stateCollection = {"type": "FeatureCollection", "features": [...]}; 
var countyCollection = {"type": "FeatureCollection", "features": [...]}; 

var stateLayer = L.mapbox.featureLayer(stateCollection).addTo(map); 
var countyLayer = L.mapbox.featureLayer(countyCollection).addTo(map); 

例如在Plunker:http://plnkr.co/edit/lY08pEq3O9UYZrCFrbo8?p=preview (添加自己的訪問令牌進行測試)

+0

感謝,雖然它不工作,但還挺開明我 – kkagill

+0

你一定在做錯事,增加了一個像魅力一樣的例子。 – iH8