【问题标题】:Angular Cli - Dojo module not foundAngular Cli - 找不到 Dojo 模块
【发布时间】:2018-12-17 01:35:16
【问题描述】:

我正在使用 Argis 4.8 JS api 开发一个 Angular 应用程序。我需要 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();
  }

}

【问题讨论】:

  • 不应该像import { on } from 'dojo'一样导入吗?
  • 是的,我试过了。但我得到了这个错误。 TS2305:模块“dojo/on”没有导出成员“on”。
  • 在安装dojo typings 模块而不是使用参考/// <reference path="../../../node_modules/@types/dojo/index.d.ts" /> 之后,您能不能尝试一下?
  • 我安装了模块。编译器似乎也没有问题。当我按下 F12 键时,我也可以进入该功能。但是编译时出现错误。
  • 尝试在script标签中添加.jsindex.html

标签: angular dojo arcgis typescript-typings esri


【解决方案1】:

我知道我参加聚会有点晚了,但是对于遇到类似问题的其他人,我发现这些错误被描述为您可以按 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 后,我的问题得到了解决。

【讨论】:

    猜你喜欢
    • 2020-05-25
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多