Closed timeroute closed 3 years ago
I can't reproduce the error. Can you please create a JSfiddle, showing the problem?
I have the same problem - as soon as i click on "draw polygon" button and hover on map i get bunch of errors of the same content: "Cannot read property '0' of undefined at NewClass._calcLayerDistances (leaflet-geoman.min.js:1)" Do I need initialize anything before using "toolbox"?
I do not have working JSfiddle, but if it changes something for you i cut some useless code for this problem and paste rest to JSfiddle. If you would like, please take a look: https://jsfiddle.net/hpbnruc2/4/
I'm just thinking... Is this error can appears because of using OpenStreetMaps instead of MapBox?
I wasn't able to check the error yet but I'm pretty sure your Tilelayer should not have an influence on Leaflet-Geoman. But I will check your error once I find the time - thanks for the reproduction link!
Ok, thank you for reply - Waiting for solution ;)
I'm having the same problem, holding alt seems to resolve it since it's an issue in the snapping mixin. The provided variable "closestSegment" is undefined which makes the [0]
give a property/index error.
Lines in code where the issue lies: https://github.com/geoman-io/leaflet-geoman/blob/41810b57bec8e60f66b3191e68f084555e55b804/src/js/Mixins/Snapping.js#L368-L373
Found out the issue, it was due to a polygon not having any coordinates attached to it a simple if around the L.polygon()
function to check that the coordinates actually exist and that the array has a length makes everything work flawlessly.
@selenecodes it would be very helpful when you create a demo page or a gif, so we can see how to reproduce this error
Unfortunately I can't add a gif of it due to it being a customer's internal website.
The problem however isn't in this repo, it occurs when you add a feature to the map that doesn't have coordinates, causing the closestSegment
in your code to break due to there not being any coordinates to read from.
The fix people should apply to their code
coordinates = []
if (coordinates.length) { // <- add this if statement to make sure that the polygon only gets created if there are actually coordinates to draw.
new L.polygon(coordinates)
}
I installed the latest leaflet-geoman version by npm. When
map.pm.enableDraw('Line')
, It raised typeerror while the mouse over the map. leaflet version: 1.6error in Firefox:
error in Chrome: