我正在使用Argis 4.8 JS api开发角度应用程序。我需要Dojo / On功能。我在编译器中也没有收到错误。但是,当我编译时,出现错误“找不到模块:错误:无法解析'dojo / on'路径”。我不能使用Dojo类。我该怎么办?
我的完整代码
import {Component, OnInit, ViewChild, ElementRef, Input, Output, EventEmitter} from '@angular/core';
import {loadModules} from 'esri-loader';
import esri = __esri;
import on = require('dojo/on');
function executeIdentifyTask(event: Event | undefined) {
console.log(event);
}
@Component({
selector: 'app-esri-map',
templateUrl: './esri-map.component.html',
styleUrls: ['./esri-map.component.css']
})
export class EsriMapComponent implements OnInit {
@ViewChild('mapViewNode') private mapViewEl: ElementRef;
constructor() {
}
map: esri.Map;
mapView: esri.MapView;
layer: esri.MapImageLayer;
identifyTask: esri.IdentifyTask;
async initializeMap() {
try {
const [EsriMap, EsriMapView, MapImageLayer, IdentifyTask, IdentifyTaskProperties] = await loadModules([
'esri/Map',
'esri/views/MapView',
'esri/layers/MapImageLayer',
'esri/tasks/IdentifyTask',
'esri/tasks/support/IdentifyParameters'
]);
this.map = new EsriMap({
basemap: 'dark-gray'
});
this.mapView = new EsriMapView({
container: this.mapViewEl.nativeElement,
center: [27.1428, 38.4237],
zoom: 15,
map: this.map
});
this.layer = new MapImageLayer(
{url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer'});
this.map.add(this.layer);
this.mapView.when(function () {
on(this.mapView , 'click' , executeIdentifyTask);
});
} catch (error) {
console.log('We have an error: ' + error);
}
}
ngOnInit() {
this.initializeMap();
}
}
答案 0 :(得分:0)
我知道我参加聚会有点晚了,但是对于其他遇到类似问题的人,我发现这些错误被描述为可以按F12键并找到类型但无法正确编译的错误,通常是由于未将类型放在types: []
内的tsconfig.app.json
数组中引起的。
我在导入__esri
时遇到了类似的问题,并不断收到以下错误消息ERROR in src/app/esri-map/esri-map.component.ts(16,15): error TS2503: Cannot find namespace '__esri'.
,并且在将"arcgis-js-api"
添加到tsconfig.app.json
后,问题得到解决。