8000 polylines and builder bugs fixed · angular-ui/angular-google-maps@7209cbe · GitHub
[go: up one dir, main page]

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

Commit 7209cbe

Browse files
committed
polylines and builder bugs fixed
1 parent d5a3ff9 commit 7209cbe

File tree

6 files changed

+60
-50
lines changed

6 files changed

+60
-50
lines changed

dist/angular-google-maps.js

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ Nicholas McCready - https://twitter.com/nmccready
19001900
];
19011901

19021902
CommonOptionsBuilder.prototype.buildOpts = function(customOpts, forEachOpts) {
1903-
var opts, _ref, _ref1, _ref2;
1903+
var hasModel, model, opts, _ref, _ref1, _ref2;
19041904
if (customOpts == null) {
19051905
customOpts = {};
19061906
}
@@ -1915,11 +1915,13 @@ Nicholas McCready - https://twitter.com/nmccready
19151915
$log.error("this.map not defined in CommonOptionsBuilder can not buildOpts");
19161916
return;
19171917
}
1918+
hasModel = _(this.scope).chain().keys().contains('model').value();
1919+
model = hasModel ? this.scope.model : this.scope;
19181920
opts = angular.extend(customOpts, this.DEFAULTS, {
19191921
map: this.map,
1920-
strokeColor: (_ref = this.scope.stroke) != null ? _ref.color : void 0,
1921-
strokeOpacity: (_ref1 = this.scope.stroke) != null ? _ref1.opacity : void 0,
1922-
strokeWeight: (_ref2 = this.scope.stroke) != null ? _ref2.weight : void 0
1922+
strokeColor: (_ref = model.stroke) != null ? _ref.color : void 0,
1923+
strokeOpacity: (_ref1 = model.stroke) != null ? _ref1.opacity : void 0,
1924+
strokeWeight: (_ref2 = model.stroke) != null ? _ref2.weight : void 0
19231925
});
19241926
angular.forEach(angular.extend(forEachOpts, {
19251927
clickable: true,
@@ -1931,10 +1933,10 @@ Nicholas McCready - https://twitter.com/nmccready
19311933
zIndex: 0
19321934
}), (function(_this) {
19331935
return function(defaultValue, key) {
1934-
if (angular.isUndefined(_this.scope[key]) || _this.scope[key] === null) {
1936+
if (angular.isUndefined(model[key] || model[key] === null)) {
19351937
return opts[key] = defaultValue;
19361938
} else {
1937-
return opts[key] = _this.scope[key];
1939+
return opts[key] = model[key];
19381940
}
19391941
};
19401942
})(this));
@@ -2632,34 +2634,41 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
26322634
PolylineChildModel.include(EventsHelper);
26332635

26342636
function PolylineChildModel(scope, attrs, map, defaults, model) {
2637+
var createPolyline;
26352638
this.scope = scope;
26362639
this.attrs = attrs;
26372640
this.map = map;
26382641
this.defaults = defaults;
26392642
this.model = model;
26402643
this.clean = __bind(this.clean, this);
2641-
scope.$watch('path', (function(_this) {
2642-
return function(newValue, oldValue) {
2644+
createPolyline = (function(_this) {
2645+
return function() {
26432646
var pathPoints;
2644-
if (!_.isEqual(newValue, oldValue) || !_this.polyline) {
2645-
pathPoints = _this.convertPathPoints(scope.path);
2646-
if (_this.polyline != null) {
2647-
_this.clean();
2648-
}
2649-
if (pathPoints.length > 0) {
2650-
_this.polyline = new google.maps.Polyline(_this.buildOpts(pathPoints));
2647+
pathPoints = _this.convertPathPoints(_this.scope.path);
2648+
if (_this.polyline != null) {
2649+
_this.clean();
2650+
}
2651+
if (pathPoints.length > 0) {
2652+
_this.polyline = new google.maps.Polyline(_this.buildOpts(pathPoints));
2653+
}
2654+
if (_this.polyline) {
2655+
if (_this.scope.fit) {
2656+
_this.extendMapBounds(map, pathPoints);
26512657
}
2652-
if (_this.polyline) {
2653-
if (scope.fit) {
2654-
_this.extendMapBounds(map, pathPoints);
2658+
arraySync(_this.polyline.getPath(), _this.scope, "path", function(pathPoints) {
2659+
if (_this.scope.fit) {
2660+
return _this.extendMapBounds(map, pathPoints);
26552661
}
2656-
arraySync(_this.polyline.getPath(), scope, "path", function(pathPoints) {
2657-
if (scope.fit) {
2658-
return _this.extendMapBounds(map, pathPoints);
2659-
}
2660-
});
2661-
return _this.listeners = _this.model ? _this.setEvents(_this.polyline, scope, _this.model) : _this.setEvents(_this.polyline, scope, scope);
2662-
}
2662+
});
2663+
return _this.listeners = _this.model ? _this.setEvents(_this.polyline, _this.scope, _this.model) : _this.setEvents(_this.polyline, _this.scope, _this.scope);
2664+
}
2665+
};
2666+
})(this);
2667+
createPolyline();
2668+
scope.$watch('path', (function(_this) {
2669+
return function(newValue, oldValue) {
2670+
if (!_.isEqual(newValue, oldValue) || !_this.polyline) {
2671+
return createPolyline();
26632672
}
26642673
};
26652674
})(this));

dist/angular-google-maps.min.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

example/assets/scripts/controllers/shapes-lines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ angular.module("angular-google-maps-example", ["google-maps".ns()]).value("rndAd
155155
color: '#6060FB',
156156
weight: 3
157157
},
158-
editable: true,
158+
editable: false,
159159
draggable: true,
160160
geodesic: true,
161161
visible: true

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ angular.module("google-maps.directives.api".ns())
1818
polygon = new google.maps.Polygon(@buildOpts(pathPoints))
1919
@extendMapBounds @map, pathPoints if scope.fit
2020

21+
#TODO refactor all these sets and watches to be handled functionally as an array
2122
if !scope.static and angular.isDefined(scope.editable)
2223
scope.$watch "editable", (newValue, oldValue) ->
2324
polygon.setEditable newValue if newValue != oldValue

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ angular.module("google-maps.directives.api".ns())
88
@include GmapUtil
99
@include EventsHelper
1010
constructor: (@scope, @attrs, @map, @defaults, @model) ->
11+
12+
createPolyline = =>
13+
pathPoints = @convertPathPoints @scope.path
14+
if @polyline?
15+
@clean()
16+
@polyline = new google.maps.Polyline @buildOpts pathPoints if pathPoints.length > 0
17+
if @polyline
18+
@extendMapBounds map, pathPoints if @scope.fit
19+
arraySync @polyline.getPath(), @scope, "path", (pathPoints) =>
20+
@extendMapBounds map, pathPoints if @scope.fit
21+
@listeners = if @model then @setEvents @polyline, @scope, @model else @setEvents @polyline, @scope, @scope
22+
23+
createPolyline() #handle stuff without being dependent on digests (ie using watches for init)
24+
1125
scope.$watch 'path', (newValue, oldValue) =>
1226
if not _.isEqual(newValue, oldValue) or not @polyline
13-
pathPoints = @convertPathPoints scope.path
14-
if @polyline?
15-
@clean()
16-
@polyline = new google.maps.Polyline @buildOpts pathPoints if pathPoints.length > 0
17-
if @polyline
18-
@extendMapBounds map, pathPoints if scope.fit
19-
arraySync @polyline.getPath(), scope, "path", (pathPoints) =>
20-
@extendMapBounds map, pathPoints if scope.fit
21-
@listeners = if @model then @setEvents @polyline, scope, @model else @setEvents @polyline, scope, scope
22-
27+
createPolyline()
28+
#TODO refactor all these sets and watches to be handled functionally as an array
2329
if !scope.static and angular.isDefined(scope.editable)
2430
scope.$watch "editable", (newValue, oldValue) =>
2531
@polyline?.setEditable newValue if newValue != oldValue

src/coffee/directives/api/options/builders/common-options-builder.cof 1C6A fee

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ angular.module("google-maps.directives.api.options.builders".ns())
1616
unless @map
1717
$log.error "this.map not defined in CommonOptionsBuilder can not buildOpts"
1818
return
19+
hasModel = _(@scope).chain().keys().contains('model').value()
20+
model = if hasModel then @scope.model else @scope #handle plurals
21+
1922
opts = angular.extend customOpts, @DEFAULTS,
2023
map: @map
21-
strokeColor: @scope.stroke?.color
22-
strokeOpacity: @scope.stroke?.opacity
23-
strokeWeight: @scope.stroke?.weight
24+
strokeColor: model.stroke?.color
25+
strokeOpacity: model.stroke?.opacity
26+
strokeWeight: model.stroke?.weight
2427

2528
angular.forEach angular.extend(forEachOpts,
2629
clickable: true
@@ -31,10 +34,10 @@ angular.module("google-maps.directives.api.options.builders".ns())
3134
visible: true
3235
zIndex: 0
3336
), (defaultValue, key) =>
34-
if angular.isUndefined(@scope[key]) or @scope[key] is null
37+
if angular.isUndefined model[key] or model[key] is null
3538
opts[key] = defaultValue
3639
else
37-
opts[key] = @scope[key]
40+
opts[key] = model[key]
3841

3942
opts.editable = false if opts.static
4043
opts

0 commit comments

Comments
 (0)
0