前言
在做ionic3+/Angular 加载ArcGIS API for JavaScript,出现以下错误:
如何在Angular项目中使用ArcGIS API for JavaScript请参考:https://blog.csdn.net/idomyway/article/details/79717710
ArcGIS API for JavaScript加载代码:
return this.esriLoaderService.load({
//ArcGIS API地址
url:"http://localhost:8080/arcgis_js_api/library/3.20/3.20/init.js"
}).then(()=>{
this.esriLoaderService.loadModules([
"esri/map",
"esri/layers/ArcGISTiledMapServiceLayer"
]).then(([Map,ArcGISTiledMapServiceLayer])=>{
this.map = new Map("mapDiv");
let layerUrl = new ArcGISTiledMapServiceLayer("http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer");
this.map.addLayer(layerUrl);
})
})
错误原因:
通过阅读npm上esri-loader的说明,导致报错的原因是因为当前项目中的esri-loader的版本过高。
官方给出的说明
解决方法
截止到当前
在执行 npm install --save angular2-esri-loader esri-loader
安装的angular2-esri-loader
和esri-loader
版本是
方法一:选择降低esri-loader
的版本,使用当前已有代码
降低esri-loader版本
npm uninstall --save esri-loader
npm cache clean -f
npm install --save esri-loader@1.0.0
方法二:保留当前esri-load版本,升级现有代码(需要加载esriLoader
模块)
const options = {
url: "http://localhost:8080/arcgis_js_api/library/3.20/3.20/init.js"
};
esriLoader.loadModules(['esri/map'], options)
.then(([Map]) => {
// create map with the given options at a DOM node w/ id 'mapNode'
let map = new Map('mapNode', {
center: [-118, 34.5],
zoom: 8,
basemap: 'dark-gray'
});
})
.catch(err => {
// handle any script or module loading errors
console.error(err);
});
具体详见npm esri-loader :https://www.npmjs.com/package/esri-loader