Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 44 additions & 48 deletions dist/angular-google-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4253,56 +4253,52 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
};
}
clean();
this.listeners = this.setEvents(gObject, scope, scope, ['radius_changed']);
if (this.listeners != null) {
this.listeners.push(google.maps.event.addListener(gObject, 'radius_changed', function() {

/*
possible google bug, and or because a circle has two radii
radius_changed appears to fire twice (original and new) which is not too helpful
therefore we will check for radius changes manually and bail out if nothing has changed
*/
var newRadius, work;
newRadius = gObject.getRadius();
if (newRadius === lastRadius) {
return;
}
lastRadius = newRadius;
work = function() {
return _settingFromDirective(scope, function() {
var ref, ref1;
if (newRadius !== scope.radius) {
scope.radius = newRadius;
}
if (((ref = scope.events) != null ? ref.radius_changed : void 0) && _.isFunction((ref1 = scope.events) != null ? ref1.radius_changed : void 0)) {
return scope.events.radius_changed(gObject, 'radius_changed', scope, arguments);
}
});
};
if (!angular.mock) {
return scope.$evalAsync(function() {
return work();
});
} else {
return work();
}
}));
}
if (this.listeners != null) {
this.listeners.push(google.maps.event.addListener(gObject, 'center_changed', function() {
this.listeners = this.setEvents(gObject, scope, scope, ['radius_changed']) || [];
this.listeners.push(google.maps.event.addListener(gObject, 'radius_changed', function() {

/*
possible google bug, and or because a circle has two radii
radius_changed appears to fire twice (original and new) which is not too helpful
therefore we will check for radius changes manually and bail out if nothing has changed
*/
var newRadius, work;
newRadius = gObject.getRadius();
if (newRadius === lastRadius) {
return;
}
lastRadius = newRadius;
work = function() {
return _settingFromDirective(scope, function() {
var ref, ref1;
if (newRadius !== scope.radius) {
scope.radius = newRadius;
}
if (((ref = scope.events) != null ? ref.radius_changed : void 0) && _.isFunction((ref1 = scope.events) != null ? ref1.radius_changed : void 0)) {
return scope.events.radius_changed(gObject, 'radius_changed', scope, arguments);
}
});
};
if (!angular.mock) {
return scope.$evalAsync(function() {
return _settingFromDirective(scope, function() {
if (angular.isDefined(scope.center.type)) {
scope.center.coordinates[1] = gObject.getCenter().lat();
return scope.center.coordinates[0] = gObject.getCenter().lng();
} else {
scope.center.latitude = gObject.getCenter().lat();
return scope.center.longitude = gObject.getCenter().lng();
}
});
return work();
});
}));
}
} else {
return work();
}
}));
this.listeners.push(google.maps.event.addListener(gObject, 'center_changed', function() {
return scope.$evalAsync(function() {
return _settingFromDirective(scope, function() {
if (angular.isDefined(scope.center.type)) {
scope.center.coordinates[1] = gObject.getCenter().lat();
return scope.center.coordinates[0] = gObject.getCenter().lng();
} else {
scope.center.latitude = gObject.getCenter().lat();
return scope.center.longitude = gObject.getCenter().lng();
}
});
});
}));
scope.$on('$destroy', (function(_this) {
return function() {
clean();
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-google-maps.min.js

Large diffs are not rendered by default.

92 changes: 44 additions & 48 deletions dist/angular-google-maps_dev_mapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -4253,56 +4253,52 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
};
}
clean();
this.listeners = this.setEvents(gObject, scope, scope, ['radius_changed']);
if (this.listeners != null) {
this.listeners.push(google.maps.event.addListener(gObject, 'radius_changed', function() {

/*
possible google bug, and or because a circle has two radii
radius_changed appears to fire twice (original and new) which is not too helpful
therefore we will check for radius changes manually and bail out if nothing has changed
*/
var newRadius, work;
newRadius = gObject.getRadius();
if (newRadius === lastRadius) {
return;
}
lastRadius = newRadius;
work = function() {
return _settingFromDirective(scope, function() {
var ref, ref1;
if (newRadius !== scope.radius) {
scope.radius = newRadius;
}
if (((ref = scope.events) != null ? ref.radius_changed : void 0) && _.isFunction((ref1 = scope.events) != null ? ref1.radius_changed : void 0)) {
return scope.events.radius_changed(gObject, 'radius_changed', scope, arguments);
}
});
};
if (!angular.mock) {
return scope.$evalAsync(function() {
return work();
});
} else {
return work();
}
}));
}
if (this.listeners != null) {
this.listeners.push(google.maps.event.addListener(gObject, 'center_changed', function() {
this.listeners = this.setEvents(gObject, scope, scope, ['radius_changed']) || [];
this.listeners.push(google.maps.event.addListener(gObject, 'radius_changed', function() {

/*
possible google bug, and or because a circle has two radii
radius_changed appears to fire twice (original and new) which is not too helpful
therefore we will check for radius changes manually and bail out if nothing has changed
*/
var newRadius, work;
newRadius = gObject.getRadius();
if (newRadius === lastRadius) {
return;
}
lastRadius = newRadius;
work = function() {
return _settingFromDirective(scope, function() {
var ref, ref1;
if (newRadius !== scope.radius) {
scope.radius = newRadius;
}
if (((ref = scope.events) != null ? ref.radius_changed : void 0) && _.isFunction((ref1 = scope.events) != null ? ref1.radius_changed : void 0)) {
return scope.events.radius_changed(gObject, 'radius_changed', scope, arguments);
}
});
};
if (!angular.mock) {
return scope.$evalAsync(function() {
return _settingFromDirective(scope, function() {
if (angular.isDefined(scope.center.type)) {
scope.center.coordinates[1] = gObject.getCenter().lat();
return scope.center.coordinates[0] = gObject.getCenter().lng();
} else {
scope.center.latitude = gObject.getCenter().lat();
return scope.center.longitude = gObject.getCenter().lng();
}
});
return work();
});
}));
}
} else {
return work();
}
}));
this.listeners.push(google.maps.event.addListener(gObject, 'center_changed', function() {
return scope.$evalAsync(function() {
return _settingFromDirective(scope, function() {
if (angular.isDefined(scope.center.type)) {
scope.center.coordinates[1] = gObject.getCenter().lat();
return scope.center.coordinates[0] = gObject.getCenter().lng();
} else {
scope.center.latitude = gObject.getCenter().lat();
return scope.center.longitude = gObject.getCenter().lng();
}
});
});
}));
scope.$on('$destroy', (function(_this) {
return function() {
clean();
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-google-maps_dev_mapped.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/angular-google-maps_dev_mapped.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/angular-google-maps_dev_mapped.min.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions spec/coffee/bootstrap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ beforeEach ->
center:
longitude: 47
latitude: -27

@timeout = $timeout
@compile = $compile

@digest = (fn) =>
@compile(@html)(@scope) if @html and @scope
@digest = (fn, doCompile = true) =>
@compile(@html)(@scope) if @html and @scope and doCompile

fn() if fn? and _.isFunction fn
while @timeout.hasPendingTasks()
Expand Down
38 changes: 38 additions & 0 deletions spec/coffee/directives/api/circle.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,44 @@ describe 'uiGmapCircle', ->
done()
, 500

it 'change center if directive events is not defined', (done) ->
#issue 1271
@html = """
<ui-gmap-google-map draggable="true" center="map.center" zoom="map.zoom">
<ui-gmap-circle center='map.circle.center'
radius='map.circle.radius'
fill='map.circle.fill'
stroke='map.circle.stroke'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no event attribute set which without this fix was failing

clickable='map.circle.clickable'
draggable='map.circle.draggable'
editable='map.circle.editable'
visible='map.circle.visible'
control='map.circle.control'>
</ui-gmap-circle>
</ui-gmap-google-map>
"""

@digest =>
@timeout =>
@digest =>
listener = GCircle.creationSubscribe @, (gObject) =>
_.delay =>
gObject.setCenter
lat: ->
-50
lng: ->
50

window.google.maps.event.fireListener(gObject,'center_changed')
@digest =>
@timeout =>
expect(@scope.map.circle.center.longitude).toBe(50)
expect(@scope.map.circle.center.latitude).toBe(-50)
done()
, false
, 200
, 500
, false
it 'change radius does not fire center_changed', (done) ->
listener = GCircle.creationSubscribe @, (gObject) =>
_.delay =>
Expand Down
9 changes: 5 additions & 4 deletions spec/coffee/helpers/google-api-mock.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ angular.module('uiGmapgoogle-maps.mocks', ['uiGmapgoogle-maps'])
@props= ['draggable', 'editable', 'map','visible', 'radius', 'center']
@setOptions opts

Circle.instances += 1
if window?.google?.maps?.event?
window.google.maps.event.fireAllListeners 'creation', @

#getters
@props.forEach (p) =>
@["get#{capitalize p}"] = =>
Expand All @@ -143,6 +139,11 @@ angular.module('uiGmapgoogle-maps.mocks', ['uiGmapgoogle-maps'])
if p == "radius" or p == "center"
window.google.maps.event.fireAllListeners "#{p}_changed", @

Circle.instances += 1
@instance = Circle.instances
if window?.google?.maps?.event?
window.google.maps.event.fireAllListeners 'creation', @

setOptions: (o)=>
super(o)
_.extend @, o
Expand Down
63 changes: 31 additions & 32 deletions src/coffee/directives/api/models/parent/circle-parent-model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,42 @@ angular.module('uiGmapgoogle-maps.directives.api.models.parent')
gObject

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main problem here @listeners needs to be set to [] even if scope.events is null

@listeners.push google.maps.event.addListener gObject, 'radius_changed', ->
###
possible google bug, and or because a circle has two radii
radius_changed appears to fire twice (original and new) which is not too helpful
therefore we will check for radius changes manually and bail out if nothing has changed
###

newRadius = gObject.getRadius()
return if newRadius == lastRadius
newRadius = gObject.getRadius()
return if newRadius == lastRadius

lastRadius = newRadius
lastRadius = newRadius

work = ->
_settingFromDirective scope, ->
scope.radius = newRadius if newRadius != scope.radius
if scope.events?.radius_changed and _.isFunction scope.events?.radius_changed
scope.events.radius_changed(gObject, 'radius_changed', scope, arguments)
work = ->
_settingFromDirective scope, ->
scope.radius = newRadius if newRadius != scope.radius
if scope.events?.radius_changed and _.isFunction scope.events?.radius_changed
scope.events.radius_changed(gObject, 'radius_changed', scope, arguments)

# hack
# for some reason in specs I can not get $evalAsync to fire.. im tired of wasting time on this
if not angular.mock
scope.$evalAsync ->
work()
else
work()
if @listeners?
@listeners.push google.maps.event.addListener gObject, 'center_changed', ->
# hack
# for some reason in specs I can not get $evalAsync to fire.. im tired of wasting time on this
if not angular.mock
scope.$evalAsync ->
_settingFromDirective scope, ->
if angular.isDefined(scope.center.type)
scope.center.coordinates[1] = gObject.getCenter().lat()
scope.center.coordinates[0] = gObject.getCenter().lng()
else
scope.center.latitude = gObject.getCenter().lat()
scope.center.longitude = gObject.getCenter().lng()
work()
else
work()

@listeners.push google.maps.event.addListener gObject, 'center_changed', ->
scope.$evalAsync ->
_settingFromDirective scope, ->
if angular.isDefined(scope.center.type)
scope.center.coordinates[1] = gObject.getCenter().lat()
scope.center.coordinates[0] = gObject.getCenter().lng()
else
scope.center.latitude = gObject.getCenter().lat()
scope.center.longitude = gObject.getCenter().lng()


scope.$on '$destroy', =>
Expand Down