ポリゴンを描き、それをMySQLデータベースに保存することができます。 (誰かが今、どのようにしたら、ちょうど質問する必要がある場合)。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
}
}
少し説明で常に歓迎 - あなたが作品を掲載しましたコード、および場所はOPがそれを利用することができる方法について説明します。 – Tom