mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-10-08 18:51:55 +00:00
@@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -13,8 +13,8 @@ export class ThingBoundsPipe implements PipeTransform {
|
|||||||
const lats = geo.polygon.coordinates[0].map(it => it[1]);
|
const lats = geo.polygon.coordinates[0].map(it => it[1]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[Math.max(...lngs), Math.max(...lats)],
|
|
||||||
[Math.min(...lngs), Math.min(...lats)],
|
[Math.min(...lngs), Math.min(...lats)],
|
||||||
|
[Math.max(...lngs), Math.max(...lats)],
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return [geo.point.coordinates as [number, number], geo.point.coordinates as [number, number]];
|
return [geo.point.coordinates as [number, number], geo.point.coordinates as [number, number]];
|
||||||
|
|||||||
Reference in New Issue
Block a user