Skip to content

Commit

Permalink
Fix geojson source bbox bug + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nf-s committed Feb 7, 2025
1 parent dac707d commit a73f22e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/Map/Vector/Protomaps/ProtomapsGeojsonSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ export function geojsonVtTileToProtomapsFeatures(
// Multi-polygon
if (Array.isArray(f.geometry[0][0])) {
// Note: the type is incorrect here
const geom = f.geometry as any as [number, number][][];
const geom = f.geometry as unknown as [number, number][][];
transformedGeom = geom.map((g1) =>
g1.map((g2) => {
const x = g2[0];
const y = g2[1];
g2 = [x * scale, y * scale];
const x = g2[0] * scale;
const y = g2[1] * scale;

if (bbox.minX > x) {
bbox.minX = x;
}
Expand Down Expand Up @@ -272,9 +272,8 @@ export function geojsonVtTileToProtomapsFeatures(
const geom = f.geometry as [number, number][];
transformedGeom = [
geom.map((g1) => {
const x = g1[0];
const y = g1[1];
g1 = [x * scale, y * scale];
const x = g1[0] * scale;
const y = g1[1] * scale;

if (bbox.minX > x) {
bbox.minX = x;
Expand Down
7 changes: 7 additions & 0 deletions test/Models/Catalog/CatalogItems/GeoJsonCatalogItemSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,13 @@ describe("GeoJsonCatalogItemSpec", () => {
expect(features.get(GEOJSON_SOURCE_LAYER_NAME)?.length).toEqual(1);
const feature = features.get(GEOJSON_SOURCE_LAYER_NAME)?.[0];
expect(feature?.geom.length).toEqual(4);

expect(feature?.bbox).toEqual({
maxX: 288,
maxY: 204.3125,
minX: -32,
minY: -32
});
});
});

Expand Down

0 comments on commit a73f22e

Please sign in to comment.