如何将完成的多边形点leaflet.draw保存到mysql表 [英] How to save a completed polygon points leaflet.draw to mysql table

查看:320
本文介绍了如何将完成的多边形点leaflet.draw保存到mysql表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用leaflet.draw创建区域轮廓.我设法使它正常运行: https://www.mapbox.com/mapbox.js/example/v1.0.0/leaflet-draw/

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/

现在,我想将每个多边形的数据保存到mysql表中.我对如何导出数据和应该采用的格式有些困惑.

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.

如果可能的话,我希望将来将数据拉回到mapbox/leaflet地图中,因此,猜测诸如geojson之类的东西会很好.

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.

推荐答案

因此,您可以使用draw:created捕获图层,将其转换为geojson,然后将其字符串化以保存在数据库中.我只做过一次,它很脏但可以用.

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);
});

这篇关于如何将完成的多边形点leaflet.draw保存到mysql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