Automated class transform
npx lebab --replace src --transform class
This commit is contained in:
+190
-202
@@ -20,213 +20,201 @@ import {deflateCoordinate} from '../geom/flat/deflate.js';
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @api
|
||||
*/
|
||||
const Circle = function(center, opt_radius, opt_layout) {
|
||||
SimpleGeometry.call(this);
|
||||
if (opt_layout !== undefined && opt_radius === undefined) {
|
||||
this.setFlatCoordinates(opt_layout, center);
|
||||
} else {
|
||||
const radius = opt_radius ? opt_radius : 0;
|
||||
this.setCenterAndRadius(center, radius, opt_layout);
|
||||
class Circle {
|
||||
constructor(center, opt_radius, opt_layout) {
|
||||
SimpleGeometry.call(this);
|
||||
if (opt_layout !== undefined && opt_radius === undefined) {
|
||||
this.setFlatCoordinates(opt_layout, center);
|
||||
} else {
|
||||
const radius = opt_radius ? opt_radius : 0;
|
||||
this.setCenterAndRadius(center, radius, opt_layout);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/Circle} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new Circle(this.flatCoordinates.slice(), undefined, this.layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const dx = x - flatCoordinates[0];
|
||||
const dy = y - flatCoordinates[1];
|
||||
const squaredDistance = dx * dx + dy * dy;
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
if (squaredDistance === 0) {
|
||||
for (let i = 0; i < this.stride; ++i) {
|
||||
closestPoint[i] = flatCoordinates[i];
|
||||
}
|
||||
} else {
|
||||
const delta = this.getRadius() / Math.sqrt(squaredDistance);
|
||||
closestPoint[0] = flatCoordinates[0] + delta * dx;
|
||||
closestPoint[1] = flatCoordinates[1] + delta * dy;
|
||||
for (let i = 2; i < this.stride; ++i) {
|
||||
closestPoint[i] = flatCoordinates[i];
|
||||
}
|
||||
}
|
||||
closestPoint.length = this.stride;
|
||||
return squaredDistance;
|
||||
} else {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
containsXY(x, y) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const dx = x - flatCoordinates[0];
|
||||
const dy = y - flatCoordinates[1];
|
||||
return dx * dx + dy * dy <= this.getRadiusSquared_();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the center of the circle as {@link module:ol/coordinate~Coordinate coordinate}.
|
||||
* @return {module:ol/coordinate~Coordinate} Center.
|
||||
* @api
|
||||
*/
|
||||
getCenter() {
|
||||
return this.flatCoordinates.slice(0, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
computeExtent(extent) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const radius = flatCoordinates[this.stride] - flatCoordinates[0];
|
||||
return createOrUpdate(
|
||||
flatCoordinates[0] - radius, flatCoordinates[1] - radius,
|
||||
flatCoordinates[0] + radius, flatCoordinates[1] + radius,
|
||||
extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the radius of the circle.
|
||||
* @return {number} Radius.
|
||||
* @api
|
||||
*/
|
||||
getRadius() {
|
||||
return Math.sqrt(this.getRadiusSquared_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @return {number} Radius squared.
|
||||
*/
|
||||
getRadiusSquared_() {
|
||||
const dx = this.flatCoordinates[this.stride] - this.flatCoordinates[0];
|
||||
const dy = this.flatCoordinates[this.stride + 1] - this.flatCoordinates[1];
|
||||
return dx * dx + dy * dy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.CIRCLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
const circleExtent = this.getExtent();
|
||||
if (intersects(extent, circleExtent)) {
|
||||
const center = this.getCenter();
|
||||
|
||||
if (extent[0] <= center[0] && extent[2] >= center[0]) {
|
||||
return true;
|
||||
}
|
||||
if (extent[1] <= center[1] && extent[3] >= center[1]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return forEachCorner(extent, this.intersectsCoordinate, this);
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the center of the circle as {@link module:ol/coordinate~Coordinate coordinate}.
|
||||
* @param {module:ol/coordinate~Coordinate} center Center.
|
||||
* @api
|
||||
*/
|
||||
setCenter(center) {
|
||||
const stride = this.stride;
|
||||
const radius = this.flatCoordinates[stride] - this.flatCoordinates[0];
|
||||
const flatCoordinates = center.slice();
|
||||
flatCoordinates[stride] = flatCoordinates[0] + radius;
|
||||
for (let i = 1; i < stride; ++i) {
|
||||
flatCoordinates[stride + i] = center[i];
|
||||
}
|
||||
this.setFlatCoordinates(this.layout, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the center (as {@link module:ol/coordinate~Coordinate coordinate}) and the radius (as
|
||||
* number) of the circle.
|
||||
* @param {!module:ol/coordinate~Coordinate} center Center.
|
||||
* @param {number} radius Radius.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @api
|
||||
*/
|
||||
setCenterAndRadius(center, radius, opt_layout) {
|
||||
this.setLayout(opt_layout, center, 0);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
/** @type {Array.<number>} */
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
let offset = deflateCoordinate(
|
||||
flatCoordinates, 0, center, this.stride);
|
||||
flatCoordinates[offset++] = flatCoordinates[0] + radius;
|
||||
for (let i = 1, ii = this.stride; i < ii; ++i) {
|
||||
flatCoordinates[offset++] = flatCoordinates[i];
|
||||
}
|
||||
flatCoordinates.length = offset;
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getCoordinates() {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {}
|
||||
|
||||
/**
|
||||
* Set the radius of the circle. The radius is in the units of the projection.
|
||||
* @param {number} radius Radius.
|
||||
* @api
|
||||
*/
|
||||
setRadius(radius) {
|
||||
this.flatCoordinates[this.stride] = this.flatCoordinates[0] + radius;
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Circle, SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/Circle} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
Circle.prototype.clone = function() {
|
||||
return new Circle(this.flatCoordinates.slice(), undefined, this.layout);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Circle.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const dx = x - flatCoordinates[0];
|
||||
const dy = y - flatCoordinates[1];
|
||||
const squaredDistance = dx * dx + dy * dy;
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
if (squaredDistance === 0) {
|
||||
for (let i = 0; i < this.stride; ++i) {
|
||||
closestPoint[i] = flatCoordinates[i];
|
||||
}
|
||||
} else {
|
||||
const delta = this.getRadius() / Math.sqrt(squaredDistance);
|
||||
closestPoint[0] = flatCoordinates[0] + delta * dx;
|
||||
closestPoint[1] = flatCoordinates[1] + delta * dy;
|
||||
for (let i = 2; i < this.stride; ++i) {
|
||||
closestPoint[i] = flatCoordinates[i];
|
||||
}
|
||||
}
|
||||
closestPoint.length = this.stride;
|
||||
return squaredDistance;
|
||||
} else {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Circle.prototype.containsXY = function(x, y) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const dx = x - flatCoordinates[0];
|
||||
const dy = y - flatCoordinates[1];
|
||||
return dx * dx + dy * dy <= this.getRadiusSquared_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the center of the circle as {@link module:ol/coordinate~Coordinate coordinate}.
|
||||
* @return {module:ol/coordinate~Coordinate} Center.
|
||||
* @api
|
||||
*/
|
||||
Circle.prototype.getCenter = function() {
|
||||
return this.flatCoordinates.slice(0, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Circle.prototype.computeExtent = function(extent) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const radius = flatCoordinates[this.stride] - flatCoordinates[0];
|
||||
return createOrUpdate(
|
||||
flatCoordinates[0] - radius, flatCoordinates[1] - radius,
|
||||
flatCoordinates[0] + radius, flatCoordinates[1] + radius,
|
||||
extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the radius of the circle.
|
||||
* @return {number} Radius.
|
||||
* @api
|
||||
*/
|
||||
Circle.prototype.getRadius = function() {
|
||||
return Math.sqrt(this.getRadiusSquared_());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @return {number} Radius squared.
|
||||
*/
|
||||
Circle.prototype.getRadiusSquared_ = function() {
|
||||
const dx = this.flatCoordinates[this.stride] - this.flatCoordinates[0];
|
||||
const dy = this.flatCoordinates[this.stride + 1] - this.flatCoordinates[1];
|
||||
return dx * dx + dy * dy;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
Circle.prototype.getType = function() {
|
||||
return GeometryType.CIRCLE;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
Circle.prototype.intersectsExtent = function(extent) {
|
||||
const circleExtent = this.getExtent();
|
||||
if (intersects(extent, circleExtent)) {
|
||||
const center = this.getCenter();
|
||||
|
||||
if (extent[0] <= center[0] && extent[2] >= center[0]) {
|
||||
return true;
|
||||
}
|
||||
if (extent[1] <= center[1] && extent[3] >= center[1]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return forEachCorner(extent, this.intersectsCoordinate, this);
|
||||
}
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the center of the circle as {@link module:ol/coordinate~Coordinate coordinate}.
|
||||
* @param {module:ol/coordinate~Coordinate} center Center.
|
||||
* @api
|
||||
*/
|
||||
Circle.prototype.setCenter = function(center) {
|
||||
const stride = this.stride;
|
||||
const radius = this.flatCoordinates[stride] - this.flatCoordinates[0];
|
||||
const flatCoordinates = center.slice();
|
||||
flatCoordinates[stride] = flatCoordinates[0] + radius;
|
||||
for (let i = 1; i < stride; ++i) {
|
||||
flatCoordinates[stride + i] = center[i];
|
||||
}
|
||||
this.setFlatCoordinates(this.layout, flatCoordinates);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the center (as {@link module:ol/coordinate~Coordinate coordinate}) and the radius (as
|
||||
* number) of the circle.
|
||||
* @param {!module:ol/coordinate~Coordinate} center Center.
|
||||
* @param {number} radius Radius.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @api
|
||||
*/
|
||||
Circle.prototype.setCenterAndRadius = function(center, radius, opt_layout) {
|
||||
this.setLayout(opt_layout, center, 0);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
/** @type {Array.<number>} */
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
let offset = deflateCoordinate(
|
||||
flatCoordinates, 0, center, this.stride);
|
||||
flatCoordinates[offset++] = flatCoordinates[0] + radius;
|
||||
for (let i = 1, ii = this.stride; i < ii; ++i) {
|
||||
flatCoordinates[offset++] = flatCoordinates[i];
|
||||
}
|
||||
flatCoordinates.length = offset;
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Circle.prototype.getCoordinates = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Circle.prototype.setCoordinates = function(coordinates, opt_layout) {};
|
||||
|
||||
|
||||
/**
|
||||
* Set the radius of the circle. The radius is in the units of the projection.
|
||||
* @param {number} radius Radius.
|
||||
* @api
|
||||
*/
|
||||
Circle.prototype.setRadius = function(radius) {
|
||||
this.flatCoordinates[this.stride] = this.flatCoordinates[0] + radius;
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Transform each coordinate of the circle from one coordinate reference system
|
||||
* to another. The geometry is modified in place.
|
||||
|
||||
+212
-223
@@ -25,41 +25,225 @@ import {create as createTransform, compose as composeTransform} from '../transfo
|
||||
* @extends {module:ol/Object}
|
||||
* @api
|
||||
*/
|
||||
const Geometry = function() {
|
||||
class Geometry {
|
||||
constructor() {
|
||||
|
||||
BaseObject.call(this);
|
||||
BaseObject.call(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/extent~Extent}
|
||||
*/
|
||||
this.extent_ = createEmpty();
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/extent~Extent}
|
||||
*/
|
||||
this.extent_ = createEmpty();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.extentRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.extentRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Object.<string, module:ol/geom/Geometry>}
|
||||
*/
|
||||
this.simplifiedGeometryCache = {};
|
||||
/**
|
||||
* @protected
|
||||
* @type {Object.<string, module:ol/geom/Geometry>}
|
||||
*/
|
||||
this.simplifiedGeometryCache = {};
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.simplifiedGeometryRevision = 0;
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.simplifiedGeometryRevision = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @abstract
|
||||
* @return {!module:ol/geom/Geometry} Clone.
|
||||
*/
|
||||
clone() {}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @param {module:ol/coordinate~Coordinate} closestPoint Closest point.
|
||||
* @param {number} minSquaredDistance Minimum squared distance.
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {}
|
||||
|
||||
/**
|
||||
* Return the closest point of the geometry to the passed point as
|
||||
* {@link module:ol/coordinate~Coordinate coordinate}.
|
||||
* @param {module:ol/coordinate~Coordinate} point Point.
|
||||
* @param {module:ol/coordinate~Coordinate=} opt_closestPoint Closest point.
|
||||
* @return {module:ol/coordinate~Coordinate} Closest point.
|
||||
* @api
|
||||
*/
|
||||
getClosestPoint(point, opt_closestPoint) {
|
||||
const closestPoint = opt_closestPoint ? opt_closestPoint : [NaN, NaN];
|
||||
this.closestPointXY(point[0], point[1], closestPoint, Infinity);
|
||||
return closestPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this geometry includes the specified coordinate. If the
|
||||
* coordinate is on the boundary of the geometry, returns false.
|
||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||
* @return {boolean} Contains coordinate.
|
||||
* @api
|
||||
*/
|
||||
intersectsCoordinate(coordinate) {
|
||||
return this.containsXY(coordinate[0], coordinate[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/extent~Extent} extent Extent.
|
||||
* @protected
|
||||
* @return {module:ol/extent~Extent} extent Extent.
|
||||
*/
|
||||
computeExtent(extent) {}
|
||||
|
||||
/**
|
||||
* Get the extent of the geometry.
|
||||
* @param {module:ol/extent~Extent=} opt_extent Extent.
|
||||
* @return {module:ol/extent~Extent} extent Extent.
|
||||
* @api
|
||||
*/
|
||||
getExtent(opt_extent) {
|
||||
if (this.extentRevision_ != this.getRevision()) {
|
||||
this.extent_ = this.computeExtent(this.extent_);
|
||||
this.extentRevision_ = this.getRevision();
|
||||
}
|
||||
return returnOrUpdate(this.extent_, opt_extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the geometry around a given coordinate. This modifies the geometry
|
||||
* coordinates in place.
|
||||
* @abstract
|
||||
* @param {number} angle Rotation angle in radians.
|
||||
* @param {module:ol/coordinate~Coordinate} anchor The rotation center.
|
||||
* @api
|
||||
*/
|
||||
rotate(angle, anchor) {}
|
||||
|
||||
/**
|
||||
* Scale the geometry (with an optional origin). This modifies the geometry
|
||||
* coordinates in place.
|
||||
* @abstract
|
||||
* @param {number} sx The scaling factor in the x-direction.
|
||||
* @param {number=} opt_sy The scaling factor in the y-direction (defaults to
|
||||
* sx).
|
||||
* @param {module:ol/coordinate~Coordinate=} opt_anchor The scale origin (defaults to the center
|
||||
* of the geometry extent).
|
||||
* @api
|
||||
*/
|
||||
scale(sx, opt_sy, opt_anchor) {}
|
||||
|
||||
/**
|
||||
* Create a simplified version of this geometry. For linestrings, this uses
|
||||
* the the {@link
|
||||
* https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
|
||||
* Douglas Peucker} algorithm. For polygons, a quantization-based
|
||||
* simplification is used to preserve topology.
|
||||
* @function
|
||||
* @param {number} tolerance The tolerance distance for simplification.
|
||||
* @return {module:ol/geom/Geometry} A new, simplified version of the original
|
||||
* geometry.
|
||||
* @api
|
||||
*/
|
||||
simplify(tolerance) {
|
||||
return this.getSimplifiedGeometry(tolerance * tolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a simplified version of this geometry using the Douglas Peucker
|
||||
* algorithm.
|
||||
* @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
|
||||
* @abstract
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {module:ol/geom/Geometry} Simplified geometry.
|
||||
*/
|
||||
getSimplifiedGeometry(squaredTolerance) {}
|
||||
|
||||
/**
|
||||
* Get the type of this geometry.
|
||||
* @abstract
|
||||
* @return {module:ol/geom/GeometryType} Geometry type.
|
||||
*/
|
||||
getType() {}
|
||||
|
||||
/**
|
||||
* Apply a transform function to each coordinate of the geometry.
|
||||
* The geometry is modified in place.
|
||||
* If you do not want the geometry modified in place, first `clone()` it and
|
||||
* then use this function on the clone.
|
||||
* @abstract
|
||||
* @param {module:ol/proj~TransformFunction} transformFn Transform.
|
||||
*/
|
||||
applyTransform(transformFn) {}
|
||||
|
||||
/**
|
||||
* Test if the geometry and the passed extent intersect.
|
||||
* @abstract
|
||||
* @param {module:ol/extent~Extent} extent Extent.
|
||||
* @return {boolean} `true` if the geometry and the extent intersect.
|
||||
*/
|
||||
intersectsExtent(extent) {}
|
||||
|
||||
/**
|
||||
* Translate the geometry. This modifies the geometry coordinates in place. If
|
||||
* instead you want a new geometry, first `clone()` this geometry.
|
||||
* @abstract
|
||||
* @param {number} deltaX Delta X.
|
||||
* @param {number} deltaY Delta Y.
|
||||
*/
|
||||
translate(deltaX, deltaY) {}
|
||||
|
||||
/**
|
||||
* Transform each coordinate of the geometry from one coordinate reference
|
||||
* system to another. The geometry is modified in place.
|
||||
* For example, a line will be transformed to a line and a circle to a circle.
|
||||
* If you do not want the geometry modified in place, first `clone()` it and
|
||||
* then use this function on the clone.
|
||||
*
|
||||
* @param {module:ol/proj~ProjectionLike} source The current projection. Can be a
|
||||
* string identifier or a {@link module:ol/proj/Projection~Projection} object.
|
||||
* @param {module:ol/proj~ProjectionLike} destination The desired projection. Can be a
|
||||
* string identifier or a {@link module:ol/proj/Projection~Projection} object.
|
||||
* @return {module:ol/geom/Geometry} This geometry. Note that original geometry is
|
||||
* modified in place.
|
||||
* @api
|
||||
*/
|
||||
transform(source, destination) {
|
||||
source = getProjection(source);
|
||||
const transformFn = source.getUnits() == Units.TILE_PIXELS ?
|
||||
function(inCoordinates, outCoordinates, stride) {
|
||||
const pixelExtent = source.getExtent();
|
||||
const projectedExtent = source.getWorldExtent();
|
||||
const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
|
||||
composeTransform(tmpTransform,
|
||||
projectedExtent[0], projectedExtent[3],
|
||||
scale, -scale, 0,
|
||||
0, 0);
|
||||
transform2D(inCoordinates, 0, inCoordinates.length, stride,
|
||||
tmpTransform, outCoordinates);
|
||||
return getTransform(source, destination)(inCoordinates, outCoordinates, stride);
|
||||
} :
|
||||
getTransform(source, destination);
|
||||
this.applyTransform(transformFn);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Geometry, BaseObject);
|
||||
|
||||
@@ -70,61 +254,6 @@ inherits(Geometry, BaseObject);
|
||||
const tmpTransform = createTransform();
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @abstract
|
||||
* @return {!module:ol/geom/Geometry} Clone.
|
||||
*/
|
||||
Geometry.prototype.clone = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @param {module:ol/coordinate~Coordinate} closestPoint Closest point.
|
||||
* @param {number} minSquaredDistance Minimum squared distance.
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
Geometry.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {};
|
||||
|
||||
|
||||
/**
|
||||
* Return the closest point of the geometry to the passed point as
|
||||
* {@link module:ol/coordinate~Coordinate coordinate}.
|
||||
* @param {module:ol/coordinate~Coordinate} point Point.
|
||||
* @param {module:ol/coordinate~Coordinate=} opt_closestPoint Closest point.
|
||||
* @return {module:ol/coordinate~Coordinate} Closest point.
|
||||
* @api
|
||||
*/
|
||||
Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) {
|
||||
const closestPoint = opt_closestPoint ? opt_closestPoint : [NaN, NaN];
|
||||
this.closestPointXY(point[0], point[1], closestPoint, Infinity);
|
||||
return closestPoint;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this geometry includes the specified coordinate. If the
|
||||
* coordinate is on the boundary of the geometry, returns false.
|
||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||
* @return {boolean} Contains coordinate.
|
||||
* @api
|
||||
*/
|
||||
Geometry.prototype.intersectsCoordinate = function(coordinate) {
|
||||
return this.containsXY(coordinate[0], coordinate[1]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/extent~Extent} extent Extent.
|
||||
* @protected
|
||||
* @return {module:ol/extent~Extent} extent Extent.
|
||||
*/
|
||||
Geometry.prototype.computeExtent = function(extent) {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
@@ -133,144 +262,4 @@ Geometry.prototype.computeExtent = function(extent) {};
|
||||
Geometry.prototype.containsXY = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* Get the extent of the geometry.
|
||||
* @param {module:ol/extent~Extent=} opt_extent Extent.
|
||||
* @return {module:ol/extent~Extent} extent Extent.
|
||||
* @api
|
||||
*/
|
||||
Geometry.prototype.getExtent = function(opt_extent) {
|
||||
if (this.extentRevision_ != this.getRevision()) {
|
||||
this.extent_ = this.computeExtent(this.extent_);
|
||||
this.extentRevision_ = this.getRevision();
|
||||
}
|
||||
return returnOrUpdate(this.extent_, opt_extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Rotate the geometry around a given coordinate. This modifies the geometry
|
||||
* coordinates in place.
|
||||
* @abstract
|
||||
* @param {number} angle Rotation angle in radians.
|
||||
* @param {module:ol/coordinate~Coordinate} anchor The rotation center.
|
||||
* @api
|
||||
*/
|
||||
Geometry.prototype.rotate = function(angle, anchor) {};
|
||||
|
||||
|
||||
/**
|
||||
* Scale the geometry (with an optional origin). This modifies the geometry
|
||||
* coordinates in place.
|
||||
* @abstract
|
||||
* @param {number} sx The scaling factor in the x-direction.
|
||||
* @param {number=} opt_sy The scaling factor in the y-direction (defaults to
|
||||
* sx).
|
||||
* @param {module:ol/coordinate~Coordinate=} opt_anchor The scale origin (defaults to the center
|
||||
* of the geometry extent).
|
||||
* @api
|
||||
*/
|
||||
Geometry.prototype.scale = function(sx, opt_sy, opt_anchor) {};
|
||||
|
||||
|
||||
/**
|
||||
* Create a simplified version of this geometry. For linestrings, this uses
|
||||
* the the {@link
|
||||
* https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
|
||||
* Douglas Peucker} algorithm. For polygons, a quantization-based
|
||||
* simplification is used to preserve topology.
|
||||
* @function
|
||||
* @param {number} tolerance The tolerance distance for simplification.
|
||||
* @return {module:ol/geom/Geometry} A new, simplified version of the original
|
||||
* geometry.
|
||||
* @api
|
||||
*/
|
||||
Geometry.prototype.simplify = function(tolerance) {
|
||||
return this.getSimplifiedGeometry(tolerance * tolerance);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a simplified version of this geometry using the Douglas Peucker
|
||||
* algorithm.
|
||||
* @see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
|
||||
* @abstract
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {module:ol/geom/Geometry} Simplified geometry.
|
||||
*/
|
||||
Geometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {};
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of this geometry.
|
||||
* @abstract
|
||||
* @return {module:ol/geom/GeometryType} Geometry type.
|
||||
*/
|
||||
Geometry.prototype.getType = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Apply a transform function to each coordinate of the geometry.
|
||||
* The geometry is modified in place.
|
||||
* If you do not want the geometry modified in place, first `clone()` it and
|
||||
* then use this function on the clone.
|
||||
* @abstract
|
||||
* @param {module:ol/proj~TransformFunction} transformFn Transform.
|
||||
*/
|
||||
Geometry.prototype.applyTransform = function(transformFn) {};
|
||||
|
||||
|
||||
/**
|
||||
* Test if the geometry and the passed extent intersect.
|
||||
* @abstract
|
||||
* @param {module:ol/extent~Extent} extent Extent.
|
||||
* @return {boolean} `true` if the geometry and the extent intersect.
|
||||
*/
|
||||
Geometry.prototype.intersectsExtent = function(extent) {};
|
||||
|
||||
|
||||
/**
|
||||
* Translate the geometry. This modifies the geometry coordinates in place. If
|
||||
* instead you want a new geometry, first `clone()` this geometry.
|
||||
* @abstract
|
||||
* @param {number} deltaX Delta X.
|
||||
* @param {number} deltaY Delta Y.
|
||||
*/
|
||||
Geometry.prototype.translate = function(deltaX, deltaY) {};
|
||||
|
||||
|
||||
/**
|
||||
* Transform each coordinate of the geometry from one coordinate reference
|
||||
* system to another. The geometry is modified in place.
|
||||
* For example, a line will be transformed to a line and a circle to a circle.
|
||||
* If you do not want the geometry modified in place, first `clone()` it and
|
||||
* then use this function on the clone.
|
||||
*
|
||||
* @param {module:ol/proj~ProjectionLike} source The current projection. Can be a
|
||||
* string identifier or a {@link module:ol/proj/Projection~Projection} object.
|
||||
* @param {module:ol/proj~ProjectionLike} destination The desired projection. Can be a
|
||||
* string identifier or a {@link module:ol/proj/Projection~Projection} object.
|
||||
* @return {module:ol/geom/Geometry} This geometry. Note that original geometry is
|
||||
* modified in place.
|
||||
* @api
|
||||
*/
|
||||
Geometry.prototype.transform = function(source, destination) {
|
||||
source = getProjection(source);
|
||||
const transformFn = source.getUnits() == Units.TILE_PIXELS ?
|
||||
function(inCoordinates, outCoordinates, stride) {
|
||||
const pixelExtent = source.getExtent();
|
||||
const projectedExtent = source.getWorldExtent();
|
||||
const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
|
||||
composeTransform(tmpTransform,
|
||||
projectedExtent[0], projectedExtent[3],
|
||||
scale, -scale, 0,
|
||||
0, 0);
|
||||
transform2D(inCoordinates, 0, inCoordinates.length, stride,
|
||||
tmpTransform, outCoordinates);
|
||||
return getTransform(source, destination)(inCoordinates, outCoordinates, stride);
|
||||
} :
|
||||
getTransform(source, destination);
|
||||
this.applyTransform(transformFn);
|
||||
return this;
|
||||
};
|
||||
export default Geometry;
|
||||
|
||||
+256
-271
@@ -18,18 +18,268 @@ import {clear} from '../obj.js';
|
||||
* @param {Array.<module:ol/geom/Geometry>=} opt_geometries Geometries.
|
||||
* @api
|
||||
*/
|
||||
const GeometryCollection = function(opt_geometries) {
|
||||
class GeometryCollection {
|
||||
constructor(opt_geometries) {
|
||||
|
||||
Geometry.call(this);
|
||||
Geometry.call(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<module:ol/geom/Geometry>}
|
||||
*/
|
||||
this.geometries_ = opt_geometries ? opt_geometries : null;
|
||||
|
||||
this.listenGeometriesChange_();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<module:ol/geom/Geometry>}
|
||||
*/
|
||||
this.geometries_ = opt_geometries ? opt_geometries : null;
|
||||
unlistenGeometriesChange_() {
|
||||
if (!this.geometries_) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0, ii = this.geometries_.length; i < ii; ++i) {
|
||||
unlisten(
|
||||
this.geometries_[i], EventType.CHANGE,
|
||||
this.changed, this);
|
||||
}
|
||||
}
|
||||
|
||||
this.listenGeometriesChange_();
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
listenGeometriesChange_() {
|
||||
if (!this.geometries_) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0, ii = this.geometries_.length; i < ii; ++i) {
|
||||
listen(
|
||||
this.geometries_[i], EventType.CHANGE,
|
||||
this.changed, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/GeometryCollection} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const geometryCollection = new GeometryCollection(null);
|
||||
geometryCollection.setGeometries(this.geometries_);
|
||||
return geometryCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
minSquaredDistance = geometries[i].closestPointXY(
|
||||
x, y, closestPoint, minSquaredDistance);
|
||||
}
|
||||
return minSquaredDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
containsXY(x, y) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
if (geometries[i].containsXY(x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
computeExtent(extent) {
|
||||
createOrUpdateEmpty(extent);
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
extend(extent, geometries[i].getExtent());
|
||||
}
|
||||
return extent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the geometries that make up this geometry collection.
|
||||
* @return {Array.<module:ol/geom/Geometry>} Geometries.
|
||||
* @api
|
||||
*/
|
||||
getGeometries() {
|
||||
return cloneGeometries(this.geometries_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<module:ol/geom/Geometry>} Geometries.
|
||||
*/
|
||||
getGeometriesArray() {
|
||||
return this.geometries_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSimplifiedGeometry(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.getRevision()) {
|
||||
clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance < this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||
return this;
|
||||
}
|
||||
const key = squaredTolerance.toString();
|
||||
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||
return this.simplifiedGeometryCache[key];
|
||||
} else {
|
||||
const simplifiedGeometries = [];
|
||||
const geometries = this.geometries_;
|
||||
let simplified = false;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
const geometry = geometries[i];
|
||||
const simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);
|
||||
simplifiedGeometries.push(simplifiedGeometry);
|
||||
if (simplifiedGeometry !== geometry) {
|
||||
simplified = true;
|
||||
}
|
||||
}
|
||||
if (simplified) {
|
||||
const simplifiedGeometryCollection = new GeometryCollection(null);
|
||||
simplifiedGeometryCollection.setGeometriesArray(simplifiedGeometries);
|
||||
this.simplifiedGeometryCache[key] = simplifiedGeometryCollection;
|
||||
return simplifiedGeometryCollection;
|
||||
} else {
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.GEOMETRY_COLLECTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
if (geometries[i].intersectsExtent(extent)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean} Is empty.
|
||||
*/
|
||||
isEmpty() {
|
||||
return this.geometries_.length === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
rotate(angle, anchor) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].rotate(angle, anchor);
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
scale(sx, opt_sy, opt_anchor) {
|
||||
let anchor = opt_anchor;
|
||||
if (!anchor) {
|
||||
anchor = getCenter(this.getExtent());
|
||||
}
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].scale(sx, opt_sy, anchor);
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the geometries that make up this geometry collection.
|
||||
* @param {Array.<module:ol/geom/Geometry>} geometries Geometries.
|
||||
* @api
|
||||
*/
|
||||
setGeometries(geometries) {
|
||||
this.setGeometriesArray(cloneGeometries(geometries));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array.<module:ol/geom/Geometry>} geometries Geometries.
|
||||
*/
|
||||
setGeometriesArray(geometries) {
|
||||
this.unlistenGeometriesChange_();
|
||||
this.geometries_ = geometries;
|
||||
this.listenGeometriesChange_();
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
applyTransform(transformFn) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].applyTransform(transformFn);
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the geometry.
|
||||
* @param {number} deltaX Delta X.
|
||||
* @param {number} deltaY Delta Y.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
translate(deltaX, deltaY) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].translate(deltaX, deltaY);
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
disposeInternal() {
|
||||
this.unlistenGeometriesChange_();
|
||||
Geometry.prototype.disposeInternal.call(this);
|
||||
}
|
||||
}
|
||||
|
||||
inherits(GeometryCollection, Geometry);
|
||||
|
||||
@@ -47,269 +297,4 @@ function cloneGeometries(geometries) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
GeometryCollection.prototype.unlistenGeometriesChange_ = function() {
|
||||
if (!this.geometries_) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0, ii = this.geometries_.length; i < ii; ++i) {
|
||||
unlisten(
|
||||
this.geometries_[i], EventType.CHANGE,
|
||||
this.changed, this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
GeometryCollection.prototype.listenGeometriesChange_ = function() {
|
||||
if (!this.geometries_) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0, ii = this.geometries_.length; i < ii; ++i) {
|
||||
listen(
|
||||
this.geometries_[i], EventType.CHANGE,
|
||||
this.changed, this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/GeometryCollection} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.clone = function() {
|
||||
const geometryCollection = new GeometryCollection(null);
|
||||
geometryCollection.setGeometries(this.geometries_);
|
||||
return geometryCollection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeometryCollection.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
minSquaredDistance = geometries[i].closestPointXY(
|
||||
x, y, closestPoint, minSquaredDistance);
|
||||
}
|
||||
return minSquaredDistance;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeometryCollection.prototype.containsXY = function(x, y) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
if (geometries[i].containsXY(x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeometryCollection.prototype.computeExtent = function(extent) {
|
||||
createOrUpdateEmpty(extent);
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
extend(extent, geometries[i].getExtent());
|
||||
}
|
||||
return extent;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the geometries that make up this geometry collection.
|
||||
* @return {Array.<module:ol/geom/Geometry>} Geometries.
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.getGeometries = function() {
|
||||
return cloneGeometries(this.geometries_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<module:ol/geom/Geometry>} Geometries.
|
||||
*/
|
||||
GeometryCollection.prototype.getGeometriesArray = function() {
|
||||
return this.geometries_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeometryCollection.prototype.getSimplifiedGeometry = function(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.getRevision()) {
|
||||
clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance < this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||
return this;
|
||||
}
|
||||
const key = squaredTolerance.toString();
|
||||
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||
return this.simplifiedGeometryCache[key];
|
||||
} else {
|
||||
const simplifiedGeometries = [];
|
||||
const geometries = this.geometries_;
|
||||
let simplified = false;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
const geometry = geometries[i];
|
||||
const simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);
|
||||
simplifiedGeometries.push(simplifiedGeometry);
|
||||
if (simplifiedGeometry !== geometry) {
|
||||
simplified = true;
|
||||
}
|
||||
}
|
||||
if (simplified) {
|
||||
const simplifiedGeometryCollection = new GeometryCollection(null);
|
||||
simplifiedGeometryCollection.setGeometriesArray(simplifiedGeometries);
|
||||
this.simplifiedGeometryCache[key] = simplifiedGeometryCollection;
|
||||
return simplifiedGeometryCollection;
|
||||
} else {
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.getType = function() {
|
||||
return GeometryType.GEOMETRY_COLLECTION;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.intersectsExtent = function(extent) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
if (geometries[i].intersectsExtent(extent)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Is empty.
|
||||
*/
|
||||
GeometryCollection.prototype.isEmpty = function() {
|
||||
return this.geometries_.length === 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.rotate = function(angle, anchor) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].rotate(angle, anchor);
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.scale = function(sx, opt_sy, opt_anchor) {
|
||||
let anchor = opt_anchor;
|
||||
if (!anchor) {
|
||||
anchor = getCenter(this.getExtent());
|
||||
}
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].scale(sx, opt_sy, anchor);
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the geometries that make up this geometry collection.
|
||||
* @param {Array.<module:ol/geom/Geometry>} geometries Geometries.
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.setGeometries = function(geometries) {
|
||||
this.setGeometriesArray(cloneGeometries(geometries));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<module:ol/geom/Geometry>} geometries Geometries.
|
||||
*/
|
||||
GeometryCollection.prototype.setGeometriesArray = function(geometries) {
|
||||
this.unlistenGeometriesChange_();
|
||||
this.geometries_ = geometries;
|
||||
this.listenGeometriesChange_();
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.applyTransform = function(transformFn) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].applyTransform(transformFn);
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Translate the geometry.
|
||||
* @param {number} deltaX Delta X.
|
||||
* @param {number} deltaY Delta Y.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
GeometryCollection.prototype.translate = function(deltaX, deltaY) {
|
||||
const geometries = this.geometries_;
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
geometries[i].translate(deltaX, deltaY);
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeometryCollection.prototype.disposeInternal = function() {
|
||||
this.unlistenGeometriesChange_();
|
||||
Geometry.prototype.disposeInternal.call(this);
|
||||
};
|
||||
export default GeometryCollection;
|
||||
|
||||
+203
-213
@@ -28,229 +28,219 @@ import {douglasPeucker} from '../geom/flat/simplify.js';
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @api
|
||||
*/
|
||||
const LineString = function(coordinates, opt_layout) {
|
||||
class LineString {
|
||||
constructor(coordinates, opt_layout) {
|
||||
|
||||
SimpleGeometry.call(this);
|
||||
SimpleGeometry.call(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/coordinate~Coordinate}
|
||||
*/
|
||||
this.flatMidpoint_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/coordinate~Coordinate}
|
||||
*/
|
||||
this.flatMidpoint_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.flatMidpointRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.flatMidpointRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Append the passed coordinate to the coordinates of the linestring.
|
||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||
* @api
|
||||
*/
|
||||
appendCoordinate(coordinate) {
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = coordinate.slice();
|
||||
} else {
|
||||
extend(this.flatCoordinates, coordinate);
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/LineString} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new LineString(this.flatCoordinates.slice(), this.layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(maxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestPoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over each segment, calling the provided callback.
|
||||
* If the callback returns a truthy value the function returns that
|
||||
* value immediately. Otherwise the function returns `false`.
|
||||
*
|
||||
* @param {function(this: S, module:ol/coordinate~Coordinate, module:ol/coordinate~Coordinate): T} callback Function
|
||||
* called for each segment.
|
||||
* @return {T|boolean} Value.
|
||||
* @template T,S
|
||||
* @api
|
||||
*/
|
||||
forEachSegment(callback) {
|
||||
return forEachSegment(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the coordinate at `m` using linear interpolation, or `null` if no
|
||||
* such coordinate exists.
|
||||
*
|
||||
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the
|
||||
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
|
||||
* M will return the first coordinate and Ms greater than the last M will
|
||||
* return the last coordinate.
|
||||
*
|
||||
* @param {number} m M.
|
||||
* @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
|
||||
* @return {module:ol/coordinate~Coordinate} Coordinate.
|
||||
* @api
|
||||
*/
|
||||
getCoordinateAtM(m, opt_extrapolate) {
|
||||
if (this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM) {
|
||||
return null;
|
||||
}
|
||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||
return lineStringCoordinateAtM(this.flatCoordinates, 0,
|
||||
this.flatCoordinates.length, this.stride, m, extrapolate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the coordinates of the linestring.
|
||||
* @return {Array.<module:ol/coordinate~Coordinate>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
getCoordinates() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the coordinate at the provided fraction along the linestring.
|
||||
* The `fraction` is a number between 0 and 1, where 0 is the start of the
|
||||
* linestring and 1 is the end.
|
||||
* @param {number} fraction Fraction.
|
||||
* @param {module:ol/coordinate~Coordinate=} opt_dest Optional coordinate whose values will
|
||||
* be modified. If not provided, a new coordinate will be returned.
|
||||
* @return {module:ol/coordinate~Coordinate} Coordinate of the interpolated point.
|
||||
* @api
|
||||
*/
|
||||
getCoordinateAt(fraction, opt_dest) {
|
||||
return interpolatePoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
fraction, opt_dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the length of the linestring on projected plane.
|
||||
* @return {number} Length (on projected plane).
|
||||
* @api
|
||||
*/
|
||||
getLength() {
|
||||
return lineStringLength(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat midpoint.
|
||||
*/
|
||||
getFlatMidpoint() {
|
||||
if (this.flatMidpointRevision_ != this.getRevision()) {
|
||||
this.flatMidpoint_ = this.getCoordinateAt(0.5, this.flatMidpoint_);
|
||||
this.flatMidpointRevision_ = this.getRevision();
|
||||
}
|
||||
return this.flatMidpoint_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||
return new LineString(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.LINE_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return intersectsLineString(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the coordinates of the linestring.
|
||||
* @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(LineString, SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* Append the passed coordinate to the coordinates of the linestring.
|
||||
* @param {module:ol/coordinate~Coordinate} coordinate Coordinate.
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.appendCoordinate = function(coordinate) {
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = coordinate.slice();
|
||||
} else {
|
||||
extend(this.flatCoordinates, coordinate);
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/LineString} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.clone = function() {
|
||||
return new LineString(this.flatCoordinates.slice(), this.layout);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
LineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(maxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestPoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Iterate over each segment, calling the provided callback.
|
||||
* If the callback returns a truthy value the function returns that
|
||||
* value immediately. Otherwise the function returns `false`.
|
||||
*
|
||||
* @param {function(this: S, module:ol/coordinate~Coordinate, module:ol/coordinate~Coordinate): T} callback Function
|
||||
* called for each segment.
|
||||
* @return {T|boolean} Value.
|
||||
* @template T,S
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.forEachSegment = function(callback) {
|
||||
return forEachSegment(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, callback);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the coordinate at `m` using linear interpolation, or `null` if no
|
||||
* such coordinate exists.
|
||||
*
|
||||
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the
|
||||
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
|
||||
* M will return the first coordinate and Ms greater than the last M will
|
||||
* return the last coordinate.
|
||||
*
|
||||
* @param {number} m M.
|
||||
* @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
|
||||
* @return {module:ol/coordinate~Coordinate} Coordinate.
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.getCoordinateAtM = function(m, opt_extrapolate) {
|
||||
if (this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM) {
|
||||
return null;
|
||||
}
|
||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||
return lineStringCoordinateAtM(this.flatCoordinates, 0,
|
||||
this.flatCoordinates.length, this.stride, m, extrapolate);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the coordinates of the linestring.
|
||||
* @return {Array.<module:ol/coordinate~Coordinate>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.getCoordinates = function() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the coordinate at the provided fraction along the linestring.
|
||||
* The `fraction` is a number between 0 and 1, where 0 is the start of the
|
||||
* linestring and 1 is the end.
|
||||
* @param {number} fraction Fraction.
|
||||
* @param {module:ol/coordinate~Coordinate=} opt_dest Optional coordinate whose values will
|
||||
* be modified. If not provided, a new coordinate will be returned.
|
||||
* @return {module:ol/coordinate~Coordinate} Coordinate of the interpolated point.
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.getCoordinateAt = function(fraction, opt_dest) {
|
||||
return interpolatePoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
fraction, opt_dest);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the length of the linestring on projected plane.
|
||||
* @return {number} Length (on projected plane).
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.getLength = function() {
|
||||
return lineStringLength(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat midpoint.
|
||||
*/
|
||||
LineString.prototype.getFlatMidpoint = function() {
|
||||
if (this.flatMidpointRevision_ != this.getRevision()) {
|
||||
this.flatMidpoint_ = this.getCoordinateAt(0.5, this.flatMidpoint_);
|
||||
this.flatMidpointRevision_ = this.getRevision();
|
||||
}
|
||||
return this.flatMidpoint_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
LineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||
return new LineString(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.getType = function() {
|
||||
return GeometryType.LINE_STRING;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.intersectsExtent = function(extent) {
|
||||
return intersectsLineString(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the coordinates of the linestring.
|
||||
* @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
LineString.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
export default LineString;
|
||||
|
||||
+107
-111
@@ -25,125 +25,121 @@ import {douglasPeucker} from '../geom/flat/simplify.js';
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @api
|
||||
*/
|
||||
const LinearRing = function(coordinates, opt_layout) {
|
||||
class LinearRing {
|
||||
constructor(coordinates, opt_layout) {
|
||||
|
||||
SimpleGeometry.call(this);
|
||||
SimpleGeometry.call(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/LinearRing} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new LinearRing(this.flatCoordinates.slice(), this.layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(maxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestPoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the area of the linear ring on projected plane.
|
||||
* @return {number} Area (on projected plane).
|
||||
* @api
|
||||
*/
|
||||
getArea() {
|
||||
return linearRingArea(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the coordinates of the linear ring.
|
||||
* @return {Array.<module:ol/coordinate~Coordinate>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
getCoordinates() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||
return new LinearRing(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.LINEAR_RING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
intersectsExtent(extent) {}
|
||||
|
||||
/**
|
||||
* Set the coordinates of the linear ring.
|
||||
* @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(LinearRing, SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/LinearRing} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
LinearRing.prototype.clone = function() {
|
||||
return new LinearRing(this.flatCoordinates.slice(), this.layout);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
LinearRing.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(maxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestPoint(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the area of the linear ring on projected plane.
|
||||
* @return {number} Area (on projected plane).
|
||||
* @api
|
||||
*/
|
||||
LinearRing.prototype.getArea = function() {
|
||||
return linearRingArea(this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the coordinates of the linear ring.
|
||||
* @return {Array.<module:ol/coordinate~Coordinate>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
LinearRing.prototype.getCoordinates = function() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeucker(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
|
||||
squaredTolerance, simplifiedFlatCoordinates, 0);
|
||||
return new LinearRing(simplifiedFlatCoordinates, GeometryLayout.XY);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
LinearRing.prototype.getType = function() {
|
||||
return GeometryType.LINEAR_RING;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
LinearRing.prototype.intersectsExtent = function(extent) {};
|
||||
|
||||
|
||||
/**
|
||||
* Set the coordinates of the linear ring.
|
||||
* @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) {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
};
|
||||
export default LinearRing;
|
||||
|
||||
+232
-241
@@ -28,258 +28,249 @@ import {douglasPeuckerArray} from '../geom/flat/simplify.js';
|
||||
* @param {Array.<number>} opt_ends Flat coordinate ends for internal use.
|
||||
* @api
|
||||
*/
|
||||
const MultiLineString = function(coordinates, opt_layout, opt_ends) {
|
||||
class MultiLineString {
|
||||
constructor(coordinates, opt_layout, opt_ends) {
|
||||
|
||||
SimpleGeometry.call(this);
|
||||
SimpleGeometry.call(this);
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @private
|
||||
*/
|
||||
this.ends_ = [];
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @private
|
||||
*/
|
||||
this.ends_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
if (Array.isArray(coordinates[0])) {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
} else if (opt_layout !== undefined && opt_ends) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
this.ends_ = opt_ends;
|
||||
} else {
|
||||
let layout = this.getLayout();
|
||||
const flatCoordinates = [];
|
||||
const ends = [];
|
||||
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
const lineString = coordinates[i];
|
||||
if (i === 0) {
|
||||
layout = lineString.getLayout();
|
||||
if (Array.isArray(coordinates[0])) {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
} else if (opt_layout !== undefined && opt_ends) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
this.ends_ = opt_ends;
|
||||
} else {
|
||||
let layout = this.getLayout();
|
||||
const flatCoordinates = [];
|
||||
const ends = [];
|
||||
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
const lineString = coordinates[i];
|
||||
if (i === 0) {
|
||||
layout = lineString.getLayout();
|
||||
}
|
||||
extend(flatCoordinates, lineString.getFlatCoordinates());
|
||||
ends.push(flatCoordinates.length);
|
||||
}
|
||||
extend(flatCoordinates, lineString.getFlatCoordinates());
|
||||
ends.push(flatCoordinates.length);
|
||||
this.setFlatCoordinates(layout, flatCoordinates);
|
||||
this.ends_ = ends;
|
||||
}
|
||||
this.setFlatCoordinates(layout, flatCoordinates);
|
||||
this.ends_ = ends;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Append the passed linestring to the multilinestring.
|
||||
* @param {module:ol/geom/LineString} lineString LineString.
|
||||
* @api
|
||||
*/
|
||||
appendLineString(lineString) {
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = lineString.getFlatCoordinates().slice();
|
||||
} else {
|
||||
extend(this.flatCoordinates, lineString.getFlatCoordinates().slice());
|
||||
}
|
||||
this.ends_.push(this.flatCoordinates.length);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/MultiLineString} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new MultiLineString(this.flatCoordinates.slice(), this.layout, this.ends_.slice());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestArrayPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the coordinate at `m` using linear interpolation, or `null` if no
|
||||
* such coordinate exists.
|
||||
*
|
||||
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the
|
||||
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
|
||||
* M will return the first coordinate and Ms greater than the last M will
|
||||
* return the last coordinate.
|
||||
*
|
||||
* `opt_interpolate` controls interpolation between consecutive LineStrings
|
||||
* within the MultiLineString. If `opt_interpolate` is `true` the coordinates
|
||||
* will be linearly interpolated between the last coordinate of one LineString
|
||||
* and the first coordinate of the next LineString. If `opt_interpolate` is
|
||||
* `false` then the function will return `null` for Ms falling between
|
||||
* LineStrings.
|
||||
*
|
||||
* @param {number} m M.
|
||||
* @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
|
||||
* @param {boolean=} opt_interpolate Interpolate. Default is `false`.
|
||||
* @return {module:ol/coordinate~Coordinate} Coordinate.
|
||||
* @api
|
||||
*/
|
||||
getCoordinateAtM(m, opt_extrapolate, opt_interpolate) {
|
||||
if ((this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM) ||
|
||||
this.flatCoordinates.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||
const interpolate = opt_interpolate !== undefined ? opt_interpolate : false;
|
||||
return lineStringsCoordinateAtM(this.flatCoordinates, 0,
|
||||
this.ends_, this.stride, m, extrapolate, interpolate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the coordinates of the multilinestring.
|
||||
* @return {Array.<Array.<module:ol/coordinate~Coordinate>>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
getCoordinates() {
|
||||
return inflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Ends.
|
||||
*/
|
||||
getEnds() {
|
||||
return this.ends_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the linestring at the specified index.
|
||||
* @param {number} index Index.
|
||||
* @return {module:ol/geom/LineString} LineString.
|
||||
* @api
|
||||
*/
|
||||
getLineString(index) {
|
||||
if (index < 0 || this.ends_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
return new LineString(this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the linestrings of this multilinestring.
|
||||
* @return {Array.<module:ol/geom/LineString>} LineStrings.
|
||||
* @api
|
||||
*/
|
||||
getLineStrings() {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const ends = this.ends_;
|
||||
const layout = this.layout;
|
||||
/** @type {Array.<module:ol/geom/LineString>} */
|
||||
const lineStrings = [];
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const lineString = new LineString(flatCoordinates.slice(offset, end), layout);
|
||||
lineStrings.push(lineString);
|
||||
offset = end;
|
||||
}
|
||||
return lineStrings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat midpoints.
|
||||
*/
|
||||
getFlatMidpoints() {
|
||||
const midpoints = [];
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
let offset = 0;
|
||||
const ends = this.ends_;
|
||||
const stride = this.stride;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const midpoint = interpolatePoint(
|
||||
flatCoordinates, offset, end, stride, 0.5);
|
||||
extend(midpoints, midpoint);
|
||||
offset = end;
|
||||
}
|
||||
return midpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeuckerArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
||||
return new MultiLineString(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEnds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.MULTI_LINE_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return intersectsLineStringArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the coordinates of the multilinestring.
|
||||
* @param {!Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const ends = deflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(MultiLineString, SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* Append the passed linestring to the multilinestring.
|
||||
* @param {module:ol/geom/LineString} lineString LineString.
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.appendLineString = function(lineString) {
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = lineString.getFlatCoordinates().slice();
|
||||
} else {
|
||||
extend(this.flatCoordinates, lineString.getFlatCoordinates().slice());
|
||||
}
|
||||
this.ends_.push(this.flatCoordinates.length);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/MultiLineString} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.clone = function() {
|
||||
return new MultiLineString(this.flatCoordinates.slice(), this.layout, this.ends_.slice());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
MultiLineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestArrayPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the coordinate at `m` using linear interpolation, or `null` if no
|
||||
* such coordinate exists.
|
||||
*
|
||||
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the
|
||||
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
|
||||
* M will return the first coordinate and Ms greater than the last M will
|
||||
* return the last coordinate.
|
||||
*
|
||||
* `opt_interpolate` controls interpolation between consecutive LineStrings
|
||||
* within the MultiLineString. If `opt_interpolate` is `true` the coordinates
|
||||
* will be linearly interpolated between the last coordinate of one LineString
|
||||
* and the first coordinate of the next LineString. If `opt_interpolate` is
|
||||
* `false` then the function will return `null` for Ms falling between
|
||||
* LineStrings.
|
||||
*
|
||||
* @param {number} m M.
|
||||
* @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
|
||||
* @param {boolean=} opt_interpolate Interpolate. Default is `false`.
|
||||
* @return {module:ol/coordinate~Coordinate} Coordinate.
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.getCoordinateAtM = function(m, opt_extrapolate, opt_interpolate) {
|
||||
if ((this.layout != GeometryLayout.XYM &&
|
||||
this.layout != GeometryLayout.XYZM) ||
|
||||
this.flatCoordinates.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
|
||||
const interpolate = opt_interpolate !== undefined ? opt_interpolate : false;
|
||||
return lineStringsCoordinateAtM(this.flatCoordinates, 0,
|
||||
this.ends_, this.stride, m, extrapolate, interpolate);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the coordinates of the multilinestring.
|
||||
* @return {Array.<Array.<module:ol/coordinate~Coordinate>>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.getCoordinates = function() {
|
||||
return inflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Ends.
|
||||
*/
|
||||
MultiLineString.prototype.getEnds = function() {
|
||||
return this.ends_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the linestring at the specified index.
|
||||
* @param {number} index Index.
|
||||
* @return {module:ol/geom/LineString} LineString.
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.getLineString = function(index) {
|
||||
if (index < 0 || this.ends_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
return new LineString(this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the linestrings of this multilinestring.
|
||||
* @return {Array.<module:ol/geom/LineString>} LineStrings.
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.getLineStrings = function() {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const ends = this.ends_;
|
||||
const layout = this.layout;
|
||||
/** @type {Array.<module:ol/geom/LineString>} */
|
||||
const lineStrings = [];
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const lineString = new LineString(flatCoordinates.slice(offset, end), layout);
|
||||
lineStrings.push(lineString);
|
||||
offset = end;
|
||||
}
|
||||
return lineStrings;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat midpoints.
|
||||
*/
|
||||
MultiLineString.prototype.getFlatMidpoints = function() {
|
||||
const midpoints = [];
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
let offset = 0;
|
||||
const ends = this.ends_;
|
||||
const stride = this.stride;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const midpoint = interpolatePoint(
|
||||
flatCoordinates, offset, end, stride, 0.5);
|
||||
extend(midpoints, midpoint);
|
||||
offset = end;
|
||||
}
|
||||
return midpoints;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedFlatCoordinates.length = douglasPeuckerArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance,
|
||||
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
||||
return new MultiLineString(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEnds);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.getType = function() {
|
||||
return GeometryType.MULTI_LINE_STRING;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.intersectsExtent = function(extent) {
|
||||
return intersectsLineStringArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the coordinates of the multilinestring.
|
||||
* @param {!Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiLineString.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const ends = deflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
this.changed();
|
||||
};
|
||||
export default MultiLineString;
|
||||
|
||||
+143
-148
@@ -23,157 +23,152 @@ import {squaredDistance as squaredDx} from '../math.js';
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @api
|
||||
*/
|
||||
const MultiPoint = function(coordinates, opt_layout) {
|
||||
SimpleGeometry.call(this);
|
||||
if (opt_layout && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
class MultiPoint {
|
||||
constructor(coordinates, opt_layout) {
|
||||
SimpleGeometry.call(this);
|
||||
if (opt_layout && !Array.isArray(coordinates[0])) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Append the passed point to this multipoint.
|
||||
* @param {module:ol/geom/Point} point Point.
|
||||
* @api
|
||||
*/
|
||||
appendPoint(point) {
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = point.getFlatCoordinates().slice();
|
||||
} else {
|
||||
extend(this.flatCoordinates, point.getFlatCoordinates());
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/MultiPoint} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const multiPoint = new MultiPoint(this.flatCoordinates.slice(), this.layout);
|
||||
return multiPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const stride = this.stride;
|
||||
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||
const squaredDistance = squaredDx(
|
||||
x, y, flatCoordinates[i], flatCoordinates[i + 1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
minSquaredDistance = squaredDistance;
|
||||
for (let j = 0; j < stride; ++j) {
|
||||
closestPoint[j] = flatCoordinates[i + j];
|
||||
}
|
||||
closestPoint.length = stride;
|
||||
}
|
||||
}
|
||||
return minSquaredDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the coordinates of the multipoint.
|
||||
* @return {Array.<module:ol/coordinate~Coordinate>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
getCoordinates() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the point at the specified index.
|
||||
* @param {number} index Index.
|
||||
* @return {module:ol/geom/Point} Point.
|
||||
* @api
|
||||
*/
|
||||
getPoint(index) {
|
||||
const n = !this.flatCoordinates ? 0 : this.flatCoordinates.length / this.stride;
|
||||
if (index < 0 || n <= index) {
|
||||
return null;
|
||||
}
|
||||
return new Point(this.flatCoordinates.slice(
|
||||
index * this.stride, (index + 1) * this.stride), this.layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the points of this multipoint.
|
||||
* @return {Array.<module:ol/geom/Point>} Points.
|
||||
* @api
|
||||
*/
|
||||
getPoints() {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const layout = this.layout;
|
||||
const stride = this.stride;
|
||||
/** @type {Array.<module:ol/geom/Point>} */
|
||||
const points = [];
|
||||
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||
const point = new Point(flatCoordinates.slice(i, i + stride), layout);
|
||||
points.push(point);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.MULTI_POINT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const stride = this.stride;
|
||||
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||
const x = flatCoordinates[i];
|
||||
const y = flatCoordinates[i + 1];
|
||||
if (containsXY(extent, x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the coordinates of the multipoint.
|
||||
* @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(MultiPoint, SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* Append the passed point to this multipoint.
|
||||
* @param {module:ol/geom/Point} point Point.
|
||||
* @api
|
||||
*/
|
||||
MultiPoint.prototype.appendPoint = function(point) {
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = point.getFlatCoordinates().slice();
|
||||
} else {
|
||||
extend(this.flatCoordinates, point.getFlatCoordinates());
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/MultiPoint} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiPoint.prototype.clone = function() {
|
||||
const multiPoint = new MultiPoint(this.flatCoordinates.slice(), this.layout);
|
||||
return multiPoint;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
MultiPoint.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const stride = this.stride;
|
||||
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||
const squaredDistance = squaredDx(
|
||||
x, y, flatCoordinates[i], flatCoordinates[i + 1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
minSquaredDistance = squaredDistance;
|
||||
for (let j = 0; j < stride; ++j) {
|
||||
closestPoint[j] = flatCoordinates[i + j];
|
||||
}
|
||||
closestPoint.length = stride;
|
||||
}
|
||||
}
|
||||
return minSquaredDistance;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the coordinates of the multipoint.
|
||||
* @return {Array.<module:ol/coordinate~Coordinate>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiPoint.prototype.getCoordinates = function() {
|
||||
return inflateCoordinates(
|
||||
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the point at the specified index.
|
||||
* @param {number} index Index.
|
||||
* @return {module:ol/geom/Point} Point.
|
||||
* @api
|
||||
*/
|
||||
MultiPoint.prototype.getPoint = function(index) {
|
||||
const n = !this.flatCoordinates ? 0 : this.flatCoordinates.length / this.stride;
|
||||
if (index < 0 || n <= index) {
|
||||
return null;
|
||||
}
|
||||
return new Point(this.flatCoordinates.slice(
|
||||
index * this.stride, (index + 1) * this.stride), this.layout);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the points of this multipoint.
|
||||
* @return {Array.<module:ol/geom/Point>} Points.
|
||||
* @api
|
||||
*/
|
||||
MultiPoint.prototype.getPoints = function() {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const layout = this.layout;
|
||||
const stride = this.stride;
|
||||
/** @type {Array.<module:ol/geom/Point>} */
|
||||
const points = [];
|
||||
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||
const point = new Point(flatCoordinates.slice(i, i + stride), layout);
|
||||
points.push(point);
|
||||
}
|
||||
return points;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MultiPoint.prototype.getType = function() {
|
||||
return GeometryType.MULTI_POINT;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MultiPoint.prototype.intersectsExtent = function(extent) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const stride = this.stride;
|
||||
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||
const x = flatCoordinates[i];
|
||||
const y = flatCoordinates[i + 1];
|
||||
if (containsXY(extent, x, y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the coordinates of the multipoint.
|
||||
* @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiPoint.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
};
|
||||
export default MultiPoint;
|
||||
|
||||
+325
-339
@@ -34,360 +34,346 @@ import {quantizeMultiArray} from '../geom/flat/simplify.js';
|
||||
* coordinates.
|
||||
* @api
|
||||
*/
|
||||
const MultiPolygon = function(coordinates, opt_layout, opt_endss) {
|
||||
class MultiPolygon {
|
||||
constructor(coordinates, opt_layout, opt_endss) {
|
||||
|
||||
SimpleGeometry.call(this);
|
||||
SimpleGeometry.call(this);
|
||||
|
||||
/**
|
||||
* @type {Array.<Array.<number>>}
|
||||
* @private
|
||||
*/
|
||||
this.endss_ = [];
|
||||
/**
|
||||
* @type {Array.<Array.<number>>}
|
||||
* @private
|
||||
*/
|
||||
this.endss_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.flatInteriorPointsRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.flatInteriorPointsRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.flatInteriorPoints_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.flatInteriorPoints_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.orientedRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.orientedRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.orientedFlatCoordinates_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.orientedFlatCoordinates_ = null;
|
||||
|
||||
if (!opt_endss && !Array.isArray(coordinates[0])) {
|
||||
let layout = this.getLayout();
|
||||
const flatCoordinates = [];
|
||||
const endss = [];
|
||||
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
const polygon = coordinates[i];
|
||||
if (i === 0) {
|
||||
layout = polygon.getLayout();
|
||||
if (!opt_endss && !Array.isArray(coordinates[0])) {
|
||||
let layout = this.getLayout();
|
||||
const flatCoordinates = [];
|
||||
const endss = [];
|
||||
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
const polygon = coordinates[i];
|
||||
if (i === 0) {
|
||||
layout = polygon.getLayout();
|
||||
}
|
||||
const offset = flatCoordinates.length;
|
||||
const ends = polygon.getEnds();
|
||||
for (let j = 0, jj = ends.length; j < jj; ++j) {
|
||||
ends[j] += offset;
|
||||
}
|
||||
extend(flatCoordinates, polygon.getFlatCoordinates());
|
||||
endss.push(ends);
|
||||
}
|
||||
const offset = flatCoordinates.length;
|
||||
const ends = polygon.getEnds();
|
||||
for (let j = 0, jj = ends.length; j < jj; ++j) {
|
||||
ends[j] += offset;
|
||||
}
|
||||
extend(flatCoordinates, polygon.getFlatCoordinates());
|
||||
endss.push(ends);
|
||||
opt_layout = layout;
|
||||
coordinates = flatCoordinates;
|
||||
opt_endss = endss;
|
||||
}
|
||||
opt_layout = layout;
|
||||
coordinates = flatCoordinates;
|
||||
opt_endss = endss;
|
||||
}
|
||||
if (opt_layout !== undefined && opt_endss) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
this.endss_ = opt_endss;
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
if (opt_layout !== undefined && opt_endss) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
this.endss_ = opt_endss;
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Append the passed polygon to this multipolygon.
|
||||
* @param {module:ol/geom/Polygon} polygon Polygon.
|
||||
* @api
|
||||
*/
|
||||
appendPolygon(polygon) {
|
||||
/** @type {Array.<number>} */
|
||||
let ends;
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = polygon.getFlatCoordinates().slice();
|
||||
ends = polygon.getEnds().slice();
|
||||
this.endss_.push();
|
||||
} else {
|
||||
const offset = this.flatCoordinates.length;
|
||||
extend(this.flatCoordinates, polygon.getFlatCoordinates());
|
||||
ends = polygon.getEnds().slice();
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
ends[i] += offset;
|
||||
}
|
||||
}
|
||||
this.endss_.push(ends);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/MultiPolygon} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const len = this.endss_.length;
|
||||
const newEndss = new Array(len);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
newEndss[i] = this.endss_[i].slice();
|
||||
}
|
||||
|
||||
return new MultiPolygon(
|
||||
this.flatCoordinates.slice(), this.layout, newEndss);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(multiArrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestMultiArrayPoint(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
containsXY(x, y) {
|
||||
return linearRingssContainsXY(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the area of the multipolygon on projected plane.
|
||||
* @return {number} Area (on projected plane).
|
||||
* @api
|
||||
*/
|
||||
getArea() {
|
||||
return linearRingssArea(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the coordinate array for this geometry. This array has the structure
|
||||
* of a GeoJSON coordinate array for multi-polygons.
|
||||
*
|
||||
* @param {boolean=} opt_right Orient coordinates according to the right-hand
|
||||
* rule (counter-clockwise for exterior and clockwise for interior rings).
|
||||
* If `false`, coordinates will be oriented according to the left-hand rule
|
||||
* (clockwise for exterior and counter-clockwise for interior rings).
|
||||
* By default, coordinate orientation will depend on how the geometry was
|
||||
* constructed.
|
||||
* @return {Array.<Array.<Array.<module:ol/coordinate~Coordinate>>>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
getCoordinates(opt_right) {
|
||||
let flatCoordinates;
|
||||
if (opt_right !== undefined) {
|
||||
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||
orientLinearRingsArray(
|
||||
flatCoordinates, 0, this.endss_, this.stride, opt_right);
|
||||
} else {
|
||||
flatCoordinates = this.flatCoordinates;
|
||||
}
|
||||
|
||||
return inflateMultiCoordinatesArray(
|
||||
flatCoordinates, 0, this.endss_, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<Array.<number>>} Endss.
|
||||
*/
|
||||
getEndss() {
|
||||
return this.endss_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat interior points.
|
||||
*/
|
||||
getFlatInteriorPoints() {
|
||||
if (this.flatInteriorPointsRevision_ != this.getRevision()) {
|
||||
const flatCenters = linearRingssCenter(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
this.flatInteriorPoints_ = getInteriorPointsOfMultiArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
||||
flatCenters);
|
||||
this.flatInteriorPointsRevision_ = this.getRevision();
|
||||
}
|
||||
return this.flatInteriorPoints_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the interior points as {@link module:ol/geom/MultiPoint multipoint}.
|
||||
* @return {module:ol/geom/MultiPoint} Interior points as XYM coordinates, where M is
|
||||
* the length of the horizontal intersection that the point belongs to.
|
||||
* @api
|
||||
*/
|
||||
getInteriorPoints() {
|
||||
return new MultiPoint(this.getFlatInteriorPoints().slice(), GeometryLayout.XYM);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Oriented flat coordinates.
|
||||
*/
|
||||
getOrientedFlatCoordinates() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
if (linearRingsAreOriented(
|
||||
flatCoordinates, 0, this.endss_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length =
|
||||
orientLinearRingsArray(
|
||||
this.orientedFlatCoordinates_, 0, this.endss_, this.stride);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
}
|
||||
return this.orientedFlatCoordinates_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEndss = [];
|
||||
simplifiedFlatCoordinates.length = quantizeMultiArray(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride,
|
||||
Math.sqrt(squaredTolerance),
|
||||
simplifiedFlatCoordinates, 0, simplifiedEndss);
|
||||
return new MultiPolygon(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEndss);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the polygon at the specified index.
|
||||
* @param {number} index Index.
|
||||
* @return {module:ol/geom/Polygon} Polygon.
|
||||
* @api
|
||||
*/
|
||||
getPolygon(index) {
|
||||
if (index < 0 || this.endss_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
let offset;
|
||||
if (index === 0) {
|
||||
offset = 0;
|
||||
} else {
|
||||
const prevEnds = this.endss_[index - 1];
|
||||
offset = prevEnds[prevEnds.length - 1];
|
||||
}
|
||||
const ends = this.endss_[index].slice();
|
||||
const end = ends[ends.length - 1];
|
||||
if (offset !== 0) {
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
ends[i] -= offset;
|
||||
}
|
||||
}
|
||||
return new Polygon(this.flatCoordinates.slice(offset, end), this.layout, ends);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the polygons of this multipolygon.
|
||||
* @return {Array.<module:ol/geom/Polygon>} Polygons.
|
||||
* @api
|
||||
*/
|
||||
getPolygons() {
|
||||
const layout = this.layout;
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const endss = this.endss_;
|
||||
const polygons = [];
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i].slice();
|
||||
const end = ends[ends.length - 1];
|
||||
if (offset !== 0) {
|
||||
for (let j = 0, jj = ends.length; j < jj; ++j) {
|
||||
ends[j] -= offset;
|
||||
}
|
||||
}
|
||||
const polygon = new Polygon(flatCoordinates.slice(offset, end), layout, ends);
|
||||
polygons.push(polygon);
|
||||
offset = end;
|
||||
}
|
||||
return polygons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.MULTI_POLYGON;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return intersectsLinearRingMultiArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the coordinates of the multipolygon.
|
||||
* @param {!Array.<Array.<Array.<module:ol/coordinate~Coordinate>>>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 3);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const endss = deflateMultiCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.endss_);
|
||||
if (endss.length === 0) {
|
||||
this.flatCoordinates.length = 0;
|
||||
} else {
|
||||
const lastEnds = endss[endss.length - 1];
|
||||
this.flatCoordinates.length = lastEnds.length === 0 ?
|
||||
0 : lastEnds[lastEnds.length - 1];
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(MultiPolygon, SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* Append the passed polygon to this multipolygon.
|
||||
* @param {module:ol/geom/Polygon} polygon Polygon.
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.appendPolygon = function(polygon) {
|
||||
/** @type {Array.<number>} */
|
||||
let ends;
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = polygon.getFlatCoordinates().slice();
|
||||
ends = polygon.getEnds().slice();
|
||||
this.endss_.push();
|
||||
} else {
|
||||
const offset = this.flatCoordinates.length;
|
||||
extend(this.flatCoordinates, polygon.getFlatCoordinates());
|
||||
ends = polygon.getEnds().slice();
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
ends[i] += offset;
|
||||
}
|
||||
}
|
||||
this.endss_.push(ends);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/MultiPolygon} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.clone = function() {
|
||||
const len = this.endss_.length;
|
||||
const newEndss = new Array(len);
|
||||
for (let i = 0; i < len; ++i) {
|
||||
newEndss[i] = this.endss_[i].slice();
|
||||
}
|
||||
|
||||
return new MultiPolygon(
|
||||
this.flatCoordinates.slice(), this.layout, newEndss);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
MultiPolygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(multiArrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestMultiArrayPoint(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
MultiPolygon.prototype.containsXY = function(x, y) {
|
||||
return linearRingssContainsXY(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, x, y);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the area of the multipolygon on projected plane.
|
||||
* @return {number} Area (on projected plane).
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.getArea = function() {
|
||||
return linearRingssArea(this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the coordinate array for this geometry. This array has the structure
|
||||
* of a GeoJSON coordinate array for multi-polygons.
|
||||
*
|
||||
* @param {boolean=} opt_right Orient coordinates according to the right-hand
|
||||
* rule (counter-clockwise for exterior and clockwise for interior rings).
|
||||
* If `false`, coordinates will be oriented according to the left-hand rule
|
||||
* (clockwise for exterior and counter-clockwise for interior rings).
|
||||
* By default, coordinate orientation will depend on how the geometry was
|
||||
* constructed.
|
||||
* @return {Array.<Array.<Array.<module:ol/coordinate~Coordinate>>>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.getCoordinates = function(opt_right) {
|
||||
let flatCoordinates;
|
||||
if (opt_right !== undefined) {
|
||||
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||
orientLinearRingsArray(
|
||||
flatCoordinates, 0, this.endss_, this.stride, opt_right);
|
||||
} else {
|
||||
flatCoordinates = this.flatCoordinates;
|
||||
}
|
||||
|
||||
return inflateMultiCoordinatesArray(
|
||||
flatCoordinates, 0, this.endss_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<Array.<number>>} Endss.
|
||||
*/
|
||||
MultiPolygon.prototype.getEndss = function() {
|
||||
return this.endss_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat interior points.
|
||||
*/
|
||||
MultiPolygon.prototype.getFlatInteriorPoints = function() {
|
||||
if (this.flatInteriorPointsRevision_ != this.getRevision()) {
|
||||
const flatCenters = linearRingssCenter(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
this.flatInteriorPoints_ = getInteriorPointsOfMultiArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride,
|
||||
flatCenters);
|
||||
this.flatInteriorPointsRevision_ = this.getRevision();
|
||||
}
|
||||
return this.flatInteriorPoints_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the interior points as {@link module:ol/geom/MultiPoint multipoint}.
|
||||
* @return {module:ol/geom/MultiPoint} Interior points as XYM coordinates, where M is
|
||||
* the length of the horizontal intersection that the point belongs to.
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.getInteriorPoints = function() {
|
||||
return new MultiPoint(this.getFlatInteriorPoints().slice(), GeometryLayout.XYM);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Oriented flat coordinates.
|
||||
*/
|
||||
MultiPolygon.prototype.getOrientedFlatCoordinates = function() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
if (linearRingsAreOriented(
|
||||
flatCoordinates, 0, this.endss_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length =
|
||||
orientLinearRingsArray(
|
||||
this.orientedFlatCoordinates_, 0, this.endss_, this.stride);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
}
|
||||
return this.orientedFlatCoordinates_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEndss = [];
|
||||
simplifiedFlatCoordinates.length = quantizeMultiArray(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride,
|
||||
Math.sqrt(squaredTolerance),
|
||||
simplifiedFlatCoordinates, 0, simplifiedEndss);
|
||||
return new MultiPolygon(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEndss);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the polygon at the specified index.
|
||||
* @param {number} index Index.
|
||||
* @return {module:ol/geom/Polygon} Polygon.
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.getPolygon = function(index) {
|
||||
if (index < 0 || this.endss_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
let offset;
|
||||
if (index === 0) {
|
||||
offset = 0;
|
||||
} else {
|
||||
const prevEnds = this.endss_[index - 1];
|
||||
offset = prevEnds[prevEnds.length - 1];
|
||||
}
|
||||
const ends = this.endss_[index].slice();
|
||||
const end = ends[ends.length - 1];
|
||||
if (offset !== 0) {
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
ends[i] -= offset;
|
||||
}
|
||||
}
|
||||
return new Polygon(this.flatCoordinates.slice(offset, end), this.layout, ends);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the polygons of this multipolygon.
|
||||
* @return {Array.<module:ol/geom/Polygon>} Polygons.
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.getPolygons = function() {
|
||||
const layout = this.layout;
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const endss = this.endss_;
|
||||
const polygons = [];
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = endss.length; i < ii; ++i) {
|
||||
const ends = endss[i].slice();
|
||||
const end = ends[ends.length - 1];
|
||||
if (offset !== 0) {
|
||||
for (let j = 0, jj = ends.length; j < jj; ++j) {
|
||||
ends[j] -= offset;
|
||||
}
|
||||
}
|
||||
const polygon = new Polygon(flatCoordinates.slice(offset, end), layout, ends);
|
||||
polygons.push(polygon);
|
||||
offset = end;
|
||||
}
|
||||
return polygons;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.getType = function() {
|
||||
return GeometryType.MULTI_POLYGON;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.intersectsExtent = function(extent) {
|
||||
return intersectsLinearRingMultiArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.endss_, this.stride, extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the coordinates of the multipolygon.
|
||||
* @param {!Array.<Array.<Array.<module:ol/coordinate~Coordinate>>>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
MultiPolygon.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 3);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const endss = deflateMultiCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.endss_);
|
||||
if (endss.length === 0) {
|
||||
this.flatCoordinates.length = 0;
|
||||
} else {
|
||||
const lastEnds = endss[endss.length - 1];
|
||||
this.flatCoordinates.length = lastEnds.length === 0 ?
|
||||
0 : lastEnds[lastEnds.length - 1];
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
export default MultiPolygon;
|
||||
|
||||
+82
-86
@@ -18,94 +18,90 @@ import {squaredDistance as squaredDx} from '../math.js';
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @api
|
||||
*/
|
||||
const Point = function(coordinates, opt_layout) {
|
||||
SimpleGeometry.call(this);
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
};
|
||||
class Point {
|
||||
constructor(coordinates, opt_layout) {
|
||||
SimpleGeometry.call(this);
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/Point} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const point = new Point(this.flatCoordinates.slice(), this.layout);
|
||||
return point;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const squaredDistance = squaredDx(x, y, flatCoordinates[0], flatCoordinates[1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
const stride = this.stride;
|
||||
for (let i = 0; i < stride; ++i) {
|
||||
closestPoint[i] = flatCoordinates[i];
|
||||
}
|
||||
closestPoint.length = stride;
|
||||
return squaredDistance;
|
||||
} else {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the coordinate of the point.
|
||||
* @return {module:ol/coordinate~Coordinate} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
getCoordinates() {
|
||||
return !this.flatCoordinates ? [] : this.flatCoordinates.slice();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
computeExtent(extent) {
|
||||
return createOrUpdateFromCoordinate(this.flatCoordinates, extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.POINT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return containsXY(extent, this.flatCoordinates[0], this.flatCoordinates[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 0);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinate(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Point, SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/Point} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
Point.prototype.clone = function() {
|
||||
const point = new Point(this.flatCoordinates.slice(), this.layout);
|
||||
return point;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Point.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const squaredDistance = squaredDx(x, y, flatCoordinates[0], flatCoordinates[1]);
|
||||
if (squaredDistance < minSquaredDistance) {
|
||||
const stride = this.stride;
|
||||
for (let i = 0; i < stride; ++i) {
|
||||
closestPoint[i] = flatCoordinates[i];
|
||||
}
|
||||
closestPoint.length = stride;
|
||||
return squaredDistance;
|
||||
} else {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the coordinate of the point.
|
||||
* @return {module:ol/coordinate~Coordinate} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
Point.prototype.getCoordinates = function() {
|
||||
return !this.flatCoordinates ? [] : this.flatCoordinates.slice();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Point.prototype.computeExtent = function(extent) {
|
||||
return createOrUpdateFromCoordinate(this.flatCoordinates, extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
Point.prototype.getType = function() {
|
||||
return GeometryType.POINT;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
Point.prototype.intersectsExtent = function(extent) {
|
||||
return containsXY(extent, this.flatCoordinates[0], this.flatCoordinates[1]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
Point.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 0);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = deflateCoordinate(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
export default Point;
|
||||
|
||||
+279
-293
@@ -39,314 +39,300 @@ import {modulo} from '../math.js';
|
||||
* coordinates).
|
||||
* @api
|
||||
*/
|
||||
const Polygon = function(coordinates, opt_layout, opt_ends) {
|
||||
class Polygon {
|
||||
constructor(coordinates, opt_layout, opt_ends) {
|
||||
|
||||
SimpleGeometry.call(this);
|
||||
SimpleGeometry.call(this);
|
||||
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @private
|
||||
*/
|
||||
this.ends_ = [];
|
||||
/**
|
||||
* @type {Array.<number>}
|
||||
* @private
|
||||
*/
|
||||
this.ends_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.flatInteriorPointRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.flatInteriorPointRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/coordinate~Coordinate}
|
||||
*/
|
||||
this.flatInteriorPoint_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/coordinate~Coordinate}
|
||||
*/
|
||||
this.flatInteriorPoint_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDelta_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxDeltaRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.orientedRevision_ = -1;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.orientedRevision_ = -1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.orientedFlatCoordinates_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.orientedFlatCoordinates_ = null;
|
||||
|
||||
if (opt_layout !== undefined && opt_ends) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
this.ends_ = opt_ends;
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
if (opt_layout !== undefined && opt_ends) {
|
||||
this.setFlatCoordinates(opt_layout, coordinates);
|
||||
this.ends_ = opt_ends;
|
||||
} else {
|
||||
this.setCoordinates(coordinates, opt_layout);
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Append the passed linear ring to this polygon.
|
||||
* @param {module:ol/geom/LinearRing} linearRing Linear ring.
|
||||
* @api
|
||||
*/
|
||||
appendLinearRing(linearRing) {
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = linearRing.getFlatCoordinates().slice();
|
||||
} else {
|
||||
extend(this.flatCoordinates, linearRing.getFlatCoordinates());
|
||||
}
|
||||
this.ends_.push(this.flatCoordinates.length);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/Polygon} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new Polygon(this.flatCoordinates.slice(), this.layout, this.ends_.slice());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
closestPointXY(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestArrayPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
containsXY(x, y) {
|
||||
return linearRingsContainsXY(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the area of the polygon on projected plane.
|
||||
* @return {number} Area (on projected plane).
|
||||
* @api
|
||||
*/
|
||||
getArea() {
|
||||
return linearRingsArea(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the coordinate array for this geometry. This array has the structure
|
||||
* of a GeoJSON coordinate array for polygons.
|
||||
*
|
||||
* @param {boolean=} opt_right Orient coordinates according to the right-hand
|
||||
* rule (counter-clockwise for exterior and clockwise for interior rings).
|
||||
* If `false`, coordinates will be oriented according to the left-hand rule
|
||||
* (clockwise for exterior and counter-clockwise for interior rings).
|
||||
* By default, coordinate orientation will depend on how the geometry was
|
||||
* constructed.
|
||||
* @return {Array.<Array.<module:ol/coordinate~Coordinate>>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
getCoordinates(opt_right) {
|
||||
let flatCoordinates;
|
||||
if (opt_right !== undefined) {
|
||||
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||
orientLinearRings(
|
||||
flatCoordinates, 0, this.ends_, this.stride, opt_right);
|
||||
} else {
|
||||
flatCoordinates = this.flatCoordinates;
|
||||
}
|
||||
|
||||
return inflateCoordinatesArray(
|
||||
flatCoordinates, 0, this.ends_, this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Ends.
|
||||
*/
|
||||
getEnds() {
|
||||
return this.ends_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Interior point.
|
||||
*/
|
||||
getFlatInteriorPoint() {
|
||||
if (this.flatInteriorPointRevision_ != this.getRevision()) {
|
||||
const flatCenter = getCenter(this.getExtent());
|
||||
this.flatInteriorPoint_ = getInteriorPointOfArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride,
|
||||
flatCenter, 0);
|
||||
this.flatInteriorPointRevision_ = this.getRevision();
|
||||
}
|
||||
return this.flatInteriorPoint_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an interior point of the polygon.
|
||||
* @return {module:ol/geom/Point} Interior point as XYM coordinate, where M is the
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
* @api
|
||||
*/
|
||||
getInteriorPoint() {
|
||||
return new Point(this.getFlatInteriorPoint(), GeometryLayout.XYM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of rings of the polygon, this includes the exterior
|
||||
* ring and any interior rings.
|
||||
*
|
||||
* @return {number} Number of rings.
|
||||
* @api
|
||||
*/
|
||||
getLinearRingCount() {
|
||||
return this.ends_.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Nth linear ring of the polygon geometry. Return `null` if the
|
||||
* given index is out of range.
|
||||
* The exterior linear ring is available at index `0` and the interior rings
|
||||
* at index `1` and beyond.
|
||||
*
|
||||
* @param {number} index Index.
|
||||
* @return {module:ol/geom/LinearRing} Linear ring.
|
||||
* @api
|
||||
*/
|
||||
getLinearRing(index) {
|
||||
if (index < 0 || this.ends_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
return new LinearRing(this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the linear rings of the polygon.
|
||||
* @return {Array.<module:ol/geom/LinearRing>} Linear rings.
|
||||
* @api
|
||||
*/
|
||||
getLinearRings() {
|
||||
const layout = this.layout;
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const ends = this.ends_;
|
||||
const linearRings = [];
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const linearRing = new LinearRing(flatCoordinates.slice(offset, end), layout);
|
||||
linearRings.push(linearRing);
|
||||
offset = end;
|
||||
}
|
||||
return linearRings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Oriented flat coordinates.
|
||||
*/
|
||||
getOrientedFlatCoordinates() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
if (linearRingIsOriented(
|
||||
flatCoordinates, 0, this.ends_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length =
|
||||
orientLinearRings(
|
||||
this.orientedFlatCoordinates_, 0, this.ends_, this.stride);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
}
|
||||
return this.orientedFlatCoordinates_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedFlatCoordinates.length = quantizeArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
Math.sqrt(squaredTolerance),
|
||||
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
||||
return new Polygon(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEnds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
getType() {
|
||||
return GeometryType.POLYGON;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
intersectsExtent(extent) {
|
||||
return intersectsLinearRingArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the coordinates of the polygon.
|
||||
* @param {!Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const ends = deflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Polygon, SimpleGeometry);
|
||||
|
||||
|
||||
/**
|
||||
* Append the passed linear ring to this polygon.
|
||||
* @param {module:ol/geom/LinearRing} linearRing Linear ring.
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.appendLinearRing = function(linearRing) {
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = linearRing.getFlatCoordinates().slice();
|
||||
} else {
|
||||
extend(this.flatCoordinates, linearRing.getFlatCoordinates());
|
||||
}
|
||||
this.ends_.push(this.flatCoordinates.length);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Make a complete copy of the geometry.
|
||||
* @return {!module:ol/geom/Polygon} Clone.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.clone = function() {
|
||||
return new Polygon(this.flatCoordinates.slice(), this.layout, this.ends_.slice());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polygon.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
|
||||
if (minSquaredDistance < closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||
return minSquaredDistance;
|
||||
}
|
||||
if (this.maxDeltaRevision_ != this.getRevision()) {
|
||||
this.maxDelta_ = Math.sqrt(arrayMaxSquaredDelta(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride, 0));
|
||||
this.maxDeltaRevision_ = this.getRevision();
|
||||
}
|
||||
return assignClosestArrayPoint(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
this.maxDelta_, true, x, y, closestPoint, minSquaredDistance);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polygon.prototype.containsXY = function(x, y) {
|
||||
return linearRingsContainsXY(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, x, y);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the area of the polygon on projected plane.
|
||||
* @return {number} Area (on projected plane).
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.getArea = function() {
|
||||
return linearRingsArea(this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the coordinate array for this geometry. This array has the structure
|
||||
* of a GeoJSON coordinate array for polygons.
|
||||
*
|
||||
* @param {boolean=} opt_right Orient coordinates according to the right-hand
|
||||
* rule (counter-clockwise for exterior and clockwise for interior rings).
|
||||
* If `false`, coordinates will be oriented according to the left-hand rule
|
||||
* (clockwise for exterior and counter-clockwise for interior rings).
|
||||
* By default, coordinate orientation will depend on how the geometry was
|
||||
* constructed.
|
||||
* @return {Array.<Array.<module:ol/coordinate~Coordinate>>} Coordinates.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.getCoordinates = function(opt_right) {
|
||||
let flatCoordinates;
|
||||
if (opt_right !== undefined) {
|
||||
flatCoordinates = this.getOrientedFlatCoordinates().slice();
|
||||
orientLinearRings(
|
||||
flatCoordinates, 0, this.ends_, this.stride, opt_right);
|
||||
} else {
|
||||
flatCoordinates = this.flatCoordinates;
|
||||
}
|
||||
|
||||
return inflateCoordinatesArray(
|
||||
flatCoordinates, 0, this.ends_, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Ends.
|
||||
*/
|
||||
Polygon.prototype.getEnds = function() {
|
||||
return this.ends_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Interior point.
|
||||
*/
|
||||
Polygon.prototype.getFlatInteriorPoint = function() {
|
||||
if (this.flatInteriorPointRevision_ != this.getRevision()) {
|
||||
const flatCenter = getCenter(this.getExtent());
|
||||
this.flatInteriorPoint_ = getInteriorPointOfArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride,
|
||||
flatCenter, 0);
|
||||
this.flatInteriorPointRevision_ = this.getRevision();
|
||||
}
|
||||
return this.flatInteriorPoint_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return an interior point of the polygon.
|
||||
* @return {module:ol/geom/Point} Interior point as XYM coordinate, where M is the
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.getInteriorPoint = function() {
|
||||
return new Point(this.getFlatInteriorPoint(), GeometryLayout.XYM);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of rings of the polygon, this includes the exterior
|
||||
* ring and any interior rings.
|
||||
*
|
||||
* @return {number} Number of rings.
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.getLinearRingCount = function() {
|
||||
return this.ends_.length;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the Nth linear ring of the polygon geometry. Return `null` if the
|
||||
* given index is out of range.
|
||||
* The exterior linear ring is available at index `0` and the interior rings
|
||||
* at index `1` and beyond.
|
||||
*
|
||||
* @param {number} index Index.
|
||||
* @return {module:ol/geom/LinearRing} Linear ring.
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.getLinearRing = function(index) {
|
||||
if (index < 0 || this.ends_.length <= index) {
|
||||
return null;
|
||||
}
|
||||
return new LinearRing(this.flatCoordinates.slice(
|
||||
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the linear rings of the polygon.
|
||||
* @return {Array.<module:ol/geom/LinearRing>} Linear rings.
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.getLinearRings = function() {
|
||||
const layout = this.layout;
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
const ends = this.ends_;
|
||||
const linearRings = [];
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
const linearRing = new LinearRing(flatCoordinates.slice(offset, end), layout);
|
||||
linearRings.push(linearRing);
|
||||
offset = end;
|
||||
}
|
||||
return linearRings;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Oriented flat coordinates.
|
||||
*/
|
||||
Polygon.prototype.getOrientedFlatCoordinates = function() {
|
||||
if (this.orientedRevision_ != this.getRevision()) {
|
||||
const flatCoordinates = this.flatCoordinates;
|
||||
if (linearRingIsOriented(
|
||||
flatCoordinates, 0, this.ends_, this.stride)) {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates;
|
||||
} else {
|
||||
this.orientedFlatCoordinates_ = flatCoordinates.slice();
|
||||
this.orientedFlatCoordinates_.length =
|
||||
orientLinearRings(
|
||||
this.orientedFlatCoordinates_, 0, this.ends_, this.stride);
|
||||
}
|
||||
this.orientedRevision_ = this.getRevision();
|
||||
}
|
||||
return this.orientedFlatCoordinates_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
const simplifiedEnds = [];
|
||||
simplifiedFlatCoordinates.length = quantizeArray(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride,
|
||||
Math.sqrt(squaredTolerance),
|
||||
simplifiedFlatCoordinates, 0, simplifiedEnds);
|
||||
return new Polygon(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEnds);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.getType = function() {
|
||||
return GeometryType.POLYGON;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.intersectsExtent = function(extent) {
|
||||
return intersectsLinearRingArray(
|
||||
this.getOrientedFlatCoordinates(), 0, this.ends_, this.stride, extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the coordinates of the polygon.
|
||||
* @param {!Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
if (!this.flatCoordinates) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
const ends = deflateCoordinatesArray(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
this.changed();
|
||||
};
|
||||
|
||||
export default Polygon;
|
||||
|
||||
|
||||
|
||||
+226
-240
@@ -19,29 +19,243 @@ import {clear} from '../obj.js';
|
||||
* @extends {module:ol/geom/Geometry}
|
||||
* @api
|
||||
*/
|
||||
const SimpleGeometry = function() {
|
||||
class SimpleGeometry {
|
||||
constructor() {
|
||||
|
||||
Geometry.call(this);
|
||||
Geometry.call(this);
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {module:ol/geom/GeometryLayout}
|
||||
*/
|
||||
this.layout = GeometryLayout.XY;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.stride = 2;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.flatCoordinates = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {module:ol/geom/GeometryLayout}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.layout = GeometryLayout.XY;
|
||||
computeExtent(extent) {
|
||||
return createOrUpdateFromFlatCoordinates(this.flatCoordinates,
|
||||
0, this.flatCoordinates.length, this.stride, extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
* @abstract
|
||||
* @return {Array} Coordinates.
|
||||
*/
|
||||
this.stride = 2;
|
||||
getCoordinates() {}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
* Return the first coordinate of the geometry.
|
||||
* @return {module:ol/coordinate~Coordinate} First coordinate.
|
||||
* @api
|
||||
*/
|
||||
this.flatCoordinates = null;
|
||||
getFirstCoordinate() {
|
||||
return this.flatCoordinates.slice(0, this.stride);
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
getFlatCoordinates() {
|
||||
return this.flatCoordinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last coordinate of the geometry.
|
||||
* @return {module:ol/coordinate~Coordinate} Last point.
|
||||
* @api
|
||||
*/
|
||||
getLastCoordinate() {
|
||||
return this.flatCoordinates.slice(this.flatCoordinates.length - this.stride);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link module:ol/geom/GeometryLayout~GeometryLayout layout} of the geometry.
|
||||
* @return {module:ol/geom/GeometryLayout} Layout.
|
||||
* @api
|
||||
*/
|
||||
getLayout() {
|
||||
return this.layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSimplifiedGeometry(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.getRevision()) {
|
||||
clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
// If squaredTolerance is negative or if we know that simplification will not
|
||||
// have any effect then just return this.
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||
return this;
|
||||
}
|
||||
const key = squaredTolerance.toString();
|
||||
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||
return this.simplifiedGeometryCache[key];
|
||||
} else {
|
||||
const simplifiedGeometry =
|
||||
this.getSimplifiedGeometryInternal(squaredTolerance);
|
||||
const simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
||||
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
||||
this.simplifiedGeometryCache[key] = simplifiedGeometry;
|
||||
return simplifiedGeometry;
|
||||
} else {
|
||||
// Simplification did not actually remove any coordinates. We now know
|
||||
// that any calls to getSimplifiedGeometry with a squaredTolerance less
|
||||
// than or equal to the current squaredTolerance will also not have any
|
||||
// effect. This allows us to short circuit simplification (saving CPU
|
||||
// cycles) and prevents the cache of simplified geometries from filling
|
||||
// up with useless identical copies of this geometry (saving memory).
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {module:ol/geom/SimpleGeometry} Simplified geometry.
|
||||
* @protected
|
||||
*/
|
||||
getSimplifiedGeometryInternal(squaredTolerance) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
getStride() {
|
||||
return this.stride;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
setFlatCoordinates(layout, flatCoordinates) {
|
||||
this.stride = getStrideForLayout(layout);
|
||||
this.layout = layout;
|
||||
this.flatCoordinates = flatCoordinates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {!Array} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {}
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout|undefined} layout Layout.
|
||||
* @param {Array} coordinates Coordinates.
|
||||
* @param {number} nesting Nesting.
|
||||
* @protected
|
||||
*/
|
||||
setLayout(layout, coordinates, nesting) {
|
||||
/** @type {number} */
|
||||
let stride;
|
||||
if (layout) {
|
||||
stride = getStrideForLayout(layout);
|
||||
} else {
|
||||
for (let i = 0; i < nesting; ++i) {
|
||||
if (coordinates.length === 0) {
|
||||
this.layout = GeometryLayout.XY;
|
||||
this.stride = 2;
|
||||
return;
|
||||
} else {
|
||||
coordinates = /** @type {Array} */ (coordinates[0]);
|
||||
}
|
||||
}
|
||||
stride = coordinates.length;
|
||||
layout = getLayoutForStride(stride);
|
||||
}
|
||||
this.layout = layout;
|
||||
this.stride = stride;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
applyTransform(transformFn) {
|
||||
if (this.flatCoordinates) {
|
||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
rotate(angle, anchor) {
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
rotate(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, angle, anchor, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
scale(sx, opt_sy, opt_anchor) {
|
||||
let sy = opt_sy;
|
||||
if (sy === undefined) {
|
||||
sy = sx;
|
||||
}
|
||||
let anchor = opt_anchor;
|
||||
if (!anchor) {
|
||||
anchor = getCenter(this.getExtent());
|
||||
}
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
scale(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, sx, sy, anchor, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
translate(deltaX, deltaY) {
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
translate(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride,
|
||||
deltaX, deltaY, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inherits(SimpleGeometry, Geometry);
|
||||
|
||||
@@ -88,234 +302,6 @@ export function getStrideForLayout(layout) {
|
||||
SimpleGeometry.prototype.containsXY = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
SimpleGeometry.prototype.computeExtent = function(extent) {
|
||||
return createOrUpdateFromFlatCoordinates(this.flatCoordinates,
|
||||
0, this.flatCoordinates.length, this.stride, extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {Array} Coordinates.
|
||||
*/
|
||||
SimpleGeometry.prototype.getCoordinates = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Return the first coordinate of the geometry.
|
||||
* @return {module:ol/coordinate~Coordinate} First coordinate.
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.getFirstCoordinate = function() {
|
||||
return this.flatCoordinates.slice(0, this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
SimpleGeometry.prototype.getFlatCoordinates = function() {
|
||||
return this.flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the last coordinate of the geometry.
|
||||
* @return {module:ol/coordinate~Coordinate} Last point.
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.getLastCoordinate = function() {
|
||||
return this.flatCoordinates.slice(this.flatCoordinates.length - this.stride);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the {@link module:ol/geom/GeometryLayout~GeometryLayout layout} of the geometry.
|
||||
* @return {module:ol/geom/GeometryLayout} Layout.
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.getLayout = function() {
|
||||
return this.layout;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
SimpleGeometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {
|
||||
if (this.simplifiedGeometryRevision != this.getRevision()) {
|
||||
clear(this.simplifiedGeometryCache);
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||
this.simplifiedGeometryRevision = this.getRevision();
|
||||
}
|
||||
// If squaredTolerance is negative or if we know that simplification will not
|
||||
// have any effect then just return this.
|
||||
if (squaredTolerance < 0 ||
|
||||
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||
return this;
|
||||
}
|
||||
const key = squaredTolerance.toString();
|
||||
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||
return this.simplifiedGeometryCache[key];
|
||||
} else {
|
||||
const simplifiedGeometry =
|
||||
this.getSimplifiedGeometryInternal(squaredTolerance);
|
||||
const simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
||||
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
||||
this.simplifiedGeometryCache[key] = simplifiedGeometry;
|
||||
return simplifiedGeometry;
|
||||
} else {
|
||||
// Simplification did not actually remove any coordinates. We now know
|
||||
// that any calls to getSimplifiedGeometry with a squaredTolerance less
|
||||
// than or equal to the current squaredTolerance will also not have any
|
||||
// effect. This allows us to short circuit simplification (saving CPU
|
||||
// cycles) and prevents the cache of simplified geometries from filling
|
||||
// up with useless identical copies of this geometry (saving memory).
|
||||
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @return {module:ol/geom/SimpleGeometry} Simplified geometry.
|
||||
* @protected
|
||||
*/
|
||||
SimpleGeometry.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number} Stride.
|
||||
*/
|
||||
SimpleGeometry.prototype.getStride = function() {
|
||||
return this.stride;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
SimpleGeometry.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
|
||||
this.stride = getStrideForLayout(layout);
|
||||
this.layout = layout;
|
||||
this.flatCoordinates = flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {!Array} coordinates Coordinates.
|
||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||
*/
|
||||
SimpleGeometry.prototype.setCoordinates = function(coordinates, opt_layout) {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/GeometryLayout|undefined} layout Layout.
|
||||
* @param {Array} coordinates Coordinates.
|
||||
* @param {number} nesting Nesting.
|
||||
* @protected
|
||||
*/
|
||||
SimpleGeometry.prototype.setLayout = function(layout, coordinates, nesting) {
|
||||
/** @type {number} */
|
||||
let stride;
|
||||
if (layout) {
|
||||
stride = getStrideForLayout(layout);
|
||||
} else {
|
||||
for (let i = 0; i < nesting; ++i) {
|
||||
if (coordinates.length === 0) {
|
||||
this.layout = GeometryLayout.XY;
|
||||
this.stride = 2;
|
||||
return;
|
||||
} else {
|
||||
coordinates = /** @type {Array} */ (coordinates[0]);
|
||||
}
|
||||
}
|
||||
stride = coordinates.length;
|
||||
layout = getLayoutForStride(stride);
|
||||
}
|
||||
this.layout = layout;
|
||||
this.stride = stride;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.applyTransform = function(transformFn) {
|
||||
if (this.flatCoordinates) {
|
||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.rotate = function(angle, anchor) {
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
rotate(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, angle, anchor, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.scale = function(sx, opt_sy, opt_anchor) {
|
||||
let sy = opt_sy;
|
||||
if (sy === undefined) {
|
||||
sy = sx;
|
||||
}
|
||||
let anchor = opt_anchor;
|
||||
if (!anchor) {
|
||||
anchor = getCenter(this.getExtent());
|
||||
}
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
scale(
|
||||
flatCoordinates, 0, flatCoordinates.length,
|
||||
stride, sx, sy, anchor, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
SimpleGeometry.prototype.translate = function(deltaX, deltaY) {
|
||||
const flatCoordinates = this.getFlatCoordinates();
|
||||
if (flatCoordinates) {
|
||||
const stride = this.getStride();
|
||||
translate(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride,
|
||||
deltaX, deltaY, flatCoordinates);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/SimpleGeometry} simpleGeometry Simple geometry.
|
||||
* @param {module:ol/transform~Transform} transform Transform.
|
||||
|
||||
Reference in New Issue
Block a user