diff --git a/src/directives/gmMarkers.js b/src/directives/gmMarkers.js index 063ace3..3a454ca 100644 --- a/src/directives/gmMarkers.js +++ b/src/directives/gmMarkers.js @@ -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: * ``` @@ -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()); } diff --git a/test/unit/directives/gmMarkersSpec.js b/test/unit/directives/gmMarkersSpec.js index 1836efe..75d0566 100644 --- a/test/unit/directives/gmMarkersSpec.js +++ b/test/unit/directives/gmMarkersSpec.js @@ -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 {