Skip to content

Commit

Permalink
Make gmMarkersRedraw event more flexible.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanfprice committed Jul 20, 2013
1 parent b3a742e commit 4736ba9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/directives/gmMarkers.js
Expand Up @@ -85,10 +85,11 @@
*
* Parameters:
*
* + `objects`: required. The name of the scope variable which holds the
* objects to redraw markers for. This is what you set `gm-objects` to.
* It is necessary because there may be multiple instances of the
* `gmMarkers` directive.
* + `objects`: Not required. The name of the scope variable which holds
* the objects to redraw markers for, i.e. what you set `gm-objects` to.
* It is useful because there may be multiple instances of the
* `gmMarkers` directive. If not specified, all instances of gmMarkers
* which are child scopes will redraw their markers.
*
* + `gmMarkersUpdated`: emitted when markers are updated. To use:
* ```
Expand Down Expand Up @@ -219,7 +220,7 @@
});

scope.$on('gmMarkersRedraw', function(event, objectsName) {
if (objectsName === attrs.gmObjects) {
if (objectsName == null || objectsName === attrs.gmObjects) {
updateMarkers(scope);
updateMarkers(scope, scope.gmObjects());
}
Expand Down
16 changes: 16 additions & 0 deletions test/unit/directives/gmMarkersSpec.js
Expand Up @@ -243,6 +243,22 @@ describe('gmMarkers', function() {
});


it('listens to marker redraw event when no objects specified', function() {
var position1 = objToLatLng(scope.people[0]);
var position2 = objToLatLng(scope.people[1]);
scope.getOpts = function(person) {
return {
key: 'differentValue',
title: person.name
};
};
scope.$broadcast('gmMarkersRedraw');

expect(mapCtrl.addMarker).toHaveBeenCalledWith(markersScopeId, {key: 'differentValue', title: jasmine.any(String), position: position1});
expect(mapCtrl.addMarker).toHaveBeenCalledWith(markersScopeId, {key: 'differentValue', title: jasmine.any(String), position: position2});
});


it('ignores marker redraw event for other instance', function() {
scope.getOpts = function(person) {
return {
Expand Down

0 comments on commit 4736ba9

Please sign in to comment.