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

Commit 114e1b6

Browse files
committed
issue #354
window fixed windows needs to pass interpolation down to the child as a service. This needs to be called to evaluate the old html to the new.
1 parent 484e69b commit 114e1b6

File tree

7 files changed

+178
-28
lines changed

7 files changed

+178
-28
lines changed

dist/angular-google-maps.js

+48-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-google-maps 1.0.13 2014-05-06
1+
/*! angular-google-maps 1.0.13 2014-05-07
22
* AngularJS directives for Google Maps
33
* git: https://github.com/nlaplante/angular-google-maps.git
44
*/
@@ -1845,32 +1845,57 @@ Nicholas McCready - https://twitter.com/nmccready
18451845
this.needToManualDestroy = needToManualDestroy != null ? needToManualDestroy : false;
18461846
this.markerIsVisibleAfterWindowClose = markerIsVisibleAfterWindowClose != null ? markerIsVisibleAfterWindowClose : true;
18471847
this.destroy = __bind(this.destroy, this);
1848+
this.remove = __bind(this.remove, this);
18481849
this.hideWindow = __bind(this.hideWindow, this);
18491850
this.getLatestPosition = __bind(this.getLatestPosition, this);
18501851
this.showWindow = __bind(this.showWindow, this);
18511852
this.handleClick = __bind(this.handleClick, this);
18521853
this.watchCoords = __bind(this.watchCoords, this);
18531854
this.watchShow = __bind(this.watchShow, this);
18541855
this.createGWin = __bind(this.createGWin, this);
1856+
this.watchElement = __bind(this.watchElement, this);
18551857
this.googleMapsHandles = [];
18561858
this.$log = Logger;
18571859
this.createGWin();
18581860
if (this.markerCtrl != null) {
18591861
this.markerCtrl.setClickable(true);
18601862
}
18611863
this.handleClick();
1864+
this.watchElement();
18621865
this.watchShow();
18631866
this.watchCoords();
18641867
this.$log.info(this);
18651868
}
18661869

