Merge pull request #11481 from michalzielanski/additional-props-in-cloned-geom
Adding original properties to cloned geometry
This commit is contained in:
@@ -188,6 +188,18 @@ class BaseObject extends Observable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply any properties from another object without triggering events.
|
||||||
|
* @param {BaseObject} source The source object.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
applyProperties(source) {
|
||||||
|
if (!source.values_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assign(this.values_ || (this.values_ = {}), source.values_);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unsets a property.
|
* Unsets a property.
|
||||||
* @param {string} key Key name.
|
* @param {string} key Key name.
|
||||||
|
|||||||
@@ -37,7 +37,13 @@ class Circle extends SimpleGeometry {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
clone() {
|
clone() {
|
||||||
return new Circle(this.flatCoordinates.slice(), undefined, this.layout);
|
const circle = new Circle(
|
||||||
|
this.flatCoordinates.slice(),
|
||||||
|
undefined,
|
||||||
|
this.layout
|
||||||
|
);
|
||||||
|
circle.applyProperties(this);
|
||||||
|
return circle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class GeometryCollection extends Geometry {
|
|||||||
clone() {
|
clone() {
|
||||||
const geometryCollection = new GeometryCollection(null);
|
const geometryCollection = new GeometryCollection(null);
|
||||||
geometryCollection.setGeometries(this.geometries_);
|
geometryCollection.setGeometries(this.geometries_);
|
||||||
|
geometryCollection.applyProperties(this);
|
||||||
return geometryCollection;
|
return geometryCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,12 @@ class LineString extends SimpleGeometry {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
clone() {
|
clone() {
|
||||||
return new LineString(this.flatCoordinates.slice(), this.layout);
|
const lineString = new LineString(
|
||||||
|
this.flatCoordinates.slice(),
|
||||||
|
this.layout
|
||||||
|
);
|
||||||
|
lineString.applyProperties(this);
|
||||||
|
return lineString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -102,11 +102,13 @@ class MultiLineString extends SimpleGeometry {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
clone() {
|
clone() {
|
||||||
return new MultiLineString(
|
const multiLineString = new MultiLineString(
|
||||||
this.flatCoordinates.slice(),
|
this.flatCoordinates.slice(),
|
||||||
this.layout,
|
this.layout,
|
||||||
this.ends_.slice()
|
this.ends_.slice()
|
||||||
);
|
);
|
||||||
|
multiLineString.applyProperties(this);
|
||||||
|
return multiLineString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class MultiPoint extends SimpleGeometry {
|
|||||||
this.flatCoordinates.slice(),
|
this.flatCoordinates.slice(),
|
||||||
this.layout
|
this.layout
|
||||||
);
|
);
|
||||||
|
multiPoint.applyProperties(this);
|
||||||
return multiPoint;
|
return multiPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -155,11 +155,14 @@ class MultiPolygon extends SimpleGeometry {
|
|||||||
newEndss[i] = this.endss_[i].slice();
|
newEndss[i] = this.endss_[i].slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MultiPolygon(
|
const multiPolygon = new MultiPolygon(
|
||||||
this.flatCoordinates.slice(),
|
this.flatCoordinates.slice(),
|
||||||
this.layout,
|
this.layout,
|
||||||
newEndss
|
newEndss
|
||||||
);
|
);
|
||||||
|
multiPolygon.applyProperties(this);
|
||||||
|
|
||||||
|
return multiPolygon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class Point extends SimpleGeometry {
|
|||||||
*/
|
*/
|
||||||
clone() {
|
clone() {
|
||||||
const point = new Point(this.flatCoordinates.slice(), this.layout);
|
const point = new Point(this.flatCoordinates.slice(), this.layout);
|
||||||
|
point.applyProperties(this);
|
||||||
return point;
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,11 +118,13 @@ class Polygon extends SimpleGeometry {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
clone() {
|
clone() {
|
||||||
return new Polygon(
|
const polygon = new Polygon(
|
||||||
this.flatCoordinates.slice(),
|
this.flatCoordinates.slice(),
|
||||||
this.layout,
|
this.layout,
|
||||||
this.ends_.slice()
|
this.ends_.slice()
|
||||||
);
|
);
|
||||||
|
polygon.applyProperties(this);
|
||||||
|
return polygon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,11 +9,14 @@ describe('ol.geom.Circle', function () {
|
|||||||
|
|
||||||
describe('#clone', function () {
|
describe('#clone', function () {
|
||||||
it('returns a clone', function () {
|
it('returns a clone', function () {
|
||||||
|
circle.setProperties({foo: 'bar', baz: null});
|
||||||
|
|
||||||
const clone = circle.clone();
|
const clone = circle.clone();
|
||||||
expect(clone).to.be.an(Circle);
|
expect(clone).to.be.an(Circle);
|
||||||
expect(clone.getCenter()).to.eql(circle.getCenter());
|
expect(clone.getCenter()).to.eql(circle.getCenter());
|
||||||
expect(clone.getCenter()).not.to.be(circle.getCenter());
|
expect(clone.getCenter()).not.to.be(circle.getCenter());
|
||||||
expect(clone.getRadius()).to.be(circle.getRadius());
|
expect(clone.getRadius()).to.be(circle.getRadius());
|
||||||
|
expect(clone.getProperties()).to.eql({foo: 'bar', baz: null});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ describe('ol.geom.GeometryCollection', function () {
|
|||||||
]);
|
]);
|
||||||
const poly = new Polygon([outer, inner1, inner2]);
|
const poly = new Polygon([outer, inner1, inner2]);
|
||||||
const multi = new GeometryCollection([point, line, poly]);
|
const multi = new GeometryCollection([point, line, poly]);
|
||||||
|
multi.setProperties({foo: 'bar', baz: null});
|
||||||
const clone = multi.clone();
|
const clone = multi.clone();
|
||||||
expect(clone).to.not.be(multi);
|
expect(clone).to.not.be(multi);
|
||||||
const geometries = clone.getGeometries();
|
const geometries = clone.getGeometries();
|
||||||
@@ -106,6 +107,7 @@ describe('ol.geom.GeometryCollection', function () {
|
|||||||
[30, 40],
|
[30, 40],
|
||||||
]);
|
]);
|
||||||
expect(geometries[2].getCoordinates()).to.eql([outer, inner1, inner2]);
|
expect(geometries[2].getCoordinates()).to.eql([outer, inner1, inner2]);
|
||||||
|
expect(clone.getProperties()).to.eql({foo: 'bar', baz: null});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does a deep clone', function () {
|
it('does a deep clone', function () {
|
||||||
|
|||||||
@@ -276,8 +276,11 @@ describe('ol.geom.MultiPolygon', function () {
|
|||||||
|
|
||||||
describe('#clone()', function () {
|
describe('#clone()', function () {
|
||||||
it('has the expected endss_', function () {
|
it('has the expected endss_', function () {
|
||||||
|
multiPolygon.setProperties({foo: 'bar', baz: null});
|
||||||
|
|
||||||
const clone = multiPolygon.clone();
|
const clone = multiPolygon.clone();
|
||||||
expect(multiPolygon.endss_).to.eql(clone.endss_);
|
expect(multiPolygon.endss_).to.eql(clone.endss_);
|
||||||
|
expect(clone.getProperties()).to.eql({foo: 'bar', baz: null});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user