5

Sto provando a impostare i limiti nell'istanza di Google Maps ma senza successo. Uso il modulo AngularJS e il modulo angular-google-maps. Il mio ultimo tentativo è stato:Imposta i limiti di Google Maps con angular-google-maps

<div id="map_canvas"> 
    <ui-gmap-google-map 
     center="map.center" 
     zoom="map.zoom" 
     bounds="map.bounds" 
     options="options"> 

     <div ng-repeat="d in devicesMarkers track by d.id"> 

      <ui-gmap-marker 
       idkey="d.id" 
       coords="d.center" 
       options="d.options"> 
      </ui-gmap-marker> 
      <ui-gmap-circle 
       center="d.center" 
       stroke="d.circle.stroke" 
       fill="d.circle.fill" 
       radius="d.circle.radius" 
       visible="d.options.visible"> 
      </ui-gmap-circle> 

     </div> 

    </ui-gmap-google-map> 
</div> 

Nel mio app.js ho scritto:

(...) 
.controller('TaihMapController', ['$scope', '$log', 'uiGmapGoogleMapApi', function($scope, $log, GoogleMapApi) { 
    $scope.devicesMarkers = devices; 
    $scope.map = { 
     center: { latitude: devices[0].center.latitude, longitude: devices[0].center.longitude }, 
     zoom: 12, 
     bounds: {} 
     // fit: true, 
    }; 
    GoogleMapApi.then(function(maps) { 
     $log.debug(maps); 
     var myBounds = new maps.LatLngBounds(); 
     for (var k = 0; k < devices.length; k++) { 
      var _tmp_position = new maps.LatLng(
       devices[k].center.latitude, 
       devices[k].center.longitude); 
      myBounds.extend(_tmp_position); 
     } 
    $scope.map.bounds = myBounds; 
    $scope.googleVersion = maps.version; 
    // $scope.bounds = myBounds; 
    // $scope.zoom = maps.getZoom(); 
    // maps.fitBounds(myBounds); 
    // $scope.bounds = maps.getBounds(); 

}); 

La funzione maps.fitBounds() non esiste. Provo l'approccio $scope.map.bounds, ma non ho risposto come penso.

+0

Prendere un'occhiata a [questo] (https://github.com/angular-ui/angular-google-maps/blob/master /example/example.html) github, e prova a cercare 'bounds', c'è un sacco di codice relativo ad esso. – bjiang

+0

Ho letto questo file, nessun successo ancora. Questo elenco contiene il nuovo approccio (basato sul file suggerito) https://gist.github.com/vitorcarvalhoml/62f804cd197572f28079 Come posso impostare map.center e map.zoom in base ai limiti? –

risposta

2

Secondo docs, i limiti delle direttive sono leggermente diversi con i limiti di google maps. È necessario impostare in modo esplicito gli attributi e southwest con il proprio latitude e longitude.

seguito dovrebbe funzionare:

$scope.map.bounds = { 
    northeast: { 
     latitude: myBounds.getNorthEast().lat(), 
     longitude: myBounds.getNorthEast().lng() 
    }, 
    southwest: { 
     latitude: myBounds.getSouthWest().lat(), 
     longitude: myBounds.getSouthWest().lng() 
    } 
}; 
+0

E inserire questi valori, ad esempio, nelle costanti di Angular - perché all'interno del controller smette di funzionare dopo il primo utilizzo. –

8

se si sta utilizzando di angolare-google-map direttiva "marcatori", basta aggiungere la misura = attributo "true" (ui-gmap-marcatori).

Esempio:

<ui-gmap-google-map center="map.center" zoom="map.zoom" options="map.options"> <ui-gmap-markers fit="true" models="markers" coords="'self'"></ui-gmap-markers> </ui-gmap-google-map>

Fonte: https://stackoverflow.com/a/29707965

Problemi correlati