diff --git a/frontend/app/src/app/modules/map/thing-bounds.pipe.spec.ts b/frontend/app/src/app/modules/map/thing-bounds.pipe.spec.ts new file mode 100644 index 00000000..6825cb8e --- /dev/null +++ b/frontend/app/src/app/modules/map/thing-bounds.pipe.spec.ts @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2026 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import {SCGeoInformation} from '@openstapps/core'; +import {LngLatBounds} from 'maplibre-gl'; +import {ThingBoundsPipe} from './thing-bounds.pipe'; + +describe('ThingBoundsPipe', () => { + const pipe = new ThingBoundsPipe(); + const west = 8.6668; + const east = 8.67; + const south = 50.1255; + const north = 50.127; + + it('should return [south-west, north-east] for a polygon', () => { + const geo = { + point: {type: 'Point', coordinates: [8.6684, 50.1262]}, + polygon: { + type: 'Polygon', + coordinates: [ + [ + [west, north], + [east, north], + [east, south], + [west, south], + [west, north], + ], + ], + }, + } as SCGeoInformation; + + expect(pipe.transform(geo)).toEqual([ + [west, south], + [east, north], + ]); + }); + + it('should not cross the antimeridian (MapLibre 6 reads west > east that way)', () => { + const geo = { + point: {type: 'Point', coordinates: [8.6684, 50.1262]}, + polygon: { + type: 'Polygon', + coordinates: [ + [ + [east, south], + [west, north], + [east, north], + [east, south], + ], + ], + }, + } as SCGeoInformation; + + const bounds = LngLatBounds.convert(pipe.transform(geo)); + expect(bounds.getWest()).toBeLessThan(bounds.getEast()); + }); + + it('should return the point twice if there is no polygon', () => { + const geo = {point: {type: 'Point', coordinates: [8.6684, 50.1262]}} as SCGeoInformation; + + expect(pipe.transform(geo)).toEqual([ + [8.6684, 50.1262], + [8.6684, 50.1262], + ]); + }); +}); diff --git a/frontend/app/src/app/modules/map/thing-bounds.pipe.ts b/frontend/app/src/app/modules/map/thing-bounds.pipe.ts index ec05c033..92a05487 100644 --- a/frontend/app/src/app/modules/map/thing-bounds.pipe.ts +++ b/frontend/app/src/app/modules/map/thing-bounds.pipe.ts @@ -13,8 +13,8 @@ export class ThingBoundsPipe implements PipeTransform { const lats = geo.polygon.coordinates[0].map(it => it[1]); return [ - [Math.max(...lngs), Math.max(...lats)], [Math.min(...lngs), Math.min(...lats)], + [Math.max(...lngs), Math.max(...lats)], ]; } else { return [geo.point.coordinates as [number, number], geo.point.coordinates as [number, number]];