区域选择传单地图角度9

问题描述

我安装了Leaflet-area-select(REPRODUCIBILITY)插件,但是在定义选择区域时出现以下错误 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

enter image description here

如果我将鼠标移到该行上, 已声明“ SelectArea”,但其值从未读取出现

如何解决此问题?

解决方法

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

"types": [
      "node"
 ]

然后像节点require一样使用它,而不是commonjs样式

var L = require("leaflet")

否则,如果您要坚持commonjs样式,则可以使用模块扩展来创建自己的.d.ts定义文件)文件

declare module leaflet 
{       
}

然后将其导入,应该可以。

import * as L from 'leaflet'

最后,您还需要在tsconfig.json中添加此自定义类型路径,以使其正常工作。

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...