Bobbie Smulders Creative Software Developer

Serializing Leaflet Draw layers


On a project I recently worked on, I used Leaflet.draw to draw polygons and rectangles on a map. Leaflet.draw is perfect for this task but does not support storage of these objects out-of-the-box. I solved this issue by using the draw:edited, draw:deleted and draw:created events to store the objects to a database using a REST API.

To save everyone else the frustration of having to figure this out, I created a project called Leaflet Draw Serialize Demo that demonstrates how to use these events to save the drawn objects to an external service using a REST API. The interesting stuff is in the front-end javascript.

Feel free to use this project as a reference for your own implementation.