I'd like to save the polyline coordinates. I'm creating it with Leaflet.Draw. The problem is that the coordinates are stored twice.


this is my code

map.on('draw:created', function(p) {
    var points = p.layer.getLatLngs();
           document.getElementById('coordinates').value=puncte1 ;


First, this is not really GIS question but pure JS one. And second, personally I don't like regexp very much, since I have no idea what they do when I look at them, and the same goes for the one above.

Anyway, this (primitive) and veary easy to read code works:

var points = event.layer.getLatLngs();
var puncte1 = points.join(',');
puncte1 = puncte1.split('LatLng(').join('');
puncte1 = puncte1.split(')').join('');
puncte1 = puncte1.split(' ').join('');

If the question was about the regexp, then this is not the right answer. If question was about the solution, then it is.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.