我正在用Argis4.8JSAPI开发一个角应用程序。我需要Dojo / On函数。我在编译器中也没有错误。但是,当我编译时,我得到了错误“模块未找到:错误:无法解析'dojo / on‘path”。我不能使用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();
}
}发布于 2018-12-20 09:25:32
我知道我迟到了一点,但对于其他有类似问题的人,我发现这些错误被描述为可以按下F12键并找到类型,但无法正确编译,通常是由于没有将该类型放在tsconfig.app.json内的types: []数组中造成的。
我在__esri导入中遇到了类似的问题,并一直收到以下错误ERROR in src/app/esri-map/esri-map.component.ts(16,15): error TS2503: Cannot find namespace '__esri'.,并且在将"arcgis-js-api"添加到ERROR in src/app/esri-map/esri-map.component.ts(16,15): error TS2503: Cannot find namespace '__esri'.之后,我的问题就解决了。
https://stackoverflow.com/questions/51244335
复制相似问题