Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a completed polygon points leaflet.draw to mysql table

Tags:

I would like to use leaflet.draw to create outlines of regions. I have managed to get this working ok: https://www.mapbox.com/mapbox.js/example/v1.0.0/leaflet-draw/

Now I'd like to save the data for each polygon to a mysql table. Am a little stuck on how I would go about exporting the data and the format I should be doing it in.

If possible I'd like to pull the data back into a mapbox/leaflet map in the future so guess something like geojson would be good.

like image 342
user3703511 Avatar asked Jun 03 '14 15:06

user3703511


1 Answers

So you could use draw:created to capture the layer, convert it to geojson then stringify it to save in your database. I've only done this once and it was dirty but worked.

map.on('draw:created', function (e) {   var type = e.layerType;   var layer = e.layer;    var shape = layer.toGeoJSON()   var shape_for_db = JSON.stringify(shape); }); 
like image 106
Michael Evans Avatar answered Sep 16 '22 13:09

Michael Evans