Skip to content

Commit 6b8c53b

Browse files
committed
clonedModel attribute for uiGmapModel-Key to be used in ModelWatcher
- This is ripe for a ChildBase Class This makes angular-ui#946 and angular-ui#772 compatible
1 parent a806ccb commit 6b8c53b

14 files changed

+64
-34
lines changed

dist/angular-google-maps.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ Nicholas McCready - https://twitter.com/nmccready
13661366
return adds.push(m);
13671367
} else {
13681368
child = childObjects.get(m[idKey]);
1369-
if (!comparison(m, child.model)) {
1369+
if (!comparison(m, child.clonedModel)) {
13701370
return updates.push({
13711371
model: m,
13721372
child: child
@@ -2413,6 +2413,7 @@ Nicholas McCready - https://twitter.com/nmccready
24132413
this.defaults = defaults;
24142414
this.model = model;
24152415
this.clean = __bind(this.clean, this);
2416+
this.clonedModel = _.clone(this.model, true);
24162417
this.isDragging = false;
24172418
this.internalEvents = {
24182419
dragend: (function(_this) {
@@ -2754,6 +2755,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
27542755
this.updateModel = __bind(this.updateModel, this);
27552756
this.handleModelChanges = __bind(this.handleModelChanges, this);
27562757
this.destroy = __bind(this.destroy, this);
2758+
this.clonedModel = _.clone(this.model, true);
27572759
this.deferred = uiGmapPromise.defer();
27582760
_.each(this.keys, (function(_this) {
27592761
return function(v, k) {
@@ -2828,7 +2830,8 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
28282830
};
28292831

28302832
MarkerChildModel.prototype.updateModel = function(model) {
2831-
return this.setMyScope('all', _.clone(model, true), this.model);
2833+
this.cloneModel = _.clone(model, true);
2834+
return this.setMyScope('all', model, this.model);
28322835
};
28332836

28342837
MarkerChildModel.prototype.renderGMarker = function(doDraw, validCb) {
@@ -3148,16 +3151,18 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
31483151

31493152
WindowChildModel.include(EventsHelper);
31503153

3151-
function WindowChildModel(model, scope, opts, isIconVisibleOnClick, mapCtrl, markerScope, element, needToManualDestroy, markerIsVisibleAfterWindowClose) {
3154+
function WindowChildModel(model, scope, opts, isIconVisibleOnClick, mapCtrl, markerScope, element, clonedModel, needToManualDestroy, markerIsVisibleAfterWindowClose, trackModel) {
31523155
this.model = model;
31533156
this.scope = scope;
31543157
this.opts = opts;
31553158
this.isIconVisibleOnClick = isIconVisibleOnClick;
31563159
this.mapCtrl = mapCtrl;
31573160
this.markerScope = markerScope;
31583161
this.element = element;
3162+
this.clonedModel = clonedModel != null ? clonedModel : _.clone(this.model, true);
31593163
this.needToManualDestroy = needToManualDestroy != null ? needToManualDestroy : false;
31603164
this.markerIsVisibleAfterWindowClose = markerIsVisibleAfterWindowClose != null ? markerIsVisibleAfterWindowClose : true;
3165+
this.trackModel = trackModel != null ? trackModel : false;
31613166
this.destroy = __bind(this.destroy, this);
31623167
this.remove = __bind(this.remove, this);
31633168
this.getLatestPosition = __bind(this.getLatestPosition, this);
@@ -4113,7 +4118,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
41134118
_.each(IMarker.scopeKeys, function(v, k) {
41144119
return keys[k] = scope[k];
41154120
});
4116-
child = new MarkerChildModel(childScope, _.clone(model, true), keys, this.map, this.DEFAULTS, this.doClick, this.gMarkerManager, doDrawSelf = false);
4121+
child = new MarkerChildModel(childScope, model, keys, this.map, this.DEFAULTS, this.doClick, this.gMarkerManager, doDrawSelf = false);
41174122
this.scope.markerModels.put(model[this.idKey], child);
41184123
return child;
41194124
};
@@ -5324,7 +5329,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
53245329
};
53255330
this.DEFAULTS = this.scopeOrModelVal(this.optionsKey, this.scope, model) || {};
53265331
opts = this.createWindowOptions(gMarker, childScope, fakeElement.html(), this.DEFAULTS);
5327-
child = new WindowChildModel(model, childScope, opts, this.isIconVisibleOnClick, gMap, (_ref = this.markersScope) != null ? (_ref1 = _ref.markerModels.get(model[this.idKey])) != null ? _ref1.scope : void 0 : void 0, fakeElement, false, true);
5332+
child = new WindowChildModel(model, childScope, opts, this.isIconVisibleOnClick, gMap, (_ref = this.markersScope) != null ? (_ref1 = _ref.markerModels.get(model[this.idKey])) != null ? _ref1.scope : void 0 : void 0, fakeElement, false, true, true);
53285333
if (model[this.idKey] == null) {
53295334
this.$log.error('Window model has no id to assign a child to. This is required for performance. Please assign id, or redirect id to a different key.');
53305335
return;

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.

dist/angular-google-maps_dev_mapped.js

+10-5
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.map

+1-1
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

+4-4
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

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

example/assets/scripts/controllers/issue-772-info-window-show-state.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ angular.module('appMaps', ['uiGmapgoogle-maps'])
66
zoom: 4,
77
bounds: {}
88
};
9-
$scope.options = {scrollwheel: false};
9+
$scope.options = {scrollwheel: false, draggable: true};
1010
var createRandomMarker = function (i, bounds, idKey) {
1111
var lat_min = bounds.southwest.latitude,
1212
lat_range = bounds.northeast.latitude - lat_min,
@@ -52,8 +52,16 @@ angular.module('appMaps', ['uiGmapgoogle-maps'])
5252

5353
$scope.markersEvents = {
5454
mouseover: function (gMarker, eventName, model) {
55+
console.debug('mouseover');
5556
model.show = true;
56-
$scope.$apply();
57+
// $scope.$apply();
5758
}
5859
};
60+
61+
$scope.shownMarkers = function(){
62+
return _.filter($scope.randomMarkers, function(m){
63+
return m.show;
64+
}).length;
65+
};
66+
5967
});
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
4+
<!--<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">-->
55
<link rel="stylesheet" href="assets/stylesheets/example.css"/>
66
<script src="../bower_components/angular/angular.js"></script>
7-
<script src="../bower_components/angular-route/angular-route.js"></script>
7+
<!--<script src="../bower_components/angular-route/angular-route.js"></script>-->
88
<script src="../bower_components/lodash/dist/lodash.js"></script>
99

10-
<script src="../dist/angular-google-maps.js"></script>
10+
<script src="../dist/angular-google-maps_dev_mapped.js"></script>
1111
<script src="assets/scripts/controllers/issue-772-info-window-show-state.js"></script>
1212
</head>
1313
<body ng-app="appMaps">
1414
<div id="map_canvas" ng-controller="mainCtrl">
15-
<ui-gmap-google-map center="map.center" zoom="map.zoom"
16-
draggable="true" options="options" bounds="map.bounds">
15+
<ui-gmap-google-map center="map.center" zoom="map.zoom" options="options" bounds="map.bounds">
1716

1817
<ui-gmap-markers models="randomMarkers" coords="'self'"
1918
icon="'icon'" fit='true' click="'onClick'" events="markersEvents" doCluster='true'>
2019

21-
<ui-gmap-windows show="'show'">
20+
<ui-gmap-windows show="'show'" >
2221
<div ng-non-bindable>{{text}}</div>
2322
</ui-gmap-windows>
2423

2524
</ui-gmap-markers>
2625

2726
</ui-gmap-google-map>
27+
markers shown: {{shownMarkers()}}
28+
<br/>
29+
markers:{{randomMarkers}}
2830
</div>
2931
</body>
3032
</html>

src/coffee/directives/api/models/child/base-poly-child-model.coffee

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ angular.module('uiGmapgoogle-maps.directives.api')
77
@include GmapUtil
88
@include EventsHelper
99
constructor: (@scope, @attrs, @map, @defaults, @model) ->
10+
#where @model is a reference to model in the controller scope
11+
#clonedModel is a copy for comparison
12+
@clonedModel = _.clone @model, true
13+
1014
@isDragging = false
1115
@internalEvents =
1216
dragend: =>

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ angular.module('uiGmapgoogle-maps.directives.api.models.child')
2121

2222
constructor: (scope, @model, @keys, @gMap, @defaults, @doClick, @gMarkerManager, @doDrawSelf = true,
2323
@trackModel = true, @needRedraw = false) ->
24-
24+
#where @model is a reference to model in the controller scope
25+
#clonedModel is a copy for comparison
26+
@clonedModel = _.clone @model,true
2527
@deferred = uiGmapPromise.defer()
2628
_.each @keys, (v, k) =>
2729
@[k + 'Key'] = if _.isFunction @keys[k] then @keys[k]() else @keys[k]
@@ -76,7 +78,8 @@ angular.module('uiGmapgoogle-maps.directives.api.models.child')
7678
@needRedraw = true
7779

7880
updateModel: (model) =>
79-
@setMyScope 'all', _.clone(model,true), @model
81+
@cloneModel = _.clone(model,true)
82+
@setMyScope 'all', model, @model
8083

8184
renderGMarker: (doDraw = true, validCb) ->
8285
#doDraw is to only update the marker on the map when it is really ready

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ angular.module('uiGmapgoogle-maps.directives.api.models.child')
77
@include GmapUtil
88
@include EventsHelper
99
constructor: (@model, @scope, @opts, @isIconVisibleOnClick, @mapCtrl, @markerScope, @element,
10-
@needToManualDestroy = false, @markerIsVisibleAfterWindowClose = true) ->
10+
#where @model is a reference to model in the controller scope
11+
#clonedModel is a copy for comparison
12+
@clonedModel = _.clone @model, true
13+
@needToManualDestroy = false, @markerIsVisibleAfterWindowClose = true, @trackModel = false) ->
1114

1215
@getGmarker = ->
1316
@markerScope?.getGMarker() if @markerScope?['getGMarker']?

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ angular.module("uiGmapgoogle-maps.directives.api.models.parent")
169169
keys = {}
170170
_.each IMarker.scopeKeys, (v,k) ->
171171
keys[k] = scope[k]
172-
child = new MarkerChildModel(childScope, _.clone(model,true), keys, @map, @DEFAULTS,
172+
child = new MarkerChildModel(childScope, model, keys, @map, @DEFAULTS,
173173
@doClick, @gMarkerManager, doDrawSelf = false) #this is managed so child is not drawing itself
174174
@scope.markerModels.put(model[@idKey], child) #major change this makes model.id a requirement
175175
child

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ angular.module('uiGmapgoogle-maps.directives.api.models.parent')
190190
@interpolateContent(@linked.element.html(), model)
191191
@DEFAULTS = @scopeOrModelVal(@optionsKey, @scope, model) or {}
192192
opts = @createWindowOptions gMarker, childScope, fakeElement.html(), @DEFAULTS
193-
child = new WindowChildModel model, childScope, opts, @isIconVisibleOnClick, gMap, @markersScope?.markerModels.get(model[@idKey])?.scope, fakeElement, false, true
193+
child = new WindowChildModel model, childScope, opts, @isIconVisibleOnClick, gMap, @markersScope?.markerModels.get(model[@idKey])?.scope, fakeElement, false, true, true
194194

195195
unless model[@idKey]?
196196
@$log.error('Window model has no id to assign a child to. This is required for performance. Please assign id, or redirect id to a different key.')

src/coffee/directives/api/utils/models-watcher.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ angular.module('uiGmapgoogle-maps.directives.api.utils')
5151
else
5252
child = childObjects.get(m[idKey])
5353
#we're UPDATE in this case
54-
unless comparison m, child.model
54+
unless comparison m, child.clonedModel
5555
updates.push
5656
model: m
5757
child: child

0 commit comments

Comments
 (0)