![](/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.