您應該嘗試定義一個函數,該函數會將每行加載到Leaflet中時設置樣式。
從這個鏈接:https://github.com/Dominique92/Leaflet.GeoJSON.Ajax
...
new L.GeoJSON.Ajax(
<URL>, // GeoJson server URL.
{
argsGeoJSON: {
name: value, // GeoJson args pairs that will be added to the url with the syntax: ?name=value&...
...
}
bbox: <boolean>, // Optional: whether or not add bbox arg to the geoJson server URL
style: function(feature) { // Optional
return {
"<NAME>": <VALUE>, // Properties pairs that will overwrite the geoJson flow features properties
"<NAME>": feature.properties.<NAME>, // The value can be calculated from any geoJson property for each features.
...
};
}
}
).addTo(map);
...
這是我的代碼,這是形狀不是線,而是應該以類似的方式工作:
geojson = L.geoJson(myGeoJson.features, {
onEachFeature: onEachFeature,
style: styleFeature,
}).addTo(myLeafletMap);
,然後我具備的功能:
function onEachFeature(feature, layer) {
...
}
和
function styleFeature(feature){
return {
weight: 2.5,
opacity: 1,
color: getColour('blue'),
};
}
來源
2017-03-09 16:41:10
TDP
我錯過了在文檔中。謝謝你指出。 – MakleBirt