【发布时间】:2020-10-14 02:16:30
【问题描述】:
我已经广泛使用 Leaflet 0.7,但我第一次尝试将 1.7 用于新项目。我正在尝试扩展 GeoJSON 图层类以使用默认的 pointToLayer 方法,这些似乎失败了,因为 GeoJSON 的类型定义没有与对象关联......这是我正在尝试的:
import { GeoJSON } from 'leaflet';
const geojsonMarkerOptions = {
...
};
export const Layer = GeoJSON.extend({
initialize: function() {
GeoJSON.prototype.initialize.call(this, [], {
pointToLayer: (feature, latlng) => this.pointToLayer(feature, latlng)
});
},
pointToLayer: function(feature, latlng) {
...
}
}
编译器抱怨:
“GeoJSON”类型上不存在属性“initialize”
所以不知何故 GeoJSON 类型没有与 GeoJSON 对象相关联是我对此的解释......你的是什么?我正在使用 Leaflet 1.7.1、@types/leaflet 1.5.19 和 Typescript 4.0.3。我已经更新到 Angular 10 并删除并重新安装了 Leaflet 及其 @types 包,我还尝试清除我的节点模块并重新安装它们。有人知道我在这里做错了什么,对吗?
【问题讨论】:
标签: angular typescript leaflet