Leaflet.draw: Error while drawing a polygon, edition or deleting.
Hello, I don’t kow if the problem comes from my code but every time I draw a polygon, edit a form or delete one I’ve got got this error :
leaflet.draw.js:9 Uncaught TypeError: Cannot read property ‘updatePosition’ of null
After that if I zoom in or out, my polygon never updates it’s size.
Here is my code:
angular.module('myApp.view1', ['ngRoute', 'leaflet-directive'])
.controller('View1Ctrl', ["$scope", "leafletData", function ($scope, leafletData) {
var drawnItems = new L.FeatureGroup();
var options = {
edit: {
featureGroup: drawnItems
},
draw: {
polyline: false,
marker: false,
polygon: {
shapeOptions: {
color: 'purple'
}
},
circle: {
shapeOptions: {
stroke: true,
weight: 4,
color: 'blue',
opacity: 0.5,
fill: true,
fillColor: null, //same as color by default
fillOpacity: 0.2,
clickable: true
}
}
},
showRadius: true
}
var drawControl = new L.Control.Draw(options);
angular.extend($scope, {
defaults: {
scrollWheelZoom: false
},
london: {
lat: 51.505,
lng: -0.09,
zoom: 8
},
controls: {
custom: [drawControl]
}
});
leafletData.getMap().then(function (map) {
map.addLayer(drawnItems);
map.on('draw:created', function (e) {
var type = e.layerType,
layer = e.layer;
if (type == "polygon") {
console.log("polygon " + JSON.stringify(layer.toGeoJSON()));
}
if (type === 'circle') {
console.log(JSON.stringify(layer.toGeoJSON()));
}
drawnItems.addLayer(layer);
});
});
}]);
Thank you for the help
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 21 (5 by maintainers)
I tried using existing geojson on map and I get cannot get ‘lat’ of undefined: https://jsfiddle.net/Lscupxqp/31/