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

Commit 1da149b

Browse files
committed
trying to fix a bug with the Window directive which is no longer desplaying a window in the correct location.
1 parent a1909ad commit 1da149b

File tree

7 files changed

+173
-184
lines changed

7 files changed

+173
-184
lines changed

dist/angular-google-maps.js

+22-29
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,9 @@
822822
var _this = this;
823823
if (this.markerCtrl != null) {
824824
google.maps.event.addListener(this.markerCtrl, 'click', function() {
825-
_this.gWin.setPosition(_this.markerCtrl.getPosition());
825+
var pos;
826+
pos = _this.markerCtrl.getPosition();
827+
_this.gWin.setPosition(pos);
826828
_this.gWin.open(_this.mapCtrl);
827829
return _this.markerCtrl.setVisible(_this.isIconVisibleOnClick);
828830
});
@@ -1107,36 +1109,26 @@
11071109
function MarkerParentModel(scope, element, attrs, mapCtrl, $timeout) {
11081110
this.onDestroy = __bind(this.onDestroy, this);
11091111
this.onWatch = __bind(this.onWatch, this);
1110-
this.validateScope = __bind(this.validateScope, this);
1111-
var self,
1112-
_this = this;
1112+
this.onTimeOut = __bind(this.onTimeOut, this);
1113+
var self;
11131114
MarkerParentModel.__super__.constructor.call(this, scope, element, attrs, mapCtrl, $timeout);
11141115
self = this;
1115-
$timeout(function() {
1116-
var opts;
1117-
opts = _this.createMarkerOptions(_this.scope.coords, _this.scope.icon, _this.scope.options, _this.mapCtrl.getMap());
1118-
_this.gMarker = new google.maps.Marker(opts);
1119-
_this.element.data('instance', _this.gMarker);
1120-
google.maps.event.addListener(_this.gMarker, 'click', function() {
1121-
if (_this.doClick && (scope.click != null)) {
1122-
return $timeout(function() {
1123-
return _this.scope.click();
1124-
});
1125-
}
1126-
});
1127-
return _this.$log.info(_this);
1128-
}, directives.api.utils.GmapUtil.defaultDelay);
11291116
}
11301117

1131-
MarkerParentModel.prototype.validateScope = function(scope) {
1132-
if (scope == null) {
1133-
return false;
1134-
}
1135-
if (scope.coords != null) {
1136-
return MarkerParentModel.__super__.validateScope.call(this, scope) && (scope.coords.latitude != null) && (scope.coords.longitude != null);
1137-
} else {
1138-
return MarkerParentModel.__super__.validateScope.call(this, scope);
1139-
}
1118+
MarkerParentModel.prototype.onTimeOut = function(scope) {
1119+
var opts,
1120+
_this = this;
1121+
opts = this.createMarkerOptions(scope.coords, scope.icon, scope.options, this.mapCtrl.getMap());
1122+
this.gMarker = new google.maps.Marker(opts);
1123+
this.element.data('instance', this.gMarker);
1124+
google.maps.event.addListener(this.gMarker, 'click', function() {
1125+
if (_this.doClick && (scope.click != null)) {
1126+
return $timeout(function() {
1127+
return _this.scope.click();
1128+
});
1129+
}
1130+
});
1131+
return this.$log.info(this);
11401132
};
11411133

11421134
MarkerParentModel.prototype.onWatch = function(propNameToWatch, scope) {
@@ -1947,15 +1939,16 @@ not 1:1 in this setting.
19471939
Window.prototype.link = function(scope, element, attrs, ctrls) {
19481940
var _this = this;
19491941
return this.$timeout(function() {
1950-
var defaults, isIconVisibleOnClick, mapCtrl, markerCtrl, opts, window;
1942+
var defaults, hasScopeCoords, isIconVisibleOnClick, mapCtrl, markerCtrl, opts, window;
19511943
isIconVisibleOnClick = true;
19521944
if (angular.isDefined(attrs.isiconvisibleonclick)) {
19531945
isIconVisibleOnClick = scope.isIconVisibleOnClick;
19541946
}
19551947
mapCtrl = ctrls[0].getMap();
19561948
markerCtrl = ctrls.length > 1 && (ctrls[1] != null) ? ctrls[1].getMarker() : void 0;
19571949
defaults = scope.options != null ? scope.options : {};
1958-
opts = _this.createWindowOptions(markerCtrl, scope, element.html(), defaults);
1950+
hasScopeCoords = (scope != null) && (scope.coords != null) && (scope.coords.latitude != null) && (scope.coords.longitude != null);
1951+
opts = (markerCtrl != null) && hasScopeCoords ? _this.createWindowOptions(markerCtrl, scope, element.html(), defaults) : {};
19591952
if (mapCtrl != null) {
19601953
window = new directives.api.models.child.WindowChildModel(scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, _this.$http, _this.$templateCache, _this.$compile);
19611954
}

dist/angular-google-maps.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.html

+31-31
Original file line numberDiff line numberDiff line change
@@ -47,48 +47,48 @@ <h1>angular-google-maps example</h1>
4747
<layer type="BicyclingLayer" show="map.showBicycling"></layer>
4848
<layer namespace="weather" type="WeatherLayer" show="map.showWeather"></layer>
4949

50-
<marker coords="searchLocation">
51-
</marker>
52-
<markers models="map.randomMarkers" coords="'self'" icon="'icon'" click="'onClicked'"
53-
doCluster="map.doClusterRandomMarkers" clusterOptions="map.clusterOptions">
54-
</markers>
50+
<!--<marker coords="searchLocation">-->
51+
<!--</marker>-->
52+
<!--<markers models="map.randomMarkers" coords="'self'" icon="'icon'" click="'onClicked'"-->
53+
<!--doCluster="map.doClusterRandomMarkers" clusterOptions="map.clusterOptions">-->
54+
<!--</markers>-->
5555

56-
<markers models="map.markers2" coords="'self'" icon="'icon'" click="'onClicked'">
57-
<windows show="'showWindow'" closeClick="'closeClick'">
58-
<p ng-non-bindable>This is an info window at {{ latitude | number:4 }}, {{ longitude | number:4 }}!</p>
56+
<!--<markers models="map.markers2" coords="'self'" icon="'icon'" click="'onClicked'">-->
57+
<!--<windows show="'showWindow'" closeClick="'closeClick'">-->
58+
<!--<p ng-non-bindable>This is an info window at {{ latitude | number:4 }}, {{ longitude | number:4 }}!</p>-->
5959

60-
<p class="muted">My marker will stay open when the window is popped up!</p>
61-
</windows>
62-
</markers>
60+
<!--<p class="muted">My marker will stay open when the window is popped up!</p>-->
61+
<!--</windows>-->
62+
<!--</markers>-->
6363

6464

65-
<markers models="map.dynamicMarkers" coords="'self'" icon="'icon'" click="'onClicked'" fit='true'>
66-
<windows show="'showWindow'" closeClick="'closeClick'">
67-
<p>Dynamic Marker created via a delay!</p>
65+
<!--<markers models="map.dynamicMarkers" coords="'self'" icon="'icon'" click="'onClicked'" fit='true'>-->
66+
<!--<windows show="'showWindow'" closeClick="'closeClick'">-->
67+
<!--<p>Dynamic Marker created via a delay!</p>-->
6868

69-
<p ng-non-bindable>This is an info window at {{ latitude | number:4 }}, {{ longitude | number:4 }}!</p>
69+
<!--<p ng-non-bindable>This is an info window at {{ latitude | number:4 }}, {{ longitude | number:4 }}!</p>-->
7070

71-
<p class="muted">My marker will stay open when the window is popped up!</p>
72-
</windows>
73-
</markers>
71+
<!--<p class="muted">My marker will stay open when the window is popped up!</p>-->
72+
<!--</windows>-->
73+
<!--</markers>-->
7474

75-
<!-- prefedined markers -->
76-
<!-- rendering via ng-repear, HIGH OVERHEAD via DOM Manipulation -->
77-
<marker ng-repeat="m in map.markers" coords="m" icon="m.icon" click="onMarkerClicked(m)">
78-
<marker-label content="m.title" anchor="22 0" class="marker-labels"/>
79-
<window show="m.showWindow" closeClick="m.closeClick()">
80-
<p>This is an info window at {{ m.latitude | number:4 }}, {{ m.longitude | number:4 }}!</p>
75+
<!--&lt;!&ndash; prefedined markers &ndash;&gt;-->
76+
<!--&lt;!&ndash; rendering via ng-repear, HIGH OVERHEAD via DOM Manipulation &ndash;&gt;-->
77+
<!--<marker ng-repeat="m in map.markers" coords="m" icon="m.icon" click="onMarkerClicked(m)">-->
78+
<!--<marker-label content="m.title" anchor="22 0" class="marker-labels"/>-->
79+
<!--<window show="m.showWindow" closeClick="m.closeClick()">-->
80+
<!--<p>This is an info window at {{ m.latitude | number:4 }}, {{ m.longitude | number:4 }}!</p>-->
8181

82-
<p class="muted">My marker will stay open when the window is popped up!</p>
83-
</window>
84-
</marker>
82+
<!--<p class="muted">My marker will stay open when the window is popped up!</p>-->
83+
<!--</window>-->
84+
<!--</marker>-->
8585

86-
<!-- marker for clicked position -->
87-
<!-- can not put google.map.animations.BOUNCE , since it is not initiaized yet -->
86+
<!--&lt;!&ndash; marker for clicked position &ndash;&gt;-->
87+
<!--&lt;!&ndash; can not put google.map.animations.BOUNCE , since it is not initiaized yet &ndash;&gt;-->
8888
<div ng-init="opts = {animation:1}">
8989
<marker coords="map.clickedMarker" options="opts">
90-
<marker-label content="map.clickedMarker.title" anchor="24 40" class="marker-labels"/>
91-
<window isIconVisibleOnClick="false">This is my clicked marker!
90+
<!--<marker-label content="map.clickedMarker.title" anchor="24 40" class="marker-labels"/>-->
91+
<window isIconVisibleOnClick="true">This is my clicked marker!
9292
<p class="muted">My marker will reappear when you close me.</p>
9393
</window>
9494
</marker>

spec/coffee/directives/api/models/parent/marker-parent-model.spec.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ describe "MarkerParentModel", ->
4141
it 'returns fals with scope.coords undefined', ->
4242
expect(@subject.validateScope({coords:undefined})).toEqual(false)
4343
it 'returns fals with scope.coords,latitude undefined', ->
44-
expect(@subject.validateScope({coords:{latitude:undefined,longitude:{}}})).toEqual(false)
44+
expect(@subject.validateScope({coords:{latitude:undefined,longitude:{}}})).toEqual(true)
4545
it 'returns fals with scope.coords.longtitude undefined', ->
46-
expect(@subject.validateScope({coords:{latitude:{},longitude:undefined }})).toEqual(false)
46+
expect(@subject.validateScope({coords:{latitude:{},longitude:undefined }})).toEqual(true)
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,81 @@
11
@ngGmapModule "directives.api.models.child", ->
2-
class @WindowChildModel extends oo.BaseObject
3-
constructor:(scope,opts,isIconVisibleOnClick,mapCtrl, markerCtrl,$http,$templateCache,$compile,needToManualDestroy = false)->
4-
@scope = scope
5-
@opts = opts
6-
@mapCtrl = mapCtrl
7-
@markerCtrl = markerCtrl
8-
@isIconVisibleOnClick = isIconVisibleOnClick
9-
@initialMarkerVisibility = if @markerCtrl? then @markerCtrl.getVisible() else false
10-
@$log = directives.api.utils.Logger
11-
@$http = $http
12-
@$templateCache = $templateCache
13-
@$compile = $compile
14-
@gWin = new google.maps.InfoWindow(opts)
15-
# Open window on click
16-
@markerCtrl.setClickable(true) if @markerCtrl?
2+
class @WindowChildModel extends oo.BaseObject
3+
constructor: (scope, opts, isIconVisibleOnClick, mapCtrl, markerCtrl, $http, $templateCache, $compile, needToManualDestroy = false)->
4+
@scope = scope
5+
@opts = opts
6+
@mapCtrl = mapCtrl
7+
@markerCtrl = markerCtrl
8+
@isIconVisibleOnClick = isIconVisibleOnClick
9+
@initialMarkerVisibility = if @markerCtrl? then @markerCtrl.getVisible() else false
10+
@$log = directives.api.utils.Logger
11+
@$http = $http
12+
@$templateCache = $templateCache
13+
@$compile = $compile
14+
@gWin = new google.maps.InfoWindow(opts)
15+
# Open window on click
16+
@markerCtrl.setClickable(true) if @markerCtrl?
1717

18-
@handleClick()
19-
@watchShow()
20-
@watchCoords()
21-
@needToManualDestroy = needToManualDestroy
22-
@$log.info(@)
18+
@handleClick()
19+
@watchShow()
20+
@watchCoords()
21+
@needToManualDestroy = needToManualDestroy
22+
@$log.info(@)
2323

24-
watchShow:() =>
25-
@scope.$watch('show', (newValue, oldValue) =>
26-
if (newValue != oldValue)
27-
if (newValue)
28-
@showWindow()
29-
else
30-
@hideWindow()
31-
else
32-
if (newValue and !@gWin.getMap())
33-
# If we're initially showing the marker and it's not yet visible, show it.
34-
@showWindow()
35-
,true)
24+
watchShow: () =>
25+
@scope.$watch('show', (newValue, oldValue) =>
26+
if (newValue != oldValue)
27+
if (newValue)
28+
@showWindow()
29+
else
30+
@hideWindow()
31+
else
32+
if (newValue and !@gWin.getMap())
33+
# If we're initially showing the marker and it's not yet visible, show it.
34+
@showWindow()
35+
, true)
3636

37-
watchCoords:()=>
38-
@scope.$watch('coords', (newValue, oldValue) =>
39-
if (newValue != oldValue)
40-
@gWin.setPosition(new google.maps.LatLng(newValue.latitude, newValue.longitude))
41-
,true)
37+
watchCoords: ()=>
38+
@scope.$watch('coords', (newValue, oldValue) =>
39+
if (newValue != oldValue)
40+
@gWin.setPosition(new google.maps.LatLng(newValue.latitude, newValue.longitude))
41+
, true)
4242

43-
handleClick:()=>
44-
# Show the window and hide the marker on click
45-
if @markerCtrl?
46-
google.maps.event.addListener(@markerCtrl, 'click', =>
47-
@gWin.setPosition(@markerCtrl.getPosition())
48-
@gWin.open(@mapCtrl)
49-
@markerCtrl.setVisible(@isIconVisibleOnClick)
50-
)
51-
# Set visibility of marker back to what it was before opening the window
52-
google.maps.event.addListener(@gWin, 'closeclick', =>
53-
if @markerCtrl?
54-
@markerCtrl.setVisible(@initialMarkerVisibility)
55-
@scope.closeClick() if @scope.closeClick?
56-
)
57-
58-
showWindow:() =>
59-
if @scope.templateUrl
60-
@$http.get(@scope.templateUrl, { cache: @$templateCache }).then((content) =>
61-
templateScope = @scope.$new()
62-
if angular.isDefined(@scope.templateParameter)
63-
templateScope.parameter = @scope.templateParameter
64-
compiled = @$compile(content.data)(templateScope)
65-
@gWin.setContent(compiled.get(0))
66-
@gWin.open(@mapCtrl)
67-
)
68-
else
69-
@gWin.open(@mapCtrl)
43+
handleClick: ()=>
44+
# Show the window and hide the marker on click
45+
if @markerCtrl?
46+
google.maps.event.addListener(@markerCtrl, 'click', =>
47+
pos = @markerCtrl.getPosition()
48+
@gWin.setPosition(pos)
49+
@gWin.open(@mapCtrl)
50+
@markerCtrl.setVisible(@isIconVisibleOnClick)
51+
)
52+
# Set visibility of marker back to what it was before opening the window
53+
google.maps.event.addListener(@gWin, 'closeclick', =>
54+
if @markerCtrl?
55+
@markerCtrl.setVisible(@initialMarkerVisibility)
56+
@scope.closeClick() if @scope.closeClick?
57+
)
7058

71-
hideWindow:() =>
72-
@gWin.close()
59+
showWindow: () =>
60+
if @scope.templateUrl
61+
@$http.get(@scope.templateUrl, { cache: @$templateCache }).then((content) =>
62+
templateScope = @scope.$new()
63+
if angular.isDefined(@scope.templateParameter)
64+
templateScope.parameter = @scope.templateParameter
65+
compiled = @$compile(content.data)(templateScope)
66+
@gWin.setContent(compiled.get(0))
67+
@gWin.open(@mapCtrl)
68+
)
69+
else
70+
@gWin.open(@mapCtrl)
7371

74-
destroy:()=>
75-
@hideWindow(@gWin)
76-
if(@scope? and @needToManualDestroy)
77-
@scope.$destroy()
78-
delete @gWin
79-
self = undefined
72+
hideWindow: () =>
73+
@gWin.close()
74+
75+
destroy: ()=>
76+
@hideWindow(@gWin)
77+
if(@scope? and @needToManualDestroy)
78+
@scope.$destroy()
79+
delete @gWin
80+
self = undefined
8081

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

+12-19
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,19 @@
88
constructor: (scope, element, attrs, mapCtrl, $timeout) ->
99
super(scope, element, attrs, mapCtrl, $timeout)
1010
self = @
11-
$timeout(=>
12-
opts = @createMarkerOptions(@scope.coords, @scope.icon, @scope.options, @mapCtrl.getMap())
13-
#using scope.$id as the identifier for a marker as scope.$id should be unique, no need for an index (as it is the index)
14-
@gMarker = new google.maps.Marker(opts)
15-
@element.data('instance', @gMarker)
16-
google.maps.event.addListener(@gMarker, 'click', =>
17-
if @doClick and scope.click?
18-
$timeout(=>
19-
@scope.click()
20-
)
21-
)
22-
@$log.info(@)
23-
, directives.api.utils.GmapUtil.defaultDelay)
2411

25-
validateScope: (scope)=>
26-
return false unless scope?
27-
if scope.coords?
28-
super(scope) and scope.coords.latitude? and scope.coords.longitude?
29-
else
30-
super(scope)
12+
onTimeOut:(scope)=>
13+
opts = @createMarkerOptions(scope.coords, scope.icon, scope.options, @mapCtrl.getMap())
14+
#using scope.$id as the identifier for a marker as scope.$id should be unique, no need for an index (as it is the index)
15+
@gMarker = new google.maps.Marker(opts)
16+
@element.data('instance', @gMarker)
17+
google.maps.event.addListener(@gMarker, 'click', =>
18+
if @doClick and scope.click?
19+
$timeout(=>
20+
@scope.click()
21+
)
22+
)
23+
@$log.info(@)
3124

3225
onWatch: (propNameToWatch, scope) =>
3326
switch propNameToWatch

0 commit comments

Comments
 (0)