我安装了传单区域-选择(https://github.com/w8r/leaflet-area-select)插件,但是当我定义选择区域时,会得到以下错误

我启动了npm install --save leaflet-area-select
在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‘,但它的值永远不会被读取,会出现。
我如何解决这个问题?
发布于 2020-09-11 14:13:19
看起来像TS问题在识别类型,或者您可以使用RequireJS。因此,安装节点类型npm install @types/node --save,然后在tsconfig文件中添加类型中的节点。
"types": [
"node"
]然后按照节点要求使用它,而不是使用公共it样式。
var L = require("leaflet")否则,如果您希望坚持使用公共if样式,则可以使用模块辅助技术创建自己的.d.ts (定义文件)文件。
declare module leaflet
{
}然后导入它,就像,它应该能工作。
import * as L from 'leaflet'最后,还需要在tsconfig.json中添加此自定义类型路径以使其工作。
"typeRoots": [ "./your_custom_type_folder_here", "./node_modules/@types"]https://stackoverflow.com/questions/63825507
复制相似问题