Skip to content

Commit

Permalink
fix simplify error
Browse files Browse the repository at this point in the history
  • Loading branch information
caldwellc committed Jun 24, 2022
1 parent f4c2ff6 commit 30a1fa0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ The GeoPackage JavaScript library currently provides the ability to read GeoPack

### Changelog

##### 4.2.2

- fix simplify error

##### 4.2.1

- Fix for drawing geometries outside of the 3857 bounds
Expand Down
15 changes: 2 additions & 13 deletions lib/tiles/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,24 +754,13 @@ export class FeatureTiles {
* @since 2.0.0
*/
simplifyPoints(lineString: any, isPolygon = false): any | null {
const coords = simplify(
lineString.coordinates = simplify(
lineString.coordinates.map(coordinate => {
return { x: coordinate[0], y: coordinate[1] };
}),
this.simplifyToleranceInPixels,
false,
).map(point => [point.x, point.y]);
if (isPolygon) {
if (coords.length < 4) {
return null;
} else if (coords[0][0] !== coords[coords.length - 1][0] || coords[0][1] !== coords[coords.length - 1][1]) {
// if first and last point do not match, add first point to end
coords.push(coords[0].slice());
}
} else if (coords.length < 2) {
return null;
}
lineString.coordinates = coords;
return lineString;
}

Expand All @@ -792,7 +781,7 @@ export class FeatureTiles {
];
});
const simplifiedLineString = this.simplifyGeometries ? this.simplifyPoints(lineString, isPolygon) : lineString;
if (simplifiedLineString.coordinates.length > 0) {
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]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ngageoint/geopackage",
"version": "4.2.1",
"version": "4.2.2",
"description": "GeoPackage JavaScript Library",
"keywords": [
"NGA",
Expand Down

0 comments on commit 30a1fa0

Please sign in to comment.