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

Commit

Permalink
Fix issue 476.
Browse files Browse the repository at this point in the history
  • Loading branch information
cthrax committed Aug 5, 2014
1 parent 582ccd0 commit 7bebfb5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
10 changes: 7 additions & 3 deletions dist/angular-google-maps.js
@@ -1,4 +1,4 @@
/*! angular-google-maps 1.2.0 2014-08-03
/*! angular-google-maps 1.2.0 2014-08-05
* AngularJS directives for Google Maps
* git: https://github.com/nlaplante/angular-google-maps.git
*/
Expand Down Expand Up @@ -3665,9 +3665,13 @@ Nicholas McCready - https://twitter.com/nmccready
}
opts = angular.extend({}, defaults, {
position: defaults.position != null ? defaults.position : getCoords(coords),
icon: defaults.icon != null ? defaults.icon : icon,
visible: defaults.visible != null ? defaults.visible : validateCoords(coords)
});
if ((defaults.icon != null) || (icon != null)) {
opts = angular.extend(opts, {
icon: defaults.icon != null ? defaults.icon : icon
});
}
if (map != null) {
opts.map = map;
}
Expand Down Expand Up @@ -5882,7 +5886,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
}
break;
case 'options':
if (this.validateCoords(scope.coords) && (scope.icon != null) && scope.options) {
if (this.validateCoords(scope.coords) && scope.options) {
if (this.scope.gMarker != null) {
this.scope.gMarker.setMap(null);
}
Expand Down
@@ -1,6 +1,7 @@
describe "MarkerParentModel", ->
afterEach ->
window.google.maps = @gMapsTemp

beforeEach ->
module "google-maps.mocks"
#define / inject values into the item we are testing... not a controller but it allows us to inject
Expand Down Expand Up @@ -76,6 +77,33 @@ describe "MarkerParentModel", ->
it 'can be created', ->
expect(@subject).toBeDefined()

describe 'scope is watched correctly', ->
#Demonstrates issue https://github.com/nlaplante/angular-google-maps/issues/476
it 'should create options that are bindable', ->
#TODO: This is very sloppy because it violates DRY and should be refactored
self = @
marker = undefined
options = {visible: true}
@scope =
idKey: 0
icon: 'icon.png'
coords:
latitude: 90
longitude: 90
options: options

#mocking google maps event listener, don't need except to instantiate
window.google.maps.event.addListener = (thing, eventName, callBack) =>
return

inject ($rootScope, $timeout, element, attrs, mapCtrl, MarkerParentModel, MarkerManager) =>
@scope = _.extend @scope, $rootScope.$new()
mgr = new MarkerManager(mapCtrl.getMap())
marker = new MarkerParentModel(@scope, element, attrs, mapCtrl, $timeout, mgr, false)

options.visible = false
expect(@scope.options.visible).toEqual(false)

describe "validateScope", ->
it 'returns false with scope undefined', ->
expect(@subject.validateScope(undefined)).toEqual(false)
Expand Down
25 changes: 25 additions & 0 deletions spec/coffee/directives/api/utils/gmap-util.spec.coffee
Expand Up @@ -34,6 +34,31 @@ describe "utils.gmap-util", ->
it "foo", ->
expect(@subject.validatePath({type: "foo", coordinates: []})).toEqual(false)

describe "should create markers with correct scope", ->
it "should create the correct scope on the marker", ->
latLng = {latitude: 1, longitude: 2}
options = {visible: true}
defaults = {
coords: latLng,
options: options
}
mOpts = @subject.createMarkerOptions latLng, undefined, defaults
expect(mOpts.visible).toEqual(defaults.options.visible)
options.visible = false;
expect(mOpts.options.visible).toEqual(defaults.options.visible)

it "should respect changes to options", ->
latLng = {latitude: 1, longitude: 2}
options = {icon: "icon"}
defaults = {
coords: latLng,
options: options
}
mOpts = @subject.createMarkerOptions latLng, options.icon, defaults
expect(mOpts.icon).toEqual(defaults.options.icon)
options.icon = "foo";
expect(mOpts.options.icon).toEqual(defaults.options.icon)

describe "should validate coordinates correctly", ->
it "basic", ->
expect(@subject.validateCoords()).toEqual(false)
Expand Down
Expand Up @@ -46,7 +46,7 @@ angular.module("google-maps.directives.api.models.parent")
@scope.gMarker.setPosition @getCoords(scope.coords)
@scope.gMarker.setVisible @validateCoords(scope.coords)
when 'options'
if @validateCoords(scope.coords) and scope.icon? and scope.options
if @validateCoords(scope.coords) and scope.options
@scope.gMarker.setMap(null) if @scope.gMarker?
@setGMarker new google.maps.Marker @createMarkerOptions(scope.coords, scope.icon, scope.options,@map)

Expand Down
7 changes: 6 additions & 1 deletion src/coffee/directives/api/utils/gmap-util.coffee
Expand Up @@ -65,8 +65,13 @@ angular.module("google-maps.directives.api.utils")
opts = angular.extend {}, defaults,
position: if defaults.position? then defaults.position
else getCoords(coords),
icon: if defaults.icon? then defaults.icon else icon,
visible: if defaults.visible? then defaults.visible else validateCoords(coords)

# Only set icon if there's one to set
if defaults.icon? or icon?
opts = angular.extend opts,
icon: if defaults.icon? then defaults.icon else icon

opts.map = map if map?
opts

Expand Down

2 comments on commit 7bebfb5

@nmccready
Copy link
Contributor

Choose a reason for hiding this comment

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

#476 commit

@cthrax
Copy link
Contributor Author

@cthrax cthrax commented on 7bebfb5 Aug 5, 2014

Choose a reason for hiding this comment

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

Oops, forgot the #. Good catch.

Please sign in to comment.