Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 05c155b

Browse files
committed
better event handling
1 parent 24f52d1 commit 05c155b

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed

dist/angular-google-maps.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,16 +2150,18 @@ Nicholas McCready - https://twitter.com/nmccready
21502150
return SpiderfierMarkerManager = (function() {
21512151
SpiderfierMarkerManager.type = 'SpiderfierMarkerManager';
21522152

2153-
function SpiderfierMarkerManager(gMap, opt_markers, opt_options, opt_events) {
2153+
function SpiderfierMarkerManager(gMap, opt_markers, opt_options, opt_events, scope) {
21542154
if (opt_markers == null) {
21552155
opt_markers = {};
21562156
}
21572157
this.opt_options = opt_options != null ? opt_options : {};
21582158
this.opt_events = opt_events;
2159+
this.scope = scope;
21592160
this.checkSync = bind(this.checkSync, this);
21602161
this.getGMarkers = bind(this.getGMarkers, this);
21612162
this.fit = bind(this.fit, this);
21622163
this.destroy = bind(this.destroy, this);
2164+
this.attachEvents = bind(this.attachEvents, this);
21632165
this.clear = bind(this.clear, this);
21642166
this.draw = bind(this.draw, this);
21652167
this.removeMany = bind(this.removeMany, this);
@@ -2231,19 +2233,21 @@ Nicholas McCready - https://twitter.com/nmccready
22312233
};
22322234

22332235
SpiderfierMarkerManager.prototype.attachEvents = function(options, optionsName) {
2234-
var eventHandler, eventName, results;
22352236
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
2236-
results = [];
2237-
for (eventName in options) {
2238-
eventHandler = options[eventName];
2239-
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
2240-
$log.info(optionsName + ": Attaching event: " + eventName + " to clusterer");
2241-
results.push(this.clusterer.addListener(eventName, options[eventName]));
2242-
} else {
2243-
results.push(void 0);
2244-
}
2245-
}
2246-
return results;
2237+
return _.each(options, (function(_this) {
2238+
return function(eventHandler, eventName) {
2239+
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
2240+
$log.info(optionsName + ": Attaching event: " + eventName + " to clusterer");
2241+
return _this.clusterer.addListener(eventName, function() {
2242+
if (eventName === 'spiderfy' || eventName === 'unspiderfy') {
2243+
return _this.scope.$evalAsync(options[eventName].apply(options, arguments));
2244+
} else {
2245+
return _this.scope.$evalAsync(options[eventName].apply(options, [arguments[0], eventName, arguments[0].model, arguments]));
2246+
}
2247+
});
2248+
}
2249+
};
2250+
})(this));
22472251
}
22482252
};
22492253

@@ -4828,7 +4832,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
48284832
if (typeEvents != null) {
48294833
this.bindToTypeEvents(typeEvents, ['spiderfy', 'unspiderfy']);
48304834
}
4831-
this.gManager = new SpiderfierMarkerManager(this.map, void 0, typeOptions, typeEvents);
4835+
this.gManager = new SpiderfierMarkerManager(this.map, void 0, typeOptions, typeEvents, this.scope);
48324836
} else {
48334837
this.gManager = new MarkerManager(this.map);
48344838
}

dist/angular-google-maps_dev_mapped.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,16 +2150,18 @@ Nicholas McCready - https://twitter.com/nmccready
21502150
return SpiderfierMarkerManager = (function() {
21512151
SpiderfierMarkerManager.type = 'SpiderfierMarkerManager';
21522152

2153-
function SpiderfierMarkerManager(gMap, opt_markers, opt_options, opt_events) {
2153+
function SpiderfierMarkerManager(gMap, opt_markers, opt_options, opt_events, scope) {
21542154
if (opt_markers == null) {
21552155
opt_markers = {};
21562156
}
21572157
this.opt_options = opt_options != null ? opt_options : {};
21582158
this.opt_events = opt_events;
2159+
this.scope = scope;
21592160
this.checkSync = bind(this.checkSync, this);
21602161
this.getGMarkers = bind(this.getGMarkers, this);
21612162
this.fit = bind(this.fit, this);
21622163
this.destroy = bind(this.destroy, this);
2164+
this.attachEvents = bind(this.attachEvents, this);
21632165
this.clear = bind(this.clear, this);
21642166
this.draw = bind(this.draw, this);
21652167
this.removeMany = bind(this.removeMany, this);
@@ -2231,19 +2233,21 @@ Nicholas McCready - https://twitter.com/nmccready
22312233
};
22322234

22332235
SpiderfierMarkerManager.prototype.attachEvents = function(options, optionsName) {
2234-
var eventHandler, eventName, results;
22352236
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
2236-
results = [];
2237-
for (eventName in options) {
2238-
eventHandler = options[eventName];
2239-
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
2240-
$log.info(optionsName + ": Attaching event: " + eventName + " to clusterer");
2241-
results.push(this.clusterer.addListener(eventName, options[eventName]));
2242-
} else {
2243-
results.push(void 0);
2244-
}
2245-
}
2246-
return results;
2237+
return _.each(options, (function(_this) {
2238+
return function(eventHandler, eventName) {
2239+
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
2240+
$log.info(optionsName + ": Attaching event: " + eventName + " to clusterer");
2241+
return _this.clusterer.addListener(eventName, function() {
2242+
if (eventName === 'spiderfy' || eventName === 'unspiderfy') {
2243+
return _this.scope.$evalAsync(options[eventName].apply(options, arguments));
2244+
} else {
2245+
return _this.scope.$evalAsync(options[eventName].apply(options, [arguments[0], eventName, arguments[0].model, arguments]));
2246+
}
2247+
});
2248+
}
2249+
};
2250+
})(this));
22472251
}
22482252
};
22492253

@@ -4828,7 +4832,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
48284832
if (typeEvents != null) {
48294833
this.bindToTypeEvents(typeEvents, ['spiderfy', 'unspiderfy']);
48304834
}
4831-
this.gManager = new SpiderfierMarkerManager(this.map, void 0, typeOptions, typeEvents);
4835+
this.gManager = new SpiderfierMarkerManager(this.map, void 0, typeOptions, typeEvents, this.scope);
48324836
} else {
48334837
this.gManager = new MarkerManager(this.map);
48344838
}

dist/angular-google-maps_dev_mapped.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/coffee/directives/api/managers/spiderfier-marker-manager.coffee

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ angular.module('uiGmapgoogle-maps.directives.api.managers')
33
'uiGmapFitHelper', 'uiGmapPropMap', 'uiGmapMarkerSpiderfier', ($log, FitHelper, PropMap, MarkerSpiderfier) ->
44
class SpiderfierMarkerManager
55
@type = 'SpiderfierMarkerManager'
6-
constructor: (gMap, opt_markers={}, @opt_options = {}, @opt_events) ->
6+
constructor: (gMap, opt_markers={}, @opt_options = {}, @opt_events, @scope) ->
77
@type = SpiderfierMarkerManager.type
88

99
@clusterer = new MarkerSpiderfier gMap, @opt_options
@@ -56,12 +56,16 @@ angular.module('uiGmapgoogle-maps.directives.api.managers')
5656
clear: ()=>
5757
@removeMany @getGMarkers()
5858

59-
attachEvents: (options, optionsName) ->
59+
attachEvents: (options, optionsName) =>
6060
if angular.isDefined(options) and options? and angular.isObject(options)
61-
for eventName, eventHandler of options
61+
_.each options, (eventHandler, eventName) =>
6262
if options.hasOwnProperty(eventName) and angular.isFunction(options[eventName])
6363
$log.info "#{optionsName}: Attaching event: #{eventName} to clusterer"
64-
@clusterer.addListener eventName, options[eventName]
64+
@clusterer.addListener eventName, =>
65+
if eventName == 'spiderfy' or eventName == 'unspiderfy'
66+
@scope.$evalAsync(options[eventName](arguments...))
67+
else #for consistency to be like EventsHelper
68+
@scope.$evalAsync(options[eventName]([arguments[0], eventName, arguments[0].model, arguments]...))
6569

6670
clearEvents: (options, optionsName) ->
6771
if angular.isDefined(options) and options? and angular.isObject(options)

src/coffee/directives/api/models/parent/markers-parent-model.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ angular.module("uiGmapgoogle-maps.directives.api.models.parent")
116116
@gManager = new ClustererMarkerManager @map, undefined, typeOptions, typeEvents
117117
else if scope.type == 'spider'
118118
@bindToTypeEvents(typeEvents, ['spiderfy', 'unspiderfy']) if typeEvents?
119-
@gManager = new SpiderfierMarkerManager @map, undefined, typeOptions, typeEvents
119+
@gManager = new SpiderfierMarkerManager @map, undefined, typeOptions, typeEvents, @scope
120120
else
121121
@gManager = new MarkerManager @map
122122

0 commit comments

Comments
 (0)