Adding original properties to cloned geometry
This commit is contained in:
@@ -37,7 +37,13 @@ class Circle extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new Circle(this.flatCoordinates.slice(), undefined, this.layout);
|
||||
const circle = new Circle(
|
||||
this.flatCoordinates.slice(),
|
||||
undefined,
|
||||
this.layout
|
||||
);
|
||||
circle.importPropertiesFrom(this);
|
||||
return circle;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -109,6 +109,17 @@ class Geometry extends BaseObject {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* Import properties from another geometry.
|
||||
* @param {Geometry} geometry Source geometry.
|
||||
* @protected
|
||||
*/
|
||||
importPropertiesFrom(geometry) {
|
||||
if (geometry.hasProperties()) {
|
||||
this.setProperties(geometry.getProperties(), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {number} x X.
|
||||
|
||||
@@ -69,6 +69,7 @@ class GeometryCollection extends Geometry {
|
||||
clone() {
|
||||
const geometryCollection = new GeometryCollection(null);
|
||||
geometryCollection.setGeometries(this.geometries_);
|
||||
geometryCollection.importPropertiesFrom(this);
|
||||
return geometryCollection;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,12 @@ class LineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new LineString(this.flatCoordinates.slice(), this.layout);
|
||||
const lineString = new LineString(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout
|
||||
);
|
||||
lineString.importPropertiesFrom(this);
|
||||
return lineString;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -102,11 +102,13 @@ class MultiLineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new MultiLineString(
|
||||
const multiLineString = new MultiLineString(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
this.ends_.slice()
|
||||
);
|
||||
multiLineString.importPropertiesFrom(this);
|
||||
return multiLineString;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,6 +61,7 @@ class MultiPoint extends SimpleGeometry {
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout
|
||||
);
|
||||
multiPoint.importPropertiesFrom(this);
|
||||
return multiPoint;
|
||||
}
|
||||
|
||||
|
||||
@@ -155,11 +155,14 @@ class MultiPolygon extends SimpleGeometry {
|
||||
newEndss[i] = this.endss_[i].slice();
|
||||
}
|
||||
|
||||
return new MultiPolygon(
|
||||
const multiPolygon = new MultiPolygon(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
newEndss
|
||||
);
|
||||
multiPolygon.importPropertiesFrom(this);
|
||||
|
||||
return multiPolygon;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@ class Point extends SimpleGeometry {
|
||||
*/
|
||||
clone() {
|
||||
const point = new Point(this.flatCoordinates.slice(), this.layout);
|
||||
point.importPropertiesFrom(this);
|
||||
return point;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,11 +118,13 @@ class Polygon extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new Polygon(
|
||||
const polygon = new Polygon(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
this.ends_.slice()
|
||||
);
|
||||
polygon.importPropertiesFrom(this);
|
||||
return polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user