无法获取折线/多边形Leaflet

时间:2017-08-22 06:05:41

标签: javascript php mysql leaflet

我成功地设法使用Leaflet和Javascript + PHP将带坐标的多边形添加到我的数据库,但我不知道如何在编辑页面上获取它们...如果我点击编辑按钮,我可以成功获取坐标,但不绘制多边形...任何想法我该怎么办?谢谢!

    var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
            osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
            osm = L.tileLayer(osmUrl, { maxZoom: 18, attribution: osmAttrib }),
            map = new L.Map('map', { center: new L.LatLng(44.9323281,26.0306833), zoom: 13 }),
            drawnItems = L.featureGroup().addTo(map);
    L.control.layers({
        'osm': osm.addTo(map)
    },).addTo(map);
   map.addControl(new L.Control.Draw({
     draw : {
        position : 'topleft',
        polygon : true,
        polyline : false,
        rectangle : false,
        circle : false,
        marker: false,
        circlemarker: false
    },
    edit : {
        featureGroup: drawnItems
    }
        /*edit: {
            featureGroup: drawnItems,
            poly: {
                allowIntersection: false
            }
        },
        draw: {
            polygon: {
                allowIntersection: false,
                showArea: true
            }
        }*/
    }));
 map.on('draw:created', function (e) {
        var type = e.layerType,
                layer = e.layer;

        if (type === 'marker') {
            layer.bindPopup('Call Point!');
        }

        drawnItems.addLayer(layer);

        var shapes = getShapes(drawnItems);

        console.log("shapes",shapes);

  var points = e.layer.getLatLngs();
  var puncte = JSON.stringify(points);
  console.log(puncte);

    });
map.on(L.Draw.Event.CREATED, function (e) {
    map.addLayer(e.layer);
    var points = e.layer.getLatLngs();
  puncte1= points.toString();
  puncte1 = puncte1.replace(/[{}]/g, '');
  puncte1=points.join(',').match(/([\d\.]+)/g).join(',')
 //var newStr = puncte1.substring(1, puncte1 .length-1);
  console.log(puncte1);
$('#geo').val(puncte1);

这是我的PHP代码:

 <?php
  if (isset($msg))
    echo $msg;
  include_once ("../../class/DB/DBConn.includeall.php");
  include_once ('../include/config.inc.php');
  $db = new DBconn(NULL);
  $zona = new tableZona($db);
  $zona = $db->DbGetRow("SELECT * FROM zona WHERE id = ".$_POST["id"]);
  echo '

<form action="" method="POST">
 <a href="?page=tabel_zona"><span class="inchide1">Inchide</span><i class="fa fa-times-circle" id="close" aria-hidden="true" style="cursor: pointer;"></i></a> 
  <h1>Modifica Datele zonei '.$zona->nume.'</h1>
   <input type="hidden" name="id_zona" value="'.$zona->id.'" />
   <div id="map" style="width: 600px; height: 400px"></div>
  <p class="form1">Nume:</p>
        <input type= "text" class= "form-control form2" style="padding:12px  20px;" name= "zona" value="'.$zona->nume.'" /> <br />
         <p class="form1">Geolocatii:</p>
        <input type= "text" class= "form-control form2" style="padding:12px  20px;" name= "geo" id="geo" value="'.$zona->geolocatii.'" /> <br />
  <p class="form1">Cuvinte cheie:</p>
        <input type= "text" class= "form-control form2" id="cuv_cheie" style="padding:12px  20px;"name= "cuv_cheie" value="'.$zona->cuv_cheie.'"> <br />
<br> <br>
<p class="form1"> <input type="submit" name="submit" value="Salveaza"> <br> </p>
</form>
  ';



 ?>

0 个答案:

没有答案