From c1ab4aa4923deb5632762a8ab0208e6af328513d Mon Sep 17 00:00:00 2001 From: Christopher Caldwell Date: Mon, 10 Oct 2022 12:25:40 -0400 Subject: [PATCH] fix for cached geometry error --- README.md | 4 ++++ lib/tiles/features/index.ts | 23 +++++++++++------------ package.json | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index df13adbf..caa2820f 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ The GeoPackage JavaScript library currently provides the ability to read GeoPack ### Changelog +##### 4.2.3 + +- fix cached geometry error + ##### 4.2.2 - fix simplify error diff --git a/lib/tiles/features/index.ts b/lib/tiles/features/index.ts index 20150b4b..bbe19a2d 100644 --- a/lib/tiles/features/index.ts +++ b/lib/tiles/features/index.ts @@ -748,20 +748,19 @@ export class FeatureTiles { /** * Simplify x,y tile coordinates by 1 pixel - * @param lineString GeoJSON with coordinates in pixels + * @param coordinatesArray GeoJSON with coordinates in pixels * @param isPolygon determines if the first and last point need to stay connected * @return simplified GeoJSON * @since 2.0.0 */ - simplifyPoints(lineString: any, isPolygon = false): any | null { - lineString.coordinates = simplify( - lineString.coordinates.map(coordinate => { + simplifyPoints(coordinatesArray: any, isPolygon = false): any | null { + return simplify( + coordinatesArray.map(coordinate => { return { x: coordinate[0], y: coordinate[1] }; }), this.simplifyToleranceInPixels, false, ).map(point => [point.x, point.y]); - return lineString; } /** @@ -773,18 +772,18 @@ export class FeatureTiles { * @param transform */ getPath(lineString: any, context: any, boundingBox: BoundingBox, isPolygon = false, transform: Function): void { - lineString.coordinates = lineString.coordinates.map(coordinate => { - const transformedCoordinate = transform(coordinate); + const line = lineString.coordinates.map(coordinate => { + const transformedCoordinate = transform(coordinate.slice()); return [ TileBoundingBoxUtils.getXPixel(this.tileWidth, boundingBox, transformedCoordinate[0]), TileBoundingBoxUtils.getYPixel(this.tileHeight, boundingBox, transformedCoordinate[1]), ]; }); - const simplifiedLineString = this.simplifyGeometries ? this.simplifyPoints(lineString, isPolygon) : lineString; - if (simplifiedLineString.coordinates.length > 1) { - context.moveTo(simplifiedLineString.coordinates[0][0], simplifiedLineString.coordinates[0][1]); - for (let i = 1; i < simplifiedLineString.coordinates.length; i++) { - context.lineTo(simplifiedLineString.coordinates[i][0], simplifiedLineString.coordinates[i][1]); + const simplifiedLineString = this.simplifyGeometries ? this.simplifyPoints(line, isPolygon) : line; + if (simplifiedLineString.length > 1) { + context.moveTo(simplifiedLineString[0][0], simplifiedLineString[0][1]); + for (let i = 1; i < simplifiedLineString.length; i++) { + context.lineTo(simplifiedLineString[i][0], simplifiedLineString[i][1]); } } } diff --git a/package.json b/package.json index 14593ad2..3dd51f4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ngageoint/geopackage", - "version": "4.2.2", + "version": "4.2.3", "description": "GeoPackage JavaScript Library", "keywords": [ "NGA",