Skip to content

Commit

Permalink
Added gmMapResize event to gmMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanfprice committed Jul 20, 2013
1 parent 2d461e2 commit a715cd1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/directives/gmMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
* If you need to get a handle on the google.maps.Map object, see
* [angulargmContainer]{@link module:angulargmContainer}
*
* Events:
*
* + `gmMapResize`: google.maps.event.trigger(map, 'resize') To use:
* `$scope.$broadcast('gmMapResize', 'myMapId')`
*
* Parameters:
*
* + `mapId`: required. The id of your map. This is what you set
* `gm-map-id` to. It is necessary because there may be multiple
* instances of the `gmMap` directive.
*
* @module gmMap
*/
(function () {
Expand Down Expand Up @@ -141,6 +152,12 @@
}
});
}

scope.$on('gmMapResize', function(event, gmMapId) {
if (scope.gmMapId() === gmMapId) {
controller.mapTrigger('resize');
}
});
}


Expand Down
13 changes: 13 additions & 0 deletions test/unit/directives/gmMapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('gmMap', function() {

// get MapController
mapCtrl = elm.controller('gmMap');
spyOn(mapCtrl, 'mapTrigger').andCallThrough();
var center, zoom, bounds;
Object.defineProperties(mapCtrl, {
'center': {
Expand Down Expand Up @@ -196,4 +197,16 @@ describe('gmMap', function() {
});


it('listens for map resize event', function() {
scope.$broadcast('gmMapResize', scope.mapId);
expect(mapCtrl.mapTrigger).toHaveBeenCalledWith('resize');
});


it('ignores map resize for different map', function() {
scope.$broadcast('gmMapResize', scope.mapId + 'diff');
expect(mapCtrl.mapTrigger).not.toHaveBeenCalled();
});


});

0 comments on commit a715cd1

Please sign in to comment.