我想知道如何给(并检索)一个ID到小册子(.draw)中的多边形。我需要这个,因为我想能够告诉数据库哪个多边形要删除/编辑。识别要删除的多边形
在此先感谢
编辑:
在我的数据库我节省了polygon_ID和多边形的坐标。这是我救一个多边形的代码:(当我完成绘制多边形这trigered)
map.on('draw:created', function(e) {
var type = e.layerType,
layer = e.layer;
if (type == "polygon") {
var polygon = {};
polygon['geometry'] = {};
polygon['geometry']['type'] = "Polygon";
var coordinates = [];
latlngs = layer.getLatLngs();
for (var i = 0; i < latlngs.length; i++) {
coordinates.push([latlngs[i].lat, latlngs[i].lng])
}
polygon['geometry']['coordinates'] = [coordinates];
coordinates = JSON.stringify(coordinates);
//console.log(coordinates);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
//alert("Sent!");
}
};
xhttp.open("POST", "inc/send.php?a=add&t=polygon&c=" + coordinates, true);
xhttp.send();
}
drawnItems.addLayer(layer);
});
这是我send.php:
if(isset($_GET['c']) && isset($_GET['t']) && isset($_GET['a'])){
$coordinates = $_GET['c'];
$type \t \t = $_GET['t'];
$action \t \t = $_GET['a'];
if($type == "polygon" && $action == "add"){
$sth = $dbh->prepare('INSERT INTO polygons (coordinates) VALUES (:coordinates)');
$sth->bindParam(':coordinates', $coordinates);
$sth->execute();
}
} else {
}
这是我如何加载我的多边形:
$polygonsth = $dbh->prepare("SELECT * FROM polygons");
$polygonsth->execute();
$polygonresult = $polygonsth->fetchAll();
...
foreach ($polygonresult as $row) {
\t
echo "L.polygon(" . $row['coordinates'] . ")
\t .addTo(drawnItems);
\t //console.log(pol.options.id);
";
}
我真的希望这个澄清的事情。
取决于您存储多边形的格式,我们无法从您的非常简短的问题中解决问题。请阅读此:http://stackoverflow.com/help/how-to-ask – iH8
我很抱歉不够清楚。在我的数据库中,我存储了多边形手柄的所有经度和纬度位置,并且每个多边形都有ID。我的问题是如何将传单和mysql ID链接在一起,以便我可以告诉数据库要删除的多边形。我使用AJAX来执行查询。也许你现在可以帮助我? –
仍然取决于如何初始化多边形以及将它们添加到地图的方式。您能否编辑您的问题并在您的评论中添加您输入的信息,并在您如何将多边形添加到地图中时包含相关的代码?单独的多边形? FeatureLayer? GeoJSON的?太多的变量给出了很好的答案 – iH8