Angular 区域选择传单地图角度9

Angular 区域选择传单地图角度9,angular,leaflet,Angular,Leaflet,我安装了传单区域选择()插件,但是当我定义选择区域时,我得到以下错误 我启动了npm安装--保存传单区域选择 在angular.json中,我添加了 "scripts": [ "node_modules/leaflet/dist/leaflet.js", "node_modules/leaflet-area-select/dist/Map.SelectArea.min.js", "node_modules/

我安装了传单区域选择()插件,但是当我定义选择区域时,我得到以下错误

我启动了
npm安装--保存传单区域选择

在angular.json中,我添加了

"scripts": [
   "node_modules/leaflet/dist/leaflet.js",
   "node_modules/leaflet-area-select/dist/Map.SelectArea.min.js",
   "node_modules/jquery/dist/jquery.min.js"
],
在代码中,我添加了以下说明:

import SelectArea from 'leaflet-area-select';
public map: L.map;
this.map = L.map('map', {
   center: [37.606655, 15.1606003],
   selectArea: true,
   zoom: 10
});
    
this.map.on('areaselected', (e) => {
   console.log(e.bounds.toBBoxString()); // lon, lat, lon, lat
});
    
this.map.selectArea.setCtrlKey(true);
似乎无法识别SelectArea

如果我在这一行上移动鼠标, “SelectArea”已声明,但其值从未被读取


如何解决这个问题?

看起来像是识别类型中的TS问题,或者您可以使用RequireJS。因此,安装节点类型
npm install@types/node——保存
,然后在tsconfig文件中添加节点类型

"types": [
      "node"
 ]
然后像NodeRequire一样使用它,而不是commonjs样式

var L = require("leaflet")
否则,如果您想要坚持commonjs样式,那么您可以使用模块AIG创建自己的
.d.ts
(定义文件)文件

declare module leaflet 
{       
}
然后像导入一样导入,这样应该可以

import * as L from 'leaflet'
最后,您还需要在tsconfig.json中添加此自定义类型路径以使其正常工作

"typeRoots": [ "./your_custom_type_folder_here", "./node_modules/@types"]