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