typescript 类型错误:L.Control.Draw 不是构造函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38930066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:44:50  来源:igfitidea点击:

TypeError: L.Control.Draw is not a constructor

typescriptionic2leaflet.draw

提问by Nishant

I wanted to draw a polygon in the leaflet map in my ionic2 app, for that I found leaflet-draw pluggin, but I am getting this error TypeError: L.Control.Draw is not a constructor

我想在我的 ionic2 应用程序的传单地图中绘制一个多边形,为此我找到了传单绘制插件,但我收到此错误 TypeError: L.Control.Draw is not a constructor

My code looks this

我的代码看起来像这样

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);

回答by Megapiharb

You need add to head html CDN's

您需要添加到头部 html CDN

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.2/leaflet.draw.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.2/leaflet.draw.js"></script>

and add to map { drawControl: true }

并添加到地图 { drawControl: true }

var map = L.map('mapid', { drawControl: true }).setView([25, 25], 2);

回答by Bashirpour

You can get latest version of leaflet.drawfrom this address

您可以leaflet.draw从此地址获取最新版本

https://cdnjs.com/libraries/leaflet.draw

https://cdnjs.com/libraries/leaflet.draw

Version 1.0.4

版本 1.0.4

https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css
https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js