I have the following code for saving my coordinates of what I draw. So what I do on drawing created I have the following function.

 map.on(L.Draw.Event.CREATED, function (e) {

        var type = e.layerType,
                layer = e.layer;
        var points = JSON.stringify(e.layer.toGeoJSON());

        console.log("coord : "+e.layer.toGeoJSON().geometry.coordinates);
        var latlngs = [];
          latlngs = LatLngsToCoords(e.layer._latlngs, 1);

        if (type === 'marker') {
            layer.bindPopup('A popup!');
        if (type === 'polygon'){

        console.log("coord : "+e.layer.toGeoJSON().geometry.coordinates);



This output e.layer.toGeoJSON().geometry.coordinates gives me example so I will then transfer it into 175.28162956237796,-37.77007019461929,175.28506278991702,-37.77271618103962,175.27849674224854,-37.77458188377217,175.27781009674072,-37.77376776473304,175.28162956237796,-37.77007019461929

into POLYGON(( 175.28162956237796 -37.77007019461929,175.28506278991702 -37.77271618103962,175.27849674224854 -37.77458188377217,175.27781009674072 -37.77376776473304,175.28162956237796 -37.77007019461929 ))

I know I could do this and save into the MySQL database.

For the reverse when I need to restore the polygon I will need to extract the POLYGON and now reverse the latitude and longitude back.

I find there is a lot of steps. Is there any direct method ?

1 Answer 1


I would recommend looking into this approach:

L.GeoJson layer and pointing Leaflet.draw at it.

You can iterate over drawn objects with drawnItems.eachLayer() method and add any objects to the layer.

  • actually at one time I only need one object to be present and user need to deal with only one to avoid confusion. Because after drawing I am going to pop-up for them to enter details before they save into database Oct 18, 2017 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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