2017-03-02 84 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是圆的元素。