2016-07-21 4 views
2

아래는 편집 된 다각형 정점을 감지하는 이벤트입니다. 전체 폴리곤의 latLng에서 정점을 편집하려고합니다. 가능합니까? 아니면 그 안에 "그리기 : 편집 됨"이벤트를 발생시켜야합니다.전단지 - 그리기 : 'draw : editvertex'이벤트에서 다각형 latLng 가져 오기

this.map.on('draw:created', function(e) { 
     this.drawnItems.addLayer(e.layer); 
     this.calculateArea(e.layer); 
     edT.enable(); 
    }.bind(this)); 

    this.map.on('draw:editvertex', function (e) { debugger; 
     var layers = e.layers; 
     // I want to get current polygon latLng here 
    }.bind(this)); 

답변

0

나는 지난 며칠이 같은 문제로 고생하고, 나를 위해 노력하고 있습니다 접근 방식을 공유하고 싶어 (하지만 가장 좋은 방법처럼 그 생각하지 않습니다).

그래서 같이 새로 만든 리플릿 다각형의 항목 "옵션"에서 _id 필드를 저장하고 :

realPoly = new L.Polygon([your Array of lanLngs],{ 
    '_id':myItem.id, 
    '_myOtherId':myOtherId 
}) 

... 다음에 "그릴 : editvertex"핸들러, 내가 할 다음 :

map.on('draw:editvertex', function(e){ 
    for (thisLayer in e.target._layers) { 
     if(e.target._layers.hasOwnProperty(thisLayer)){ 
     if(e.target._layers[thisLayer].hasOwnProperty("edited")){ 
      console.log("we think we found polygon id?"); 
      console.log(e.target._layers[thisLayer]); 
      // you can find your custom params below 
      console.log(e.target._layers[thisLayer].options._id); 
      console.log(e.target._layers[thisLayer].options._myOtherId); 
      // the updated Polygon array points are here: 
      newPolyLatLngArray = e.target._layers[thisLayer].editing.latlngs[0]); 
     } 
    } 
    }; 
}); 

... 내가 말했듯이, 이것은 굉장하다고 느끼지 않지만 지금까지는 나를 위해 일하고있다. 도움이 되었기를 바랍니다.

AKA