2016-06-28 15 views
0

loadGeoJsonで読み込まれたGoogleマップのデータレイヤーで頂点(ポリゴンポイント)を削除するにはどうすればよいですか?私は(例えば、GoogleからのLの左上隅)白い円を右クリックすることで、単一の頂点を削除するGoogleマップを削除するDataLayerの頂点

http://output.jsbin.com/tuyived

+0

実は私はDataLayerのHTTPSでこのhttps://developers.google.com/maps/documentation/javascript/examples/delete-vertex-menuを達成したい:// developers.google.com/maps/documentation/javascript/datalayer#overview –

答えて

4

次のスニペットで、すべてを削除することができます:

map.data.forEach(function(feature) { 
    //If you want, check here for some constraints. 
    map.data.remove(feature); 
}); 

参考:Remove all features from data layer

編集:

削除したい場合は、単にそれは少しトリッキーですが、私は、次のクリックハンドラによって行うことができる頂点クリック:

map.data.addListener('click', function(ev) { 

    //array to hold all LatLng in the new polygon, except the clicked one 
    var newPolyPoints = []; 

    //iterating over LatLng in features geometry 
    ev.feature.getGeometry().forEachLatLng(function(latlng) { 

     //excluding the clicked one 
     if (latlng.lat() == ev.latLng.lat() && latlng.lng() == ev.latLng.lng()) { 
      console.log('This one will be removed: lat: ' + latlng.lat() + ', lng: ' + latlng.lng()); 
     } else { 
      //keeping not matching LatLng 
      newPolyPoints.push(latlng); 
     } 
    }); 

    //creating new linear ring 
    var newLinearRing = new google.maps.Data.LinearRing(newPolyPoints); 

    //creating a new polygon out of the new linear ring 
    var newPoly = new google.maps.Data.Polygon([newLinearRing]); 

    //apply the new polygon to the clicked feature 
    ev.feature.setGeometry(newPoly); 
}); 

あなたは/あなたのニーズに応じて、あなたのデータを、それを調整する必要があります構造。それは提供された構造のために働く。

希望それが役立つ。この時間;)

+0

多分私の質問は不完全でした。更新された質問を確認してください。 –

+0

は、更新された質問 –

+0

にマッチする回答を編集しました。ありがとう! –

関連する問題