首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角谷歌地图fitBounds

角谷歌地图fitBounds
EN

Stack Overflow用户
提问于 2017-05-10 22:50:09
回答 1查看 1.9K关注 0票数 0

我不知道如何从角谷歌地图实例调用fitBounds()。我试图在uiGmapGoogleMapApi解析后调用它,但是我不知道在哪里/如何访问这个方法。从普通的js实现中,您可以调用map.fitBounds(界),但我不确定在角-google v2.2.1中等效的是什么,谢谢您的帮助。

编辑

我将控件属性添加到scope.map中,然后在getGMap()解析时调用uiGmapIsReady ()。

代码语言:javascript
复制
      uiGmapGoogleMapApi.then(function(maps) {
        scope.bounds = new maps.LatLngBounds();
        scope.map = {
          center: {
            latitude: 47.60427,
            longitude: -122.33825
          },
          zoom: 16,
          polys: [],
          bounds: {},
          control: {} // add this property

        };
        traceVehicle(scope.tripDetails);
      });
      // add uiGmapIsReady and call getGMap()
      uiGmapIsReady.promise(1).then(function(instances) {
        instances.forEach(function(inst) {
          var map = inst.map;
          var uuid = map.uiGmap_id;
          var mapInstanceNumber = inst.instance; // Starts at 1.
          var gMap = scope.map.control.getGMap(); // assign getGMap();
          gMap.fitBounds(scope.bounds);
        });
      });



  function traceVehicle(selectedTrip) {
    var rawPolys = [];
    var polylineObj = {
      id: 1,
      path: [],
      stroke: {
        color: '#6060FB',
        weight: 3
      },
      editable: false,
      draggable: false,
      geodesic: true,
      visible: true
    };
    scope.polylines = [];
    if(selectedTrip.locations.length > 0) {
      angular.forEach(selectedTrip.locations, function(v, i) {
        polylineObj.path.push({ latitude: v.lat, longitude: v.lon });
        scope.bounds.extend({ lat: v.lat, lng: v.lon });
      });
      rawPolys.push(polylineObj);
      scope.map = {
        center: {
          latitude: polylineObj.path[(Math.round(polylineObj.path.length/2) -1)].latitude,
          longitude: polylineObj.path[(Math.round(polylineObj.path.length/2) -1)].longitude
        },
        zoom: 16,
        polys: rawPolys
      };
      scope.map.fitBounds(scope.bounds); // how to call fitBounds()?
EN

回答 1

Stack Overflow用户

发布于 2017-05-11 00:00:45

您将需要$scope.map成为谷歌地图对象。目前这只是个选择。

代码语言:javascript
复制
var mapOptions = {
    zoom: 16,
    polys: [],
    bounds: {},
    center: new google.maps.LatLng(47.60427, -122.33825),
    mapTypeId: google.maps.MapTypeId.TERRAIN
};

$scope.map = new google.maps.Map(document.getElementById('map'), mapOptions);
$scope.map.fitBounds(YOUR_CODE_FOR_BOUNDS);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43903869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档