dylanfprice / angular-gm

AngularJS Google Maps Directives
MIT License
197 stars 47 forks source link

How do we update center? #40

Closed rohi closed 10 years ago

rohi commented 10 years ago

How do we update center of the map without redrawing the markers.

dylanfprice commented 10 years ago

If you've bound your center to a scope variable, all you need to do is set the variable to the new center you want (as a google.maps.LatLng object) and the map will update.

<div ng-controller="MyCtrl">
    <gm-map gm-center='myCenter' ...>
        <gm-markers ....></gm-markers>
    </gm-map>
    <button ng-click="updateCenter()"></button>
</div>
function MyCtrl($scope) {
    $scope.updateCenter = function() {
        $scope.myCenter = new google.maps.LatLng(newLat, newLng);
    };
}
jraede commented 10 years ago

This doesn't seem to be working in 1.0: http://jsfiddle.net/znyqN/

NoelOConnell commented 10 years ago

@jraede

It works fine just a small thing to change in your jsfiddle. Change gm-zoom="zoom" to gm-zoom="options.map.zoom" so now the scopes match.

jraede commented 10 years ago

Ok cool. So then what's the point of gm-map-options if it doesn't correctly do the two-way binding? I have no problem typing "options.map" every time for the various attributes but you should make this clear in the documentation so nobody gets confused.