Created
April 21, 2016 13:52
-
-
Save sime/910343c7a3e9773cc2022e0565cbf7e8 to your computer and use it in GitHub Desktop.
Patch for Angular Google Maps 2.0.9 MultiPolygon patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- angular-google-maps.js 2016-04-21 15:48:38.000000000 +0200 | |
+++ angular-google-maps-2.0.9.custom.js 2016-04-21 15:43:34.000000000 +0200 | |
@@ -2,7 +2,6 @@ | |
* AngularJS directives for Google Maps | |
* git: https://github.com/angular-ui/angular-google-maps.git | |
*/ | |
- | |
/* | |
! | |
The MIT License | |
@@ -34,7 +33,6 @@ | |
Nicolas Laplante - https://plus.google.com/108189012221374960701 | |
Nicholas McCready - https://twitter.com/nmccready | |
*/ | |
- | |
(function() { | |
angular.module('uiGmapgoogle-maps.providers', []); | |
@@ -854,11 +852,14 @@ | |
return false; | |
} | |
if (path.type === 'Polygon') { | |
- if (path.coordinates[0].length < 4) { | |
+ for (var y = 0; y < path.coordinates.length; y++) { | |
+ if (path.coordinates[y].length < 4) { | |
return false; | |
} | |
- array = path.coordinates[0]; | |
+ } | |
+ //array = path.coordinates; | |
} else if (path.type === 'MultiPolygon') { | |
+ /* | |
trackMaxVertices = { | |
max: 0, | |
index: 0 | |
@@ -873,24 +874,72 @@ | |
array = polygon[0]; | |
if (array.length < 4) { | |
return false; | |
+ }*/ | |
+ for (var polyIndex = 0; polyIndex < path.coordinates.length; polyIndex++) { | |
+ for (var pathIndex = 0; pathIndex < path.coordinates[polyIndex].length; pathIndex++) { | |
+ if (path.coordinates[polyIndex][pathIndex].length < 4) { | |
+ return false; | |
+ } | |
+ } | |
} | |
} else if (path.type === 'LineString') { | |
if (path.coordinates.length < 2) { | |
return false; | |
} | |
- array = path.coordinates; | |
+ //array = path.coordinates; | |
} else { | |
return false; | |
} | |
+ /* | |
while (i < array.length) { | |
if (array[i].length !== 2) { | |
return false; | |
} | |
i++; | |
} | |
+ */ | |
return true; | |
} | |
}, | |
+ flattenOuterPathPoints: function(path) { | |
+ var i, latlng, result; | |
+ i = 0; | |
+ result = new google.maps.MVCArray(); | |
+ if (angular.isUndefined(path.type)) { | |
+ while (i < path.length) { | |
+ latlng; | |
+ if (angular.isDefined(path[i].latitude) && angular.isDefined(path[i].longitude)) { | |
+ latlng = new google.maps.LatLng(path[i].latitude, path[i].longitude); | |
+ } else if (typeof path[i].lat === 'function' && typeof path[i].lng === 'function') { | |
+ latlng = path[i]; | |
+ } | |
+ result.push(latlng); | |
+ i++; | |
+ } | |
+ } else { | |
+ if (path.type === "Polygon") { | |
+ i = 0; | |
+ while (i < path.coordinates[0].length) { | |
+ result.push(new google.maps.LatLng(path.coordinates[0][i][1], path.coordinates[0][i][0])); | |
+ i++; | |
+ } | |
+ } else if (path.type === "MultiPolygon") { | |
+ angular.forEach(path.coordinates, function(poly) { | |
+ i = 0; | |
+ while (i < poly[0].length) { | |
+ result.push(new google.maps.LatLng(poly[0][i][1], poly[0][i][0])); | |
+ i++; | |
+ } | |
+ }); | |
+ } else { | |
+ while (i < path.coordinates.length) { | |
+ result.push(new google.maps.LatLng(array[i][1], array[i][0])); | |
+ i++; | |
+ } | |
+ } | |
+ } | |
+ return result; | |
+ }, | |
convertPathPoints: function(path) { | |
var array, i, latlng, result, trackMaxVertices; | |
i = 0; | |
@@ -907,10 +956,12 @@ | |
i++; | |
} | |
} else { | |
- array; | |
+ array = path.coordinates; | |
+ /* | |
if (path.type === 'Polygon') { | |
- array = path.coordinates[0]; | |
+ array = path.coordinates; | |
} else if (path.type === 'MultiPolygon') { | |
+ | |
trackMaxVertices = { | |
max: 0, | |
index: 0 | |
@@ -925,11 +976,38 @@ | |
} else if (path.type === 'LineString') { | |
array = path.coordinates; | |
} | |
+ */ | |
+ if (path.type === "Polygon") { | |
+ result = []; | |
+ angular.forEach(array, function(path) { | |
+ var polyPath = new google.maps.MVCArray(); | |
+ i = 0; | |
+ while (i < path.length) { | |
+ polyPath.push(new google.maps.LatLng(path[i][1], path[i][0])); | |
+ i++; | |
+ } | |
+ result.push(polyPath); | |
+ }); | |
+ } else if (path.type === "MultiPolygon") { | |
+ result = []; | |
+ angular.forEach(array, function(poly) { | |
+ angular.forEach(poly, function(path) { | |
+ var polyPath = new google.maps.MVCArray(); | |
+ i = 0; | |
+ while (i < path.length) { | |
+ polyPath.push(new google.maps.LatLng(path[i][1], path[i][0])); | |
+ i++; | |
+ } | |
+ result.push(polyPath); | |
+ }); | |
+ }); | |
+ } else { | |
while (i < array.length) { | |
result.push(new google.maps.LatLng(array[i][1], array[i][0])); | |
i++; | |
} | |
} | |
+ } | |
return result; | |
}, | |
extendMapBounds: function(map, points) { | |
@@ -2007,7 +2085,7 @@ | |
} | |
i = 0; | |
oldLength = oldArray.getLength(); | |
- newLength = array.length; | |
+ newLength = array ? array.length : 0; | |
l = Math.min(oldLength, newLength); | |
newValue = void 0; | |
while (i < l) { | |
@@ -2269,7 +2347,7 @@ | |
PolygonOptionsBuilder.prototype.buildOpts = function(pathPoints) { | |
return PolygonOptionsBuilder.__super__.buildOpts.call(this, { | |
- path: pathPoints | |
+ paths: pathPoints | |
}, { | |
geodesic: false | |
}); | |
@@ -2836,8 +2914,11 @@ | |
} | |
pathPoints = this.convertPathPoints(scope.path); | |
polygon = new google.maps.Polygon(this.buildOpts(pathPoints)); | |
+ if (scope.id) { | |
+ polygon.id = scope.id; | |
+ } | |
if (scope.fit) { | |
- this.extendMapBounds(this.map, pathPoints); | |
+ this.extendMapBounds(this.map, this.flattenOuterPathPoints(scope.path)); | |
} | |
if (!scope["static"] && angular.isDefined(scope.editable)) { | |
scope.$watch('editable', function(newValue, oldValue) { | |
@@ -2864,7 +2945,7 @@ | |
scope.$watch('geodesic', (function(_this) { | |
return function(newValue, oldValue) { | |
if (newValue !== oldValue) { | |
- return polygon.setOptions(_this.buildOpts(polygon.getPath())); | |
+ return polygon.setOptions(_this.buildOpts(_this.convertPathPoints(scope.path))); | |
} | |
}; | |
})(this)); | |
@@ -2872,7 +2953,7 @@ | |
if (angular.isDefined(scope.stroke) && angular.isDefined(scope.stroke.opacity)) { | |
scope.$watch('stroke.opacity', (function(_this) { | |
return function(newValue, oldValue) { | |
- return polygon.setOptions(_this.buildOpts(polygon.getPath())); | |
+ return polygon.setOptions(_this.buildOpts(_this.convertPathPoints(scope.path))); | |
}; | |
})(this)); | |
} | |
@@ -2880,7 +2961,7 @@ | |
scope.$watch('stroke.weight', (function(_this) { | |
return function(newValue, oldValue) { | |
if (newValue !== oldValue) { | |
- return polygon.setOptions(_this.buildOpts(polygon.getPath())); | |
+ return polygon.setOptions(_this.buildOpts(_this.convertPathPoints(scope.path))); | |
} | |
}; | |
})(this)); | |
@@ -2889,7 +2970,7 @@ | |
scope.$watch('stroke.color', (function(_this) { | |
return function(newValue, oldValue) { | |
if (newValue !== oldValue) { | |
- return polygon.setOptions(_this.buildOpts(polygon.getPath())); | |
+ return polygon.setOptions(_this.buildOpts(_this.convertPathPoints(scope.path))); | |
} | |
}; | |
})(this)); | |
@@ -2898,7 +2979,7 @@ | |
scope.$watch('fill.color', (function(_this) { | |
return function(newValue, oldValue) { | |
if (newValue !== oldValue) { | |
- return polygon.setOptions(_this.buildOpts(polygon.getPath())); | |
+ return polygon.setOptions(_this.buildOpts(_this.convertPathPoints(scope.path))); | |
} | |
}; | |
})(this)); | |
@@ -2907,7 +2988,7 @@ | |
scope.$watch('fill.opacity', (function(_this) { | |
return function(newValue, oldValue) { | |
if (newValue !== oldValue) { | |
- return polygon.setOptions(_this.buildOpts(polygon.getPath())); | |
+ return polygon.setOptions(_this.buildOpts(_this.convertPathPoints(scope.path))); | |
} | |
}; | |
})(this)); | |
@@ -2916,7 +2997,7 @@ | |
scope.$watch('zIndex', (function(_this) { | |
return function(newValue, oldValue) { | |
if (newValue !== oldValue) { | |
- return polygon.setOptions(_this.buildOpts(polygon.getPath())); | |
+ return polygon.setOptions(_this.buildOpts(_this.convertPathPoints(scope.path))); | |
} | |
}; | |
})(this)); | |
@@ -2924,6 +3005,11 @@ | |
if (angular.isDefined(scope.events) && scope.events !== null && angular.isObject(scope.events)) { | |
this.listeners = EventsHelper.setEvents(polygon, scope, scope); | |
} | |
+ if ((attrs.control != null) && (scope.control != null)) { | |
+ scope.control.getGPoly = function() { | |
+ return polygon; | |
+ }; | |
+ } | |
arraySyncer = arraySync(polygon.getPath(), scope, 'path', (function(_this) { | |
return function(pathPoints) { | |
if (scope.fit) { | |
@@ -3532,6 +3618,11 @@ | |
} | |
}); | |
}); | |
+ if ((attrs.control != null) && (scope.control != null)) { | |
+ scope.control.getGCircle = function() { | |
+ return circle; | |
+ }; | |
+ } | |
scope.$on('$destroy', (function(_this) { | |
return function() { | |
_this.removeEvents(listeners); | |
@@ -5439,7 +5530,8 @@ | |
geodesic: "=", | |
icons: "=icons", | |
visible: "=", | |
- events: "=" | |
+ events: "=", | |
+ control: '=control' | |
} | |
}; | |
} | |
@@ -5628,6 +5720,7 @@ | |
IPolygon.prototype.require = '^' + 'uiGmapGoogleMap'; | |
IPolygon.prototype.scope = { | |
+ id: "=id", | |
path: '=path', | |
stroke: '=stroke', | |
clickable: '=', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment