import { linearRingss } from "./chunk-VIJW6LYV.js"; import { getInteriorPointOfArray, getInteriorPointsOfMultiArray, inflateEnds } from "./chunk-RBA5LKAR.js"; import { interpolatePoint } from "./chunk-CXIHWQDX.js"; import { douglasPeucker, douglasPeuckerArray, quantizeArray } from "./chunk-NLIGXLAR.js"; import { transform2D } from "./chunk-YUTQGDGI.js"; import { compose, create } from "./chunk-JFONEOYG.js"; import { get } from "./chunk-XZU4LSFD.js"; import { createOrUpdateFromCoordinate, createOrUpdateFromFlatCoordinates, getCenter, getHeight } from "./chunk-CKDBVGKM.js"; import { memoizeOne } from "./chunk-KJXIHBKT.js"; import { extend } from "./chunk-FQY6EMA7.js"; // node_modules/ol/render/Feature.js var tmpTransform = create(); var RenderFeature = class _RenderFeature { /** * @param {Type} type Geometry type. * @param {Array} flatCoordinates Flat coordinates. These always need * to be right-handed for polygons. * @param {Array} ends Ends. * @param {number} stride Stride. * @param {Object} properties Properties. * @param {number|string|undefined} id Feature id. */ constructor(type, flatCoordinates, ends, stride, properties, id) { this.styleFunction; this.extent_; this.id_ = id; this.type_ = type; this.flatCoordinates_ = flatCoordinates; this.flatInteriorPoints_ = null; this.flatMidpoints_ = null; this.ends_ = ends || null; this.properties_ = properties; this.squaredTolerance_; this.stride_ = stride; this.simplifiedGeometry_; } /** * Get a feature property by its key. * @param {string} key Key * @return {*} Value for the requested key. * @api */ get(key) { return this.properties_[key]; } /** * Get the extent of this feature's geometry. * @return {import("../extent.js").Extent} Extent. * @api */ getExtent() { if (!this.extent_) { this.extent_ = this.type_ === "Point" ? createOrUpdateFromCoordinate(this.flatCoordinates_) : createOrUpdateFromFlatCoordinates( this.flatCoordinates_, 0, this.flatCoordinates_.length, 2 ); } return this.extent_; } /** * @return {Array} Flat interior points. */ getFlatInteriorPoint() { if (!this.flatInteriorPoints_) { const flatCenter = getCenter(this.getExtent()); this.flatInteriorPoints_ = getInteriorPointOfArray( this.flatCoordinates_, 0, this.ends_, 2, flatCenter, 0 ); } return this.flatInteriorPoints_; } /** * @return {Array} Flat interior points. */ getFlatInteriorPoints() { if (!this.flatInteriorPoints_) { const ends = inflateEnds(this.flatCoordinates_, this.ends_); const flatCenters = linearRingss(this.flatCoordinates_, 0, ends, 2); this.flatInteriorPoints_ = getInteriorPointsOfMultiArray( this.flatCoordinates_, 0, ends, 2, flatCenters ); } return this.flatInteriorPoints_; } /** * @return {Array} Flat midpoint. */ getFlatMidpoint() { if (!this.flatMidpoints_) { this.flatMidpoints_ = interpolatePoint( this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, 0.5 ); } return this.flatMidpoints_; } /** * @return {Array} Flat midpoints. */ getFlatMidpoints() { if (!this.flatMidpoints_) { this.flatMidpoints_ = []; const flatCoordinates = this.flatCoordinates_; let offset = 0; const ends = ( /** @type {Array} */ this.ends_ ); for (let i = 0, ii = ends.length; i < ii; ++i) { const end = ends[i]; const midpoint = interpolatePoint(flatCoordinates, offset, end, 2, 0.5); extend(this.flatMidpoints_, midpoint); offset = end; } } return this.flatMidpoints_; } /** * Get the feature identifier. This is a stable identifier for the feature and * is set when reading data from a remote source. * @return {number|string|undefined} Id. * @api */ getId() { return this.id_; } /** * @return {Array} Flat coordinates. */ getOrientedFlatCoordinates() { return this.flatCoordinates_; } /** * For API compatibility with {@link module:ol/Feature~Feature}, this method is useful when * determining the geometry type in style function (see {@link #getType}). * @return {RenderFeature} Feature. * @api */ getGeometry() { return this; } /** * @param {number} squaredTolerance Squared tolerance. * @return {RenderFeature} Simplified geometry. */ getSimplifiedGeometry(squaredTolerance) { return this; } /** * Get a transformed and simplified version of the geometry. * @param {number} squaredTolerance Squared tolerance. * @param {import("../proj.js").TransformFunction} [transform] Optional transform function. * @return {RenderFeature} Simplified geometry. */ simplifyTransformed(squaredTolerance, transform) { return this; } /** * Get the feature properties. * @return {Object} Feature properties. * @api */ getProperties() { return this.properties_; } /** * Get an object of all property names and values. This has the same behavior as getProperties, * but is here to conform with the {@link module:ol/Feature~Feature} interface. * @return {Object?} Object. */ getPropertiesInternal() { return this.properties_; } /** * @return {number} Stride. */ getStride() { return this.stride_; } /** * @return {import('../style/Style.js').StyleFunction|undefined} Style */ getStyleFunction() { return this.styleFunction; } /** * Get the type of this feature's geometry. * @return {Type} Geometry type. * @api */ getType() { return this.type_; } /** * Transform geometry coordinates from tile pixel space to projected. * * @param {import("../proj.js").ProjectionLike} projection The data projection */ transform(projection) { projection = get(projection); const pixelExtent = projection.getExtent(); const projectedExtent = projection.getWorldExtent(); if (pixelExtent && projectedExtent) { const scale = getHeight(projectedExtent) / getHeight(pixelExtent); compose( tmpTransform, projectedExtent[0], projectedExtent[3], scale, -scale, 0, 0, 0 ); transform2D( this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, tmpTransform, this.flatCoordinates_ ); } } /** * Apply a transform function to the coordinates 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. * @param {import("../proj.js").TransformFunction} transformFn Transform function. */ applyTransform(transformFn) { transformFn(this.flatCoordinates_, this.flatCoordinates_, this.stride_); } /** * @return {RenderFeature} A cloned render feature. */ clone() { var _a; return new _RenderFeature( this.type_, this.flatCoordinates_.slice(), (_a = this.ends_) == null ? void 0 : _a.slice(), this.stride_, Object.assign({}, this.properties_), this.id_ ); } /** * @return {Array|null} Ends. */ getEnds() { return this.ends_; } /** * Add transform and resolution based geometry simplification to this instance. * @return {RenderFeature} This render feature. */ enableSimplifyTransformed() { this.simplifyTransformed = memoizeOne((squaredTolerance, transform) => { if (squaredTolerance === this.squaredTolerance_) { return this.simplifiedGeometry_; } this.simplifiedGeometry_ = this.clone(); if (transform) { this.simplifiedGeometry_.applyTransform(transform); } const simplifiedFlatCoordinates = this.simplifiedGeometry_.getFlatCoordinates(); let simplifiedEnds; switch (this.type_) { case "LineString": simplifiedFlatCoordinates.length = douglasPeucker( simplifiedFlatCoordinates, 0, this.simplifiedGeometry_.flatCoordinates_.length, this.simplifiedGeometry_.stride_, squaredTolerance, simplifiedFlatCoordinates, 0 ); simplifiedEnds = [simplifiedFlatCoordinates.length]; break; case "MultiLineString": simplifiedEnds = []; simplifiedFlatCoordinates.length = douglasPeuckerArray( simplifiedFlatCoordinates, 0, this.simplifiedGeometry_.ends_, this.simplifiedGeometry_.stride_, squaredTolerance, simplifiedFlatCoordinates, 0, simplifiedEnds ); break; case "Polygon": simplifiedEnds = []; simplifiedFlatCoordinates.length = quantizeArray( simplifiedFlatCoordinates, 0, this.simplifiedGeometry_.ends_, this.simplifiedGeometry_.stride_, Math.sqrt(squaredTolerance), simplifiedFlatCoordinates, 0, simplifiedEnds ); break; default: } if (simplifiedEnds) { this.simplifiedGeometry_ = new _RenderFeature( this.type_, simplifiedFlatCoordinates, simplifiedEnds, 2, this.properties_, this.id_ ); } this.squaredTolerance_ = squaredTolerance; return this.simplifiedGeometry_; }); return this; } }; RenderFeature.prototype.getFlatCoordinates = RenderFeature.prototype.getOrientedFlatCoordinates; var Feature_default2 = RenderFeature; export { Feature_default2 as Feature_default }; //# sourceMappingURL=chunk-FDGVG43Y.js.map