我创建了一个非常小的codepen,但在尝试创建绘图控件时遇到错误 .
见:https://codepen.io/DrYSG/pen/QgmVZg
我认为我做错了很简单 . 但我查看了我正在使用的CDN,我没有看到任何明显的信息:
https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.9/leaflet.draw-src.js
这些是我在控制台中看到的错误:
Util.js:15 Uncaught TypeError: Cannot add property segmentsIntersect, object is not extensible
at Object.extend (Util.js:15)
at LineUtil.Intersect.js:6
at EditToolbar.Delete.js:145 extend @ Util.js:15 (anonymous) @ LineUtil.Intersect.js:6 (anonymous) @ EditToolbar.Delete.js:145 pen.js:11 Uncaught TypeError: L.Control.Draw is not a constructor
at pen.js:11
var map = L.map("root").setView([42, -71], 7);
L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution:
'© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors'
}).addTo(map);
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
2 回答
实际上,Leaflet.draw不适用于Leaflet 1.1.0 . 据报道 . 只要this issue未关闭,请考虑问题仍然存在 .
显然我不能评论,直到我有更多的声誉 .
已发布Leaflet.Draw
0.4.10
,将Leaflet的上限版本限制为1.0.x
而不是1.1.x
. Leaflet 1.1.x介绍了Leaflet.Draw未准备好的ES6和Rollup,并且正在积极寻求解决 .