繁体   English   中英

LeafletJS无效的GeoJSON对象

[英]LeafletJS invalid GeoJSON object

我正在与Leaflet一起尝试使一些GeoJSON正常运行。 一切正常,地图可以正常工作,但是在DevTools控制台中,我遇到了无效的GeoJSON错误。 我的组件是:

我有getRegionsGeoJson,它通过一些网址返回给我geoJSON。

我的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工厂期望它的第一个参数是您的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM