我在使用Leaflet的绘制控件绘制形状时遇到问题。我在地图中创建了一个绘制控件,该控件使用户可以绘制形状(标记,线条等)。
当我单击绘图控制栏上的任何项目时,在我的浏览器控制台中会弹出以下错误。
Uncaught TypeError: Cannot read property 'Feature' of undefined
at NewClass.addHooks (Draw.Polyline.js:71)
at NewClass.enable (leaflet.js:5)
at NewClass.enable (Draw.Feature.js:38)
at HTMLAnchorElement.handler (DomEvent.js:79)
我尝试导入不同版本的Leaflet.draw。这样的。
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"></script>
还有这个。
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw-src.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw-src.js"></script>
但是,所有的导入似乎都不起作用。
这是代码。
let map = L.map('map', { drawControl: true })
.setView([42.35, -71.08], 13);
let imageryLayer = L.esri.basemapLayer("Imagery").addTo(map);
let imageryLabelLayer = L.esri.basemapLayer("ImageryLabels").addTo(map);
// Initialise the FeatureGroup to store editable layers
let editableLayers = new L.FeatureGroup();
map.addLayer(editableLayers);
let drawPluginOptions =
{
position: 'topright',
draw: {
polygon: {
allowIntersection: false, //only allow simple polygons
drawError: {
color: 'e1e100',
message: '<strong>Oh snap!<strong> you can\'t draw that!'
}
},
shapeOptions: {
color: '#97009c'
},
polyline: false,
circle: false,
rectangle: false,
marker: false,
},
edit: {
featureGroup: editableLayers,
remove: false
}
};
let drawControl = new L.Control.Draw({ edit: {featureGroup: editableLayers}});
map.addControl(drawControl);
map.on('draw:created', function (e) {
let type = e.layerType,
layer = e.layer;
if (type === 'marker') {
layer.bindPopup('A popup!');
}
editableLayers.addLayer(layer);
});
这是图书馆问题吗?还是我初始化和使用绘画控件的方式有问题?