【问题标题】:Fit zoom to show all markers. I already set center correctly适合缩放以显示所有标记。我已经正确设置了中心
【发布时间】:2015-07-15 06:49:54
【问题描述】:

我有一张带有多个标记的地图,我需要将它们全部放在窗口中。我正在使用移动 Angular UI:http://mobileangularui.com/ 和 Angular Google 地图:http://angular-ui.github.io/angular-google-maps/#!/

我用默认中心和缩放定义地图:

$scope.map = {
  center: {        // set on XXX as initial default
    latitude: 45.322594, 
    longitude: -2.938249 
  },
  zoom: 14,
  options: mapServices.getMapOptions().mapOptions
}; 

当我向地图添加标记时,y 扩展边界:

var markers = [];
var bounds = new google.maps.LatLngBounds();

for loop ....

var marker = {
          latitude: indicadores[i].sensores[j].lat, //43.401188,
          longitude: indicadores[i].sensores[j].lon, //-5.823359,
          title: indicadores[i].sensores[j].nombre,
          valor: getValor(indicadores[i], indicadores[i].sensores[j].ultimo_valor, indicadores[i].sensores[j].ultimo_estado),
          url: "#/sensor/" + $scope.$parent.Despliegue.id + "/"+ indicadores[i].id + "/" + indicadores[i].sensores[j].id,
          id: i,
          fit: true,
          options: { 
            icon: { url: obtenerImagen(indicadores[i].factor_ambiental, indicadores[i].sensores[j].ultimo_estado) }
          },
          showWindow: false,
        };

var latlng = new google.maps.LatLng(marker.latitude, marker.longitude);
bounds.extend(latlng);

markers.push(marker);

然后我得到中心并应用边界:

var centro = bounds.getCenter();

$scope.map.center = { 
   latitude: centro.lat(),
   longitude: centro.lng()
}

var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();

$scope.map.bounds = {
   northeast: {
      latitude: ne.lat(),
      longitude: ne.lng()
   },
   southwest: {
      latitude: sw.lat(),
      longitude: sw.lng()
   }
}

我的地图完全居中,但它不会缩放以适合所有标记。

有什么帮助吗?提前致谢!

【问题讨论】:

    标签: angularjs angular-google-maps mobile-angular-ui


    【解决方案1】:

    尝试在您的模板文件中使用标签<ui-gmap-markers> fit 选项fit="'true'"

    <ui-gmap-markers idKey="map.dynamicMarkers.id" models="map.dynamicMarkers" coords="'self'"
    fit="'true'">
    

    【讨论】:

    • 您知道如何为此定义最大缩放吗?当只有一个结果时,它会放大太多。
    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多