Accept flat coordinates in LinearRing constructor
This commit is contained in:
@@ -418,11 +418,7 @@ GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
|
||||
GMLBase.prototype.readLinearRing = function(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
const ring = new LinearRing(null);
|
||||
ring.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
|
||||
return ring;
|
||||
} else {
|
||||
return undefined;
|
||||
return new LinearRing(flatCoordinates, GeometryLayout.XYZ);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ import {douglasPeucker} from '../geom/flat/simplify.js';
|
||||
*
|
||||
* @constructor
|
||||
* @extends {module:ol/geom/SimpleGeometry}
|
||||
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||
* @param {Array.<module:ol/coordinate~Coordinate>|Array.<number>} coordinates
|
||||
* Coordinates. (For internal use, flat coordinates in combination with
|
||||
* `opt_layout` are also accepted.)
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @api
|
||||
*/
|
||||
@@ -39,7 +41,11 @@ const LinearRing = function(coordinates, opt_layout) {
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinatesInternal(opt_layout, coordinates);
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -53,9 +59,7 @@ inherits(LinearRing, SimpleGeometry);
|
||||
* @api
|
||||
*/
|
||||
LinearRing.prototype.clone = function() {
|
||||
const linearRing = new LinearRing(null);
|
||||
linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
|
||||
return linearRing;
|
||||
return new LinearRing(this.flatCoordinates.slice(), this.layout);
|
||||
};
|
||||
|
||||
|
||||
@@ -107,10 +111,7 @@ LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance)
|
||||
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||
const simplifiedLinearRing = new LinearRing(null);
|
||||
simplifiedLinearRing.setFlatCoordinates(
|
||||
GeometryLayout.XY, simplifiedFlatCoordinates);
|
||||
return simplifiedLinearRing;
|
||||
return new LinearRing(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
};
|
||||
|
||||
|
||||
@@ -131,32 +132,18 @@ LinearRing.prototype.intersectsExtent = function(extent) {};
|
||||
|
||||
/**
|
||||
* Set the coordinates of the linear ring.
|
||||
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||
* @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
LinearRing.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
if (!coordinates) {
|
||||
this.setFlatCoordinates(GeometryLayout.XY, null);
|
||||
} else {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
LinearRing.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
|
||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
};
|
||||
export default LinearRing;
|
||||
|
||||
@@ -249,10 +249,8 @@ Polygon.prototype.getLinearRing = function(index) {
|
||||
if (index < 0 || this.ends_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
const linearRing = new LinearRing(null);
|
||||
linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]));
|
||||
return linearRing;
|
||||
return new LinearRing(this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
|
||||
};
|
||||
|
||||
|
||||
@@ -269,8 +267,7 @@ Polygon.prototype.getLinearRings = function() {
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const linearRing = new LinearRing(null);
|
||||
linearRing.setFlatCoordinates(layout, flatCoordinates.slice(offset, end));
|
||||
const linearRing = new LinearRing(flatCoordinates.slice(offset, end), layout);
|
||||
linearRings.push(linearRing);
|
||||
offset = end;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user