1870+
WindowChildModel.prototype.watchElement = function() {
1871+
var _this = this;
1872+
return this.scope.$watch(function() {
1873+
var _ref;
1874+
if (!_this.element || !_this.html) {
1875+
return;
1876+
}
1877+
if (_this.html !== _this.element.html()) {
1878+
if (_this.gWin) {
1879+
if ((_ref = _this.opts) != null) {
1880+
_ref.content = void 0;
1881+
}
1882+
_this.remove();
1883+
_this.createGWin();
1884+
return _this.showHide();
1885+
}
1886+
}
1887+
});
1888+
};
1889+
18671890
WindowChildModel.prototype.createGWin = function() {
1868-
var defaults, html,
1891+
var defaults,
18691892
_this = this;
1870-
if ((this.gWin == null) && (this.markerCtrl != null)) {
1893+
if (this.gWin == null) {
18711894
defaults = this.opts != null ? this.opts : {};
1872-
html = _.isObject(this.element) ? this.element.html() : this.element;
1873-
this.opts = this.markerCtrl != null ? this.createWindowOptions(this.markerCtrl, this.scope, html, defaults) : {};
1895+
if (this.element) {
1896+
this.html = _.isObject(this.element) ? this.element.html() : this.element;
1897+
}
1898+
this.opts = this.createWindowOptions(this.markerCtrl, this.scope, this.html, defaults);
18741899
}
18751900
if ((this.opts != null) && !this.gWin) {
18761901
if (this.opts.boxClass && (window.InfoBox && typeof window.InfoBox === 'function')) {
@@ -1978,6 +2003,14 @@ Nicholas McCready - https://twitter.com/nmccready
19782003
}
19792004
};
19802005

2006+
WindowChildModel.prototype.showHide = function() {
2007+
if (this.scope.show) {
2008+
return this.showWindow();
2009+
} else {
2010+
return this.hideWindow();
2011+
}
2012+
};
2013+
19812014
WindowChildModel.prototype.getLatestPosition = function() {
19822015
if ((this.gWin != null) && (this.markerCtrl != null)) {
19832016
return this.gWin.setPosition(this.markerCtrl.getPosition());
@@ -1990,20 +2023,24 @@ Nicholas McCready - https://twitter.com/nmccready
19902023
}
19912024
};
19922025

1993-
WindowChildModel.prototype.destroy = function(manualOverride) {
1994-
var self;
1995-
if (manualOverride == null) {
1996-
manualOverride = false;
1997-
}
2026+
WindowChildModel.prototype.remove = function() {
19982027
this.hideWindow();
19992028
_.each(this.googleMapsHandles, function(h) {
20002029
return google.maps.event.removeListener(h);
20012030
});
20022031
this.googleMapsHandles.length = 0;
2032+
return delete this.gWin;
2033+
};
2034+
2035+
WindowChildModel.prototype.destroy = function(manualOverride) {
2036+
var self;
2037+
if (manualOverride == null) {
2038+
manualOverride = false;
2039+
}
2040+
this.remove();
20032041
if ((this.scope != null) && (this.needToManualDestroy || manualOverride)) {
20042042
this.scope.$destroy();
20052043
}
2006-
delete this.gWin;
20072044
return self = void 0;
20082045
};
20092046

dist/angular-google-maps.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
angular.module("angular-google-maps-example", ["google-maps"]).value("rndAddToLatLon", function () {
2+
return Math.floor(((Math.random() < 0.5 ? -1 : 1) * 2) + 1)
3+
})
4+
.controller(
5+
"controller", ['$rootScope', '$scope', '$location', '$http',
6+
function ($rootScope, $scope, $location, $http) {
7+
$scope.map = {
8+
center: {
9+
latitude: 51.219053,
10+
longitude: 4.404418
11+
},
12+
zoom: 15
13+
};
14+
$scope.windows = [
15+
{
16+
latitude: 51.419053,
17+
longitude: 4.404418,
18+
show:true
19+
}
20+
]
21+
$scope.test = {};
22+
$scope.test.name = true;
23+
}]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<html xmlns:ng="http://angularjs.org" id='ng-app' ng-app="angular-google-maps-example">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>angular-google-maps example page</title>
6+
<!-- See https://rawgithub.com/ as it returns the correct mimetypes that are requested from github.-->
7+
<!-- make IE Happy , http://docs.angularjs.org/guide/ie -->
8+
<!--[if lte IE 9]>
9+
<script>
10+
window.html5 = {
11+
'elements': 'marker window windows markers layer polyline marker-label ng-controller ng-repeat ng-init ng-model ng-hide ng-show'
12+
};
13+
</script>
14+
15+
<script src="https://rawgithub.com/bestiejs/json3/v3.2.5a/lib/json3.min.js"></script>
16+
<script src="https://rawgithub.com/kriskowal/es5-shim/v2.1.0/es5-shim.min.js"></script>
17+
<script src="https://rawgithub.com/jwmcpeak/EventShim/master/eventShim.js"></script>
18+
<script src="https://rawgithub.com/aFarkas/html5shiv/3.7.0/src/html5shiv.js"></script>
19+
<![endif]-->
20+
21+
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"
22+
type="text/css">
23+
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,800,600,300,700'
24+
rel='stylesheet' type='text/css'>
25+
<link href="assets/stylesheets/example.css" rel="stylesheet" type="text/css">
26+
</head>
27+
28+
<body ng-controller="controller">
29+
<!-- You can use either a div having class 'google-map' or the '<google-map>' element; in
30+
the latter case, uncomment the style above to make sure the custom elements gets block display -->
31+
<div class="page-title ">
32+
<h2 ng-cloak>angular-google-maps example {{version}}</h2>
33+
</div>
34+
<div class="container">
35+
<div class="row">
36+
<button class="col-md-2 btn btn-success" ng-click="map.refresh()">Refresh Map</button>
37+
<button ng-click="test.name = !test.name">Change test </button>
38+
test = {{ test.name }}
39+
</div>
40+
<div class="row">
41+
<google-map class="col-md-12"
42+
center="map.center"
43+
zoom="map.zoom"
44+
dragging="map.dragging"
45+
draggable="true"
46+
control="map.control">
47+
<window show="true" coords="map.center">
48+
<div class="popup" style="width: 100px; height: 50px;">
49+
<p>test = {{test.name}}</p>
50+
</div>
51+
</window>
52+
<windows models="windows" show="'show'" coords="'self'">
53+
<div class="popup" style="width: 100px; height: 50px;">
54+
<p>test = {{test.name}}</p>
55+
</div>
56+
</windows>
57+
</google-map>
58+
</div>
59+
</div>
60+
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
61+
<script src="http://maps.googleapis.com/maps/api/js?libraries=weather,visualization&sensor=false&language=en&v=3.13"></script>
62+
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
63+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
64+
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js" type="text/javascript"></script>
65+
<script src="../dist/angular-google-maps.js"></script>
66+
<script src="assets/scripts/mocks/heat-layer.js"></script>
67+
<script src="assets/scripts/controllers/issue-354-window-windows-rerender-content.js"></script>
68+
<script src="assets/scripts/controllers/templates/info.js"></script>
69+
<script src="http://localhost:35729/livereload.js"></script>
70+
</body>
71+
72+
</html>

src/coffee/directives/api/models/child/window-child-model.coffee

+29-8
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@ angular.module("google-maps.directives.api.models.child")
1212
@markerCtrl.setClickable(true) if @markerCtrl?
1313

1414
@handleClick()
15+
@watchElement()
1516
@watchShow()
1617
@watchCoords()
1718
@$log.info(@)
1819

20+
watchElement:=>
21+
@scope.$watch =>
22+
return if not @element or not @html
23+
if @html != @element.html() #has content changed?
24+
if @gWin
25+
@opts?.content = undefined
26+
@remove()
27+
@createGWin()
28+
@showHide()
29+
1930
createGWin:() =>
20-
if !@gWin? and @markerCtrl?
31+
if !@gWin?
2132
defaults = if @opts? then @opts else {}
22-
html = if _.isObject(@element) then @element.html() else @element
23-
@opts = if @markerCtrl? then @createWindowOptions(@markerCtrl, @scope, html, defaults) else {}
33+
if @element
34+
@html = if _.isObject(@element) then @element.html() else @element
35+
@opts = @createWindowOptions(@markerCtrl, @scope, @html, defaults)
2436

2537
if @opts? and !@gWin
2638
if @opts.boxClass and (window.InfoBox && typeof window.InfoBox == 'function')
@@ -90,20 +102,29 @@ angular.module("google-maps.directives.api.models.child")
90102
else
91103
show()
92104

105+
showHide: ->
106+
if @scope.show
107+
@showWindow()
108+
else
109+
@hideWindow()
110+
93111
getLatestPosition: () =>
94112
@gWin.setPosition @markerCtrl.getPosition() if @gWin? and @markerCtrl?
95113

96114
hideWindow: () =>
97115
@gWin.close() if @gWin? and @gWin.isOpen()
98116

117+
remove: =>
118+
@hideWindow()
119+
_.each @googleMapsHandles, (h) ->
120+
google.maps.event.removeListener h
121+
@googleMapsHandles.length = 0
122+
delete @gWin
123+
99124
destroy: (manualOverride = false)=>
100-
@hideWindow()
101-
_.each @googleMapsHandles, (h) ->
102-
google.maps.event.removeListener h
103-
@googleMapsHandles.length = 0
125+
@remove()
104126
if @scope? and (@needToManualDestroy or manualOverride)
105127
@scope.$destroy()
106-
delete @gWin
107128
self = undefined
108129

109130
WindowChildModel

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ angular.module("google-maps.directives.api.models.parent")
119119
@$log.error("Marker model has no id to assign a child to. This is required for performance. Please assign id, or redirect id to a different key.")
120120
return
121121
@$log.info('child', child, 'markers', @scope.markerModels)
122-
child = new MarkerChildModel(model, scope, @mapCtrl,
123-
@$timeout,
124-
@DEFAULTS, @doClick, @gMarkerManager, @idKey)
122+
child = new MarkerChildModel(model, scope, @mapCtrl, @$timeout, @DEFAULTS,
123+
@doClick, @gMarkerManager, @idKey)
125124
@scope.markerModels.put(model[@idKey], child) #major change this makes model.id a requirement
126125
child
127126

src/coffee/directives/api/window.coffee

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ angular.module("google-maps.directives.api")
2222
opts = if hasScopeCoords then @createWindowOptions(markerCtrl, scope, element.html(), defaults) else defaults
2323

2424
if mapCtrl? #at the very least we need a Map, the marker is optional as we can create Windows without markers
25-
window = new WindowChildModel(
26-
{}, scope, opts, isIconVisibleOnClick, mapCtrl,
25+
window = new WindowChildModel {}, scope, opts, isIconVisibleOnClick, mapCtrl,
2726
markerCtrl, element
28-
)
2927
scope.$on "$destroy", =>
3028
window.destroy()
3129

0 commit comments

Comments
 (0)