2017-03-02 85 views
0

我在Angular中使用ngMaps。 我已經創建了一張地圖,幷包含一個可根據我的半徑值進行調整的形狀(圓形)。角度ng-Map setBounds用圓圈半徑調整

是否可以設置地圖的邊界進行調整以包含整個圓?

這是我的視圖:

<ng-map class="bu-map" 
       default-style="false" 
       scrollwheel="false" 
       style="margin: 0 -15px" 
       data-ng-style="{'height': appCtrl.windowHeight - 81 + 'px'}" 
       map-type-control="false" 
     > 

      <shape id="circle" 
        name="circle" 
        centered="true" 
        stroke-color='#FF0000' 
        stroke-opacity="0.8" 
        stroke-weight="1" 
        center="{{listCtrl.queryBounds.centerPoint}}" 
        radius="{{listCtrl.queryBounds.radius}}" 
        editable="false"></shape> 
</ng-map> 

和我的控制器:

 NgMap.getMap().then((map) => { 
      bu.map = map; 
      map.setCenter(centerPoint); 
      bu.queryBounds = { 
       centerPoint: [centerPoint.lat, centerPoint.lng], 
       // miles to meters conversion 
       radius: (parseFloat(searchQuery.radius) || 1) * 1600, 
      }; 
      map.setZoom(10); 
     }); 
    }); 

在這種情況下,searchQuery.radius可以被調整,其調整在所述地圖上繪製的圓但它是有時地圖太大,變焦不能調​​整。

我在setZoom上做了一個計算,但setZoom的值沒有足夠的多樣性來完全包含圓。

這是可能的setBounds?

謝謝!

回答

0

這裏是一個本地方式。在圓上找到4個座標(名稱:東,西,北,南)。

NgMap.getMap().then((map) => { 
    let bounds = new google.maps.LatLngBounds(); 
    bounds.extend(east); 
    bounds.extend(west); 
    bounds.extend(north); 
    bounds.extend(south); 

    map.fitBounds(bounds); // fit the zoom to show all the four cordinates 
    map.setCenter(bounfd.getCenter()); // set the circle to the map center. 
} 

UPD:對於上面的方式,由google.maps.geometry.spherical.computeOffset(),我們能找到的四點經緯度。

Way2:

NgMap.getMap().then((map) => { 
    map.fitBounds(map.shapes[0].getBounds()); // fit the zoom to the circle. 
} 

注:通過這種方式,你必須精確,其形狀map.shapes是圓的元素。