尝试将GeoJson 加载到我的地图时出现 400 错误。
该文件位于我的 src/assets 文件夹中。如果我在该文件夹中放置了一个不同的文件,我可以在启动 ng 服务器时通过 http 请求访问它,这意味着我应该可以访问这些文件。但是对于我在 loadGeoJson 方法调用中指定的文件,如果我尝试在浏览器中显示它,浏览
http://localhost:4200/assets/sample-farms.geojson
器会显示我的应用程序的主屏幕......
所以发生了一些奇怪的重定向?
这是我的代码:
import { analyzeAndValidateNgModules } from '@angular/compiler';
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
})
export class AppComponent {
title = 'simple-gmaps-demo';
map: any; // important to declare the type of property map, so we can refer to it with this.map
features: any; // Do I need this too?
onMapReady(map: google.maps.Map) {
this.map = map;
this.map.setCenter({lat:-32.910, lng:117.133});
this.map.setZoom(10);
// Error in this method call?
this.map.data.loadGeoJson('http://localhost:4200/assets/sample-farms.geojson', {},
function (features: any) {
console.log(features);
});
}
}
这是我在控制台中得到的错误:
zone-evergreen.js:2845 GET http://localhost:4200/assets/sample-farms.geojson 404 (Not Found)
非常感谢任何帮助。