Deep clone geometry coordinates

Our geometries are mutable, so they can be modified without
creating garbage by changing coordinates in place and calling
setGeometry afterwards. But this also means that we need to
create a deep clone of the coordinates.
This commit is contained in:
ahocevar
2013-11-12 11:36:40 +01:00
parent 15053cbe56
commit ed09173730
2 changed files with 17 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ goog.provide('ol.geom.GeometryType');
goog.require('goog.events.Event');
goog.require('goog.events.EventTarget');
goog.require('goog.object');
goog.require('ol.Extent');
goog.require('ol.TransformFunction');
@@ -25,7 +26,7 @@ goog.inherits(ol.geom.Geometry, goog.events.EventTarget);
* @return {ol.geom.Geometry} The cloned geometry.
*/
ol.geom.Geometry.prototype.clone = function() {
return new this.constructor(this.getCoordinates());
return new this.constructor(goog.object.unsafeClone(this.getCoordinates()));
};