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

Commit b33d4a9

Browse files
committed
fix(circle): scope properties update again even if the event attribute
is not set in the directive issue /#1328 fixed
1 parent 2dcb004 commit b33d4a9

10 files changed

+171
-141
lines changed

dist/angular-google-maps.js

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,56 +4253,52 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
42534253
};
42544254
}
42554255
clean();
4256-
this.listeners = this.setEvents(gObject, scope, scope, ['radius_changed']);
4257-
if (this.listeners != null) {
4258-
this.listeners.push(google.maps.event.addListener(gObject, 'radius_changed', function() {
4259-
4260-
/*
4261-
possible google bug, and or because a circle has two radii
4262-
radius_changed appears to fire twice (original and new) which is not too helpful
4263-
therefore we will check for radius changes manually and bail out if nothing has changed
4264-
*/
4265-
var newRadius, work;
4266-
newRadius = gObject.getRadius();
4267-
if (newRadius === lastRadius) {
4268-
return;
4269-
}
4270-
lastRadius = newRadius;
4271-
work = function() {
4272-
return _settingFromDirective(scope, function() {
4273-
var ref, ref1;
4274-
if (newRadius !== scope.radius) {
4275-
scope.radius = newRadius;
4276-
}
4277-
if (((ref = scope.events) != null ? ref.radius_changed : void 0) && _.isFunction((ref1 = scope.events) != null ? ref1.radius_changed : void 0)) {
4278-
return scope.events.radius_changed(gObject, 'radius_changed', scope, arguments);
4279-
}
4280-
});
4281-
};
4282-
if (!angular.mock) {
4283-
return scope.$evalAsync(function() {
4284-
return work();
4285-
});
4286-
} else {
4287-
return work();
4288-
}
4289-
}));
4290-
}
4291-
if (this.listeners != null) {
4292-
this.listeners.push(google.maps.event.addListener(gObject, 'center_changed', function() {
4256+
this.listeners = this.setEvents(gObject, scope, scope, ['radius_changed']) || [];
4257+
this.listeners.push(google.maps.event.addListener(gObject, 'radius_changed', function() {
4258+
4259+
/*
4260+
possible google bug, and or because a circle has two radii
4261+
radius_changed appears to fire twice (original and new) which is not too helpful
4262+
therefore we will check for radius changes manually and bail out if nothing has changed
4263+
*/
4264+
var newRadius, work;
4265+
newRadius = gObject.getRadius();
4266+
if (newRadius === lastRadius) {
4267+
return;
4268+
}
4269+
lastRadius = newRadius;
4270+
work = function() {
4271+
return _settingFromDirective(scope, function() {
4272+
var ref, ref1;
4273+
if (newRadius !== scope.radius) {
4274+
scope.radius = newRadius;
4275+
}
4276+
if (((ref = scope.events) != null ? ref.radius_changed : void 0) && _.isFunction((ref1 = scope.events) != null ? ref1.radius_changed : void 0)) {
4277+
return scope.events.radius_changed(gObject, 'radius_changed', scope, arguments);
4278+
}
4279+
});
4280+
};
4281+
if (!angular.mock) {
42934282
return scope.$evalAsync(function() {
4294-
return _settingFromDirective(scope, function() {
4295-
if (angular.isDefined(scope.center.type)) {
4296-
scope.center.coordinates[1] = gObject.getCenter().lat();
4297-
return scope.center.coordinates[0] = gObject.getCenter().lng();
4298-
} else {
4299-
scope.center.latitude = gObject.getCenter().lat();
4300-
return scope.center.longitude = gObject.getCenter().lng();
4301-
}
4302-
});
4283+
return work();
43034284
});
4304-
}));
4305-
}
4285+
} else {
4286+
return work();
4287+
}
4288+
}));
4289+
this.listeners.push(google.maps.event.addListener(gObject, 'center_changed', function() {
4290+
return scope.$evalAsync(function() {
4291+
return _settingFromDirective(scope, function() {
4292+
if (angular.isDefined(scope.center.type)) {
4293+
scope.center.coordinates[1] = gObject.getCenter().lat();
4294+
return scope.center.coordinates[0] = gObject.getCenter().lng();
4295+
} else {
4296+
scope.center.latitude = gObject.getCenter().lat();
4297+
return scope.center.longitude = gObject.getCenter().lng();
4298+
}
4299+
});
4300+
});
4301+
}));
43064302
scope.$on('$destroy', (function(_this) {
43074303
return function() {
43084304
clean();

dist/angular-google-maps.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps_dev_mapped.js

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4253,56 +4253,52 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
42534253
};
42544254
}
42554255
clean();
4256-
this.listeners = this.setEvents(gObject, scope, scope, ['radius_changed']);
4257-
if (this.listeners != null) {
4258-
this.listeners.push(google.maps.event.addListener(gObject, 'radius_changed', function() {
4259-
4260-
/*
4261-
possible google bug, and or because a circle has two radii
4262-
radius_changed appears to fire twice (original and new) which is not too helpful
4263-
therefore we will check for radius changes manually and bail out if nothing has changed
4264-
*/
4265-
var newRadius, work;
4266-
newRadius = gObject.getRadius();
4267-
if (newRadius === lastRadius) {
4268-
return;
4269-
}
4270-
lastRadius = newRadius;
4271-
work = function() {
4272-
return _settingFromDirective(scope, function() {
4273-
var ref, ref1;
4274-
if (newRadius !== scope.radius) {
4275-
scope.radius = newRadius;
4276-
}
4277-
if (((ref = scope.events) != null ? ref.radius_changed : void 0) && _.isFunction((ref1 = scope.events) != null ? ref1.radius_changed : void 0)) {
4278-
return scope.events.radius_changed(gObject, 'radius_changed', scope, arguments);
4279-
}
4280-
});
4281-
};
4282-
if (!angular.mock) {
4283-
return scope.$evalAsync(function() {
4284-
return work();
4285-
});
4286-
} else {
4287-
return work();
4288-
}
4289-
}));
4290-
}
4291-
if (this.listeners != null) {
4292-
this.listeners.push(google.maps.event.addListener(gObject, 'center_changed', function() {
4256+
this.listeners = this.setEvents(gObject, scope, scope, ['radius_changed']) || [];
4257+
this.listeners.push(google.maps.event.addListener(gObject, 'radius_changed', function() {
4258+
4259+
/*
4260+
possible google bug, and or because a circle has two radii
4261+
radius_changed appears to fire twice (original and new) which is not too helpful
4262+
therefore we will check for radius changes manually and bail out if nothing has changed
4263+
*/
4264+
var newRadius, work;
4265+
newRadius = gObject.getRadius();
4266+
if (newRadius === lastRadius) {
4267+
return;
4268+
}
4269+
lastRadius = newRadius;
4270+
work = function() {
4271+
return _settingFromDirective(scope, function() {
4272+
var ref, ref1;
4273+
if (newRadius !== scope.radius) {
4274+
scope.radius = newRadius;
4275+
}
4276+
if (((ref = scope.events) != null ? ref.radius_changed : void 0) && _.isFunction((ref1 = scope.events) != null ? ref1.radius_changed : void 0)) {
4277+
return scope.events.radius_changed(gObject, 'radius_changed', scope, arguments);
4278+
}
4279+
});
4280+
};
4281+
if (!angular.mock) {
42934282
return scope.$evalAsync(function() {
4294-
return _settingFromDirective(scope, function() {
4295-
if (angular.isDefined(scope.center.type)) {
4296-
scope.center.coordinates[1] = gObject.getCenter().lat();
4297-
return scope.center.coordinates[0] = gObject.getCenter().lng();
4298-
} else {
4299-
scope.center.latitude = gObject.getCenter().lat();
4300-
return scope.center.longitude = gObject.getCenter().lng();
4301-
}
4302-
});
4283+
return work();
43034284
});
4304-
}));
4305-
}
4285+
} else {
4286+
return work();
4287+
}
4288+
}));
4289+
this.listeners.push(google.maps.event.addListener(gObject, 'center_changed', function() {
4290+
return scope.$evalAsync(function() {
4291+
return _settingFromDirective(scope, function() {
4292+
if (angular.isDefined(scope.center.type)) {
4293+
scope.center.coordinates[1] = gObject.getCenter().lat();
4294+
return scope.center.coordinates[0] = gObject.getCenter().lng();
4295+
} else {
4296+
scope.center.latitude = gObject.getCenter().lat();
4297+
return scope.center.longitude = gObject.getCenter().lng();
4298+
}
4299+
});
4300+
});
4301+
}));
43064302
scope.$on('$destroy', (function(_this) {
43074303
return function() {
43084304
clean();

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.

dist/angular-google-maps_dev_mapped.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps_dev_mapped.min.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.

spec/coffee/bootstrap.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ beforeEach ->
3232
center:
3333
longitude: 47
3434
latitude: -27
35-
35+
3636
@timeout = $timeout
3737
@compile = $compile
3838

39-
@digest = (fn) =>
40-
@compile(@html)(@scope) if @html and @scope
39+
@digest = (fn, doCompile = true) =>
40+
@compile(@html)(@scope) if @html and @scope and doCompile
4141

4242
fn() if fn? and _.isFunction fn
4343
while @timeout.hasPendingTasks()

spec/coffee/directives/api/circle.spec.coffee

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,44 @@ describe 'uiGmapCircle', ->
108108
done()
109109
, 500
110110

111+
it 'change center if directive events is not defined', (done) ->
112+
#issue 1271
113+
@html = """
114+
<ui-gmap-google-map draggable="true" center="map.center" zoom="map.zoom">
115+
<ui-gmap-circle center='map.circle.center'
116+
radius='map.circle.radius'
117+
fill='map.circle.fill'
118+
stroke='map.circle.stroke'
119+
clickable='map.circle.clickable'
120+
draggable='map.circle.draggable'
121+
editable='map.circle.editable'
122+
visible='map.circle.visible'
123+
control='map.circle.control'>
124+
</ui-gmap-circle>
125+
</ui-gmap-google-map>
126+
"""
127+
128+
@digest =>
129+
@timeout =>
130+
@digest =>
131+
listener = GCircle.creationSubscribe @, (gObject) =>
132+
_.delay =>
133+
gObject.setCenter
134+
lat: ->
135+
-50
136+
lng: ->
137+
50
138+
139+
window.google.maps.event.fireListener(gObject,'center_changed')
140+
@digest =>
141+
@timeout =>
142+
expect(@scope.map.circle.center.longitude).toBe(50)
143+
expect(@scope.map.circle.center.latitude).toBe(-50)
144+
done()
145+
, false
146+
, 200
147+
, 500
148+
, false
111149
it 'change radius does not fire center_changed', (done) ->
112150
listener = GCircle.creationSubscribe @, (gObject) =>
113151
_.delay =>

spec/coffee/helpers/google-api-mock.coffee

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ angular.module('uiGmapgoogle-maps.mocks', ['uiGmapgoogle-maps'])
127127
@props= ['draggable', 'editable', 'map','visible', 'radius', 'center']
128128
@setOptions opts
129129

130-
Circle.instances += 1
131-
if window?.google?.maps?.event?
132-
window.google.maps.event.fireAllListeners 'creation', @
133-
134130
#getters
135131
@props.forEach (p) =>
136132
@["get#{capitalize p}"] = =>
@@ -143,6 +139,11 @@ angular.module('uiGmapgoogle-maps.mocks', ['uiGmapgoogle-maps'])
143139
if p == "radius" or p == "center"
144140
window.google.maps.event.fireAllListeners "#{p}_changed", @
145141

142+
Circle.instances += 1
143+
@instance = Circle.instances
144+
if window?.google?.maps?.event?
145+
window.google.maps.event.fireAllListeners 'creation', @
146+
146147
setOptions: (o)=>
147148
super(o)
148149
_.extend @, o

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

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,42 @@ angular.module('uiGmapgoogle-maps.directives.api.models.parent')
4242
gObject
4343

4444
clean()
45-
@listeners = @setEvents gObject, scope, scope, ['radius_changed']
46-
if @listeners?
47-
@listeners.push google.maps.event.addListener gObject, 'radius_changed', ->
48-
###
49-
possible google bug, and or because a circle has two radii
50-
radius_changed appears to fire twice (original and new) which is not too helpful
51-
therefore we will check for radius changes manually and bail out if nothing has changed
52-
###
45+
@listeners = @setEvents(gObject, scope, scope, ['radius_changed']) or [] #or needed incase no-one is listening in controller
46+
@listeners.push google.maps.event.addListener gObject, 'radius_changed', ->
47+
###
48+
possible google bug, and or because a circle has two radii
49+
radius_changed appears to fire twice (original and new) which is not too helpful
50+
therefore we will check for radius changes manually and bail out if nothing has changed
51+
###
5352

54-
newRadius = gObject.getRadius()
55-
return if newRadius == lastRadius
53+
newRadius = gObject.getRadius()
54+
return if newRadius == lastRadius
5655

57-
lastRadius = newRadius
56+
lastRadius = newRadius
5857

59-
work = ->
60-
_settingFromDirective scope, ->
61-
scope.radius = newRadius if newRadius != scope.radius
62-
if scope.events?.radius_changed and _.isFunction scope.events?.radius_changed
63-
scope.events.radius_changed(gObject, 'radius_changed', scope, arguments)
58+
work = ->
59+
_settingFromDirective scope, ->
60+
scope.radius = newRadius if newRadius != scope.radius
61+
if scope.events?.radius_changed and _.isFunction scope.events?.radius_changed
62+
scope.events.radius_changed(gObject, 'radius_changed', scope, arguments)
6463

65-
# hack
66-
# for some reason in specs I can not get $evalAsync to fire.. im tired of wasting time on this
67-
if not angular.mock
68-
scope.$evalAsync ->
69-
work()
70-
else
71-
work()
72-
if @listeners?
73-
@listeners.push google.maps.event.addListener gObject, 'center_changed', ->
64+
# hack
65+
# for some reason in specs I can not get $evalAsync to fire.. im tired of wasting time on this
66+
if not angular.mock
7467
scope.$evalAsync ->
75-
_settingFromDirective scope, ->
76-
if angular.isDefined(scope.center.type)
77-
scope.center.coordinates[1] = gObject.getCenter().lat()
78-
scope.center.coordinates[0] = gObject.getCenter().lng()
79-
else
80-
scope.center.latitude = gObject.getCenter().lat()
81-
scope.center.longitude = gObject.getCenter().lng()
68+
work()
69+
else
70+
work()
71+
72+
@listeners.push google.maps.event.addListener gObject, 'center_changed', ->
73+
scope.$evalAsync ->
74+
_settingFromDirective scope, ->
75+
if angular.isDefined(scope.center.type)
76+
scope.center.coordinates[1] = gObject.getCenter().lat()
77+
scope.center.coordinates[0] = gObject.getCenter().lng()
78+
else
79+
scope.center.latitude = gObject.getCenter().lat()
80+
scope.center.longitude = gObject.getCenter().lng()
8281

8382

8483
scope.$on '$destroy', =>

0 commit comments

Comments
 (0)