[英]LeafletJS invalid GeoJSON object
I'm working with Leaflet trying to get some GeoJSON going. 我正在与Leaflet一起尝试使一些GeoJSON正常运行。 Everything fine, map is working, but in DevTools console i have an error with invalid GeoJSON. 一切正常,地图可以正常工作,但是在DevTools控制台中,我遇到了无效的GeoJSON错误。 My component is: 我的组件是:
I have getRegionsGeoJson, which return to me geoJSON from some url. 我有getRegionsGeoJson,它通过一些网址返回给我geoJSON。
My DevTools Console 我的DevTools控制台
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
factory expects its first argument to be your GeoJSON data, or null if you will be providing it later with addData
method. L.geoJSON
工厂期望它的第一个参数是您的GeoJSON数据,如果以后要为它提供addData
方法,则它为null。
The error you see is because it tries to interpret your optuons object as a GeoJSON objetc, and obviously fails. 您看到的错误是因为它试图将Optuons对象解释为GeoJSON objetc,并且显然失败了。
Solution: 解:
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.