我使用leaflet.draw在地图上创建形状(地理区域),当我画一个圆时,由于圆没有长度,因此我会收到此错误Uncaught TypeError: Cannot read property 'length' of null,而当我绘制圆时,也会收到此错误我在shapeOptions:
中放入了 editable:true$("#mapContainer").on("click", ".btnCircleDraw",function(){
circleDrawer = new L.Draw.Circle(map, {
shapeOptions: {
color: color,
fillOpacity: opacity,
fillColor: color,
stroke: color,
opacity: opacity,
editable: true
}
});
map.on('draw:created', drawCreated);
circleDrawer.enable();
});
我有此函数drawCreated:
function drawCreated(e) {
type = e.layerType,
layer = e.layer;
layer.addTo(drawnItems);
console.log(type, ' drawn', layer);
layer.on("edit", function(event) {
var content = "";
if (type === "circle") {
//content = 'Circle with : <ul><li> Radius : ' + layer.getRadius() + '</li>'+
//'<li> Center : ' + layer.getLatLng() + ' </li></ul>';
var lngLat = layer.getLatLng();
console.log("new: ", lngLat);
}
});
if (type === 'circle') {
var theCenterPt = layer.getLatLng();
var theRadius = layer.getRadius();
points['lng'] = theCenterPt.lng;
points['lat'] = theCenterPt.lat;
points['radius'] = theRadius;
console.log(points);
drawnItems.addLayer(layer);
}
}
是否有解决此问题的方法或替代方法?