[英]Leaflet GeoJSON type not associating with GeoJSON object
我已經廣泛使用 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”類型上不存在屬性“初始化”
所以不知何故 GeoJSON 類型沒有與 GeoJSON 對象相關聯是我對此的解釋......你的是什么? 我正在使用 Leaflet 1.7.1、@types/leaflet 1.5.19 和 Typescript 4.0.3。 我已經更新到 Angular 10 並刪除並重新安裝了 Leaflet 和它的 @types 包,我還嘗試清除我的節點模塊並重新安裝它們。 有人知道我在這里做錯了什么,對吧??
雖然 Leaflet JS 代碼確實在其類上有一個initialize
方法,並且在文檔示例中提到了這個方法,但它並沒有在 API 中明確描述,因此它沒有被包含在類型...
您可以添加它,或者更好地向@types/leaflet
包/repo 發送拉取請求,或者簡單地忽略 TypeScript 編譯器錯誤,並在使用initialize
方法的行上方使用// @ts-ignore
注釋指令。
你不想做這樣的事情嗎?
export class Layer extends GeoJSON {
initialize() {
super.initialize()
}
}
我承認雖然不知道傳單。 但這將是我的第一個猜測。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.