5
我想在我的ionic2應用程序中的小冊子地圖上畫一個多邊形,爲此我找到了leaflet-draw插件,但是出現此錯誤 TypeError:L.Control .Draw是不是構造TypeError:L.Control.Draw不是構造函數
我的代碼看起來這
this.map = L
.map("map")
.setView(this.latLng, 13)
.on("click", this.onMapClicked.bind(this))
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
.addTo(this.map);
this.marker = L
.marker(this.latLng, { draggable: true })
.on("dragend", this.onMarkerPositionChanged.bind(this))
.addTo(this.map);
var drawnItems = new L.FeatureGroup();
this.map.addLayer(drawnItems);
console.log(drawnItems);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: drawnItems
}
});
this.map.addControl(drawControl);
['Leaflet.draw'](https://github.com/Leaflet/Leaflet.draw)是一個插件。它不是Leaflet核心的一部分。你是否按照[安裝說明](https://github.com/Leaflet/Leaflet.draw#install)並且包含了適當的JavaScript文件? – cartant
我確實按照安裝說明進行操作。但爲了能夠從我的腳本代碼中使用它,我安裝了leaflet-draw的類型,並通過參考路徑包含在我的類中:/// 。有什麼我在這裏錯過 –
Nishant
當我從我的瀏覽器中調試它時,我看到L.Control是一個在小冊子typescript文件中定義的函數,而在leaflet -print typescript文件中,「Control」是一個名稱空間,裏面其中繪製定義,所以我認爲這段代碼是不是指的是正確的'控制' – Nishant