Skip to content

Commit 4736ba9

Browse files
committed
Make gmMarkersRedraw event more flexible.
1 parent b3a742e commit 4736ba9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/directives/gmMarkers.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@
8585
*
8686
* Parameters:
8787
*
88-
* + `objects`: required. The name of the scope variable which holds the
89-
* objects to redraw markers for. This is what you set `gm-objects` to.
90-
* It is necessary because there may be multiple instances of the
91-
* `gmMarkers` directive.
88+
* + `objects`: Not required. The name of the scope variable which holds
89+
* the objects to redraw markers for, i.e. what you set `gm-objects` to.
90+
* It is useful because there may be multiple instances of the
91+
* `gmMarkers` directive. If not specified, all instances of gmMarkers
92+
* which are child scopes will redraw their markers.
9293
*
9394
* + `gmMarkersUpdated`: emitted when markers are updated. To use:
9495
* ```
@@ -219,7 +220,7 @@
219220
});
220221

221222
scope.$on('gmMarkersRedraw', function(event, objectsName) {
222-
if (objectsName === attrs.gmObjects) {
223+
if (objectsName == null || objectsName === attrs.gmObjects) {
223224
updateMarkers(scope);
224225
updateMarkers(scope, scope.gmObjects());
225226
}

test/unit/directives/gmMarkersSpec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,22 @@ describe('gmMarkers', function() {
243243
});
244244

245245

246+
it('listens to marker redraw event when no objects specified', function() {
247+
var position1 = objToLatLng(scope.people[0]);
248+
var position2 = objToLatLng(scope.people[1]);
249+
scope.getOpts = function(person) {
250+
return {
251+
key: 'differentValue',
252+
title: person.name
253+
};
254+
};
255+
scope.$broadcast('gmMarkersRedraw');
256+
257+
expect(mapCtrl.addMarker).toHaveBeenCalledWith(markersScopeId, {key: 'differentValue', title: jasmine.any(String), position: position1});
258+
expect(mapCtrl.addMarker).toHaveBeenCalledWith(markersScopeId, {key: 'differentValue', title: jasmine.any(String), position: position2});
259+
});
260+
261+
246262
it('ignores marker redraw event for other instance', function() {
247263
scope.getOpts = function(person) {
248264
return {

0 commit comments

Comments
 (0)