Angular/ionic 加载ArcGIS API for JavaScrip
前言
在做+/ 加载 API for ,出现以下错误:
如何在项目中使用 API for 请参考:
API for 加载代码:
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-的说明,导致报错的原因是因为当前项目中的esri-的版本过高。
官方给出的说明
解决方法
截止到当前
在执行 npm --save -esri- esri-
安装的-esri- 和esri-版本是
方法一:选择降低esri-的版本,使用当前已有代码
降低esri-版本
npm uninstall --save esri-loader
npm cache clean -f
npm install --save esri-loader@1.0.0
方法二:保留当前esri-load版本,升级现有代码(需要加载 模块)
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 errorsconsole.error(err);
});
具体详见npm esri- :