【发布时间】:2017-01-23 22:51:46
【问题描述】:
我可以绘制一个多边形并将其保存到 MySQL 数据库中。 (如果有人现在需要怎么做,请问)。
我还可以向我的数据库发送一个 SELECT 请求并显示保存的多边形。
这是我的数据库返回给我的内容
{
"type":"FeatureCollection",
"features":[
{
"id":1,
"type":"Feature",
"properties":{},
"geometry":{
"type":"Polygon",
"coordinates":[
[
[6.146185398101807,46.447689601949826],
[6.146475076675416,46.44726084421887],
[6.1472368240356445,46.44776352535544],
[6.1466360092163095,46.447833752497885],
[6.146185398101807,46.447689601949826]
]
]
}
},
{
"id":"id",
"type":"Feature",
"properties":{},
"geometry":{
"type":"Polygon",
"coordinates":[
[
[6.146185398101807,46.447689601949826],
[6.146475076675416,46.44726084421887],
[6.1472368240356445,46.44776352535544],
[6.1466360092163095,46.447833752497885],
[6.146185398101807,46.447689601949826]
]
]
}
}
]
}
但是我如何在我的地图中添加一个带有我的多边形的图层,并且可以编辑或删除它,就像我从我的 Draw Control 中绘制一个新的多边形一样。
因为不是事件,我不能用这个吧?:
map.on(L.Draw.Event.CREATED, function (e) {
var type = e.layerType,
layer = e.layer;
FGgpx.addLayer(layer);
var shape = layer.toGeoJSON()
var shape_for_db = JSON.stringify(shape);
console.log("Create");
console.log(shape_for_db);
// Save to db
saveGeofences(1,shape_for_db);
});
我试过了,没有结果! 但它就像一个创造?不是吗?
这是我用来从我的数据库中获取多边形的代码:
function getGeofences(devise_id){
$.ajax({
type: "POST",
url: "maps/sql/getGeofences.php",
//data: {data:data},
data: {devise_id:devise_id},
success: result,
error: error,
dataType: "json"
});
function error(data)
{
console.log("Error getGeofences");
console.log(data);
}
function result(data){
console.log("Geofences from DB");
console.log(data);
// How can I add a layer with the polygons to my map
//FGgpx.addLayer(data); // This does not works
}
}
【问题讨论】:
标签: leaflet polygon leaflet.draw