0

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

49.907018,16.324997,49.907018,16.324997,49.818936,16.340103,49.818936,16.340103....

this is my code

map.on('draw:created', function(p) {
   map.addLayer(p.layer);
    var points = p.layer.getLatLngs();
  puncte1=points.join(',');
  puncte1=puncte1.toString();
  puncte1=points.join(',').match(/([\d\.]+)/g).join(',');
           document.getElementById('coordinates').value=puncte1 ;

});
0

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.

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.