1

以下は、各境界項目を表すマップ上の境界と長方形の描画の配列を含む私のコードです。

http://jsfiddle.net/XffyE/4/

複数の長方形/境界を 1 つのポリゴンにマージすることは可能ですか? 目標は、長方形を結合して作成された多角形内を検索することです。

たとえば、各境界を個別に検索するのではなく、結合された境界内の場所を検索します。

    function createBounds() {

        var bounds = new Array();

        bounds[0] = new google.maps.LatLngBounds(
            new google.maps.LatLng(25.941886953491675, -80.17411103748543),
            new google.maps.LatLng(25.947676224813897, -80.16767330177947)
        );
        bounds[1] = new google.maps.LatLngBounds(
            new google.maps.LatLng(25.941886953491675, -80.16767330177947),
            new google.maps.LatLng(25.94622890698334, -80.1644544339265)
        );
        bounds[2] = new google.maps.LatLngBounds(
            new google.maps.LatLng(25.927413775186118, -80.1644544339265),
            new google.maps.LatLng(25.94622890698334, -80.15962613214703)
        );
        bounds[3] = new google.maps.LatLngBounds(
            new google.maps.LatLng(25.927413775186118, -80.15962613214703),
            new google.maps.LatLng(25.931755728677782, -80.15801669822054)
        );
        bounds[4] = new google.maps.LatLngBounds(
            new google.maps.LatLng(25.927413775186118, -80.15801669822054),
            new google.maps.LatLng(25.933203046508336, -80.15318839644107)
        );
        bounds[5] = new google.maps.LatLngBounds(
            new google.maps.LatLng(25.92886109301667, -80.15318839644107),
            new google.maps.LatLng(25.933203046508336, -80.15157896251458)
        );

        drawRectangles(bounds);   
    }

    // Draw the array of bounds as rectangles on the map
    function drawRectangles(bounds) {
      boundsRectangles = new Array(bounds.length);
      for (var i = 0; i < bounds.length; i++) {
        boundsRectangles[i] = new google.maps.Rectangle({
          bounds: bounds[i],
          fillOpacity: 0,
          strokeOpacity: 1.0,
          strokeColor: '#000000',
          strokeWeight: 1,
          map: map
        });
      }
    }
4

1 に答える 1

1

楽しい質問です。短い答えは次のとおりです。

  1. すべての長方形の頂点の座標を見つけます
  2. これらの頂点を時計回りまたは反時計回り (Google マップが望む方) に並べ替えます。
  3. これらの頂点を LatLng オブジェクトの配列として、並べ替えられた順序で Polygon() コンストラクターにフィードします。

反対側のコーナーを見つけたり、角度ごとに並べ替えたりする方法について詳しく説明する時間がなくて申し訳ありません。

于 2013-07-26T20:11:36.527 に答える