-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculation of widget using maps API under FF (#658)
- Loading branch information
Showing
37 changed files
with
603 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import bboxPolygon from '@turf/bbox-polygon'; | ||
import { isGlobalViewport, getGeometryToIntersect } from '../../src/utils/geo'; | ||
|
||
/** @type { import('../../src').Viewport } */ | ||
const viewport = [-10, -10, 10, 10]; // west - south - east - north | ||
const viewportGeometry = bboxPolygon(viewport).geometry; | ||
|
||
/** @type { import('geojson').Polygon } */ | ||
const filterGeometry = { | ||
type: 'Polygon', | ||
coordinates: [ | ||
[ | ||
[-1, -1], | ||
[1, -1], | ||
[1, 1], | ||
[-1, 1], | ||
[-1, -1] | ||
] | ||
] | ||
}; | ||
|
||
describe('isGlobalViewport', () => { | ||
const normalViewports = [ | ||
{ v: null }, | ||
{ v: viewport }, | ||
{ | ||
v: [-344.2596303029739, -75.05112877980663, 230.26452782294038, 75.05112877980655] | ||
}, | ||
{ v: [-125.2596303029739, -85.05112877980663, 230.26452782294038, 85.05112877980655] } | ||
]; | ||
const globalViewports = [ | ||
{ v: [-344.2596303029739, -85.05112877980663, 230.26452782294038, 85.05112877980655] } | ||
]; | ||
|
||
test.each(normalViewports)('return false for normal viewports', ({ v }) => { | ||
expect(!isGlobalViewport(v)); | ||
}); | ||
|
||
test.each(globalViewports)('return true for global viewports', ({ v }) => { | ||
console.log(viewport); | ||
expect(isGlobalViewport(v)); | ||
}); | ||
}); | ||
|
||
describe('getGeometryToIntersect', () => { | ||
test('returns null in case no or invalid viewport or geometry is present', () => { | ||
expect(getGeometryToIntersect(null, null)).toStrictEqual(null); | ||
expect(getGeometryToIntersect([], null)).toStrictEqual(null); | ||
expect(getGeometryToIntersect(null, {})).toStrictEqual(null); | ||
expect(getGeometryToIntersect([], {})).toStrictEqual(null); | ||
}); | ||
|
||
test('returns the viewport as geometry', () => { | ||
expect(getGeometryToIntersect(viewport, null)).toStrictEqual(viewportGeometry); | ||
}); | ||
|
||
test('returns the filter as geometry', () => { | ||
expect(getGeometryToIntersect(null, filterGeometry)).toStrictEqual(filterGeometry); | ||
expect(getGeometryToIntersect(viewport, filterGeometry)).toStrictEqual( | ||
filterGeometry | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
import { TileFeatures, TileFeaturesResponse } from '../types'; | ||
import { Geometry, Feature, Polygon, MultiPolygon } from 'geojson'; | ||
|
||
export function getGeometryToIntersect(viewport: number[], geometry: Geometry | null): Feature<Polygon | MultiPolygon> | null; | ||
export function tileFeatures(arg: TileFeatures): TileFeaturesResponse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum Flags { | ||
REMOTE_WIDGETS = '2023-remote-widgets' | ||
} | ||
export function setFlags(flags: Record<string, any> | string[]): void | ||
export function clearFlags(): void | ||
export function hasFlag(flag: string): boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
let featureFlags = []; | ||
|
||
export const Flags = Object.freeze({ | ||
REMOTE_WIDGETS: '2023-remote-widgets' | ||
}); | ||
|
||
export function setFlags(flags) { | ||
const isValidFlag = (f) => typeof f === 'string' && f; | ||
|
||
if (Array.isArray(flags) && flags.every(isValidFlag)) { | ||
featureFlags = flags; | ||
} else if ( | ||
!Array.isArray(flags) && | ||
typeof flags === 'object' && | ||
Object.keys(flags).every(isValidFlag) | ||
) { | ||
featureFlags = []; | ||
for (const [flag, value] of Object.entries(flags)) { | ||
if (value) { | ||
featureFlags.push(flag); | ||
} | ||
} | ||
} else { | ||
throw new Error(`Invalid feature flags: ${flags}`); | ||
} | ||
} | ||
|
||
export function clearFlags() { | ||
featureFlags = []; | ||
} | ||
|
||
export function hasFlag(flag) { | ||
return featureFlags.includes(flag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Viewport } from '../types'; | ||
import { Polygon, MultiPolygon } from 'geojson'; | ||
|
||
export function getGeometryToIntersect(viewport: Viewport | null, geometry: Polygon | MultiPolygon | null): Polygon | MultiPolygon | null; | ||
|
||
export function isGlobalViewport(viewport: Viewport | null): boolean; |
Oops, something went wrong.