![](/img/trans.png)
[英]Angular2-Leafletjs: Defining style for L.geoJSON().addTo(myMap)
[英]LeafletJS invalid GeoJSON object
我正在與Leaflet一起嘗試使一些GeoJSON正常運行。 一切正常,地圖可以正常工作,但是在DevTools控制台中,我遇到了無效的GeoJSON錯誤。 我的組件是:
我有getRegionsGeoJson,它通過一些網址返回給我geoJSON。
ngOnInit() {
this.regionsGeoJsonSubscription$ = this.mapService.getRegionsGeoJson()
.subscribe(regionsGeoJson => {
this.regionsGeoJson = regionsGeoJson;
this.regionsGeoJsonLoaded = Object.keys(this.regionsGeoJson).length > 0;
this.statisticsEnabled = true;
this.hidePreloader();
}
);
// LeafletJS map init
this.map = L.map('map')
.setView([-25.441105, -49.276855], 13);
L.tileLayer
.provider('OpenStreetMap.Mapnik')
.addTo(this.map);
L.geoJSON( {
style: function (feature) {
return {color: feature.properties.color};
}
}).bindPopup(function (layer) {
return layer.feature.properties.description;
}).addTo(this.map);
}
hidePreloader() {
this.preloader.nativeElement.style.display = 'none';
}
}
L.geoJSON
工廠期望它的第一個參數是您的GeoJSON數據,如果以后要為它提供addData
方法,則它為null。
您看到的錯誤是因為它試圖將Optuons對象解釋為GeoJSON objetc,並且顯然失敗了。
解:
L.geoJSON(this.regionsGeoJson <-- solution {
style: function (feature) {
return {color: feature.properties.color};
}
}).bindPopup(function (layer) {
return layer.feature.properties.description;
}).addTo(this.map);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.