我可以绘制一个多边形并将其保存到 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]
]
]
}
}
]
}
但是,我怎样才能将带有多边形的图层添加到我的地图中,并且可以编辑或删除它,就好像我从我的绘图控件中绘制了一个新的多边形一样。
因为它不是一个事件,所以我不能使用它,对吧?:
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
}
}