dylanfprice / angular-gm

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

google.maps.event.clearInstanceListeners side effets #4

Closed MatthieuBarthel closed 11 years ago

MatthieuBarthel commented 11 years ago

Hi @dylanfprice

Next to your memory leak fix, I worked with angular-gm on a project :)

I saw that a reused map didn't "reset" the center and zoom, I tried to fix it by adding those two lines in angulargmMapController.js (next the line 131) :

map.setCenter(config.center);
map.setZoom(config.zoom);

Strangely, the above setZoom doesn't work while setCenter is ok. After digging, I saw that gmMapResize neither works with a reused map. The issue comes from angulargmMapController.js, here is the breaking line :

google.maps.event.clearInstanceListeners(this._map);

I guess it's better to use 'clearListeners' method for each event that needs to be cleared, so it won't break some core functions, what do you think ?

I also have another suggestion, on my project the map has a "full screen" button, on click I modify the container position, and I $broadcast the gmMapResize event.I needed to re-center the map and update some parameters, so I added this two event listeners the same way you did :

scope.$on('gmMapResetCenter', function(event, gmMapId) {
  controller.getMap(scope.gmMapId()).setCenter(scope.gmCenter);
});

scope.$on('gmMapSet', function(event, gmMapId, param, value) {
  if (scope.gmMapId() === gmMapId) {
    controller.getMap(scope.gmMapId()).set(param, value);
  }
});
MatthieuBarthel commented 11 years ago

I've just noticed another side effect, if you use mapOptions, like scrollwheel, it won't be reset when the map is reused. I hope I'm not persecuting you too much :)