From 62697c3a1e344a4de0a236bf48042ae138db5620 Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Mon, 2 Oct 2023 10:26:19 +1300 Subject: [PATCH] feat(landing): hard code scanned aerial imagery layers BM-892 (#2970) #### Description The server currently does not provide a full list of tilesets to the client, so some layers need to be hard coded into the layer switcher. #### Intention Adds the new new historical imagery tilesets into the layer switcher dropdown #### Checklist *If not applicable, provide explanation of why.* - [ ] Tests updated - [ ] Docs updated - [x] Issue linked in Title --- .../components/layer.switcher.dropdown.tsx | 33 ++++++------ packages/landing/src/config.map.ts | 54 +++++++++++++------ 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/packages/landing/src/components/layer.switcher.dropdown.tsx b/packages/landing/src/components/layer.switcher.dropdown.tsx index 496a1fb93..18353ca96 100644 --- a/packages/landing/src/components/layer.switcher.dropdown.tsx +++ b/packages/landing/src/components/layer.switcher.dropdown.tsx @@ -5,16 +5,17 @@ import { LayerInfo, MapConfig } from '../config.map.js'; type CategoryMap = Map; -const CategoryOrder = new Map([ - ['Basemaps', 1], - ['Satellite Imagery', 2], - ['Urban Aerial Photos', 3], - ['Rural Aerial Photos', 4], - ['Scanned Aerial Imagery', 5], - ['Event', 6], - ['Bathymetry', 7], - ['Elevation', 8], -]); +const Categories = [ + 'Basemaps', + 'Satellite Imagery', + 'Urban Aerial Photos', + 'Rural Aerial Photos', + 'Scanned Aerial Imagery Basemaps', + 'Scanned Aerial Imagery', + 'Event', + 'Bathymetry', + 'Elevation', +]; export interface GroupedOptions { label: string; @@ -64,6 +65,7 @@ export class LayerSwitcherDropdown extends Component { const layer = f.get(layerId); if (layer == null) return; + if (layer.upperLeft == null || layer.lowerRight == null) return; Config.map.emit('bounds', [layer.upperLeft, layer.lowerRight]); }); } @@ -117,12 +119,11 @@ export class LayerSwitcherDropdown extends Component { - const fallbackOrder = 999; - const orderA = CategoryOrder.get(a[0]) ?? fallbackOrder; - const orderB = CategoryOrder.get(b[0]) ?? fallbackOrder; - if (orderA > orderB) return 1; - if (orderA < orderB) return -1; - return a[0].localeCompare(b[0]); + const orderA = Categories.indexOf(a[0]); + const orderB = Categories.indexOf(b[0]); + if (orderA === orderB) return a[0].localeCompare(b[0]); + if (orderA === -1 || orderA < orderB) return -1; + return 1; }), ); return { options: [...orderedCategories.values()], current: current }; diff --git a/packages/landing/src/config.map.ts b/packages/landing/src/config.map.ts index 74d1e1a42..c3e18e0ba 100644 --- a/packages/landing/src/config.map.ts +++ b/packages/landing/src/config.map.ts @@ -229,8 +229,8 @@ export interface LayerInfo { /** Layer category */ category?: string; /* Bounding box */ - upperLeft: [number, number]; - lowerRight: [number, number]; + upperLeft?: [number, number]; + lowerRight?: [number, number]; /** What projections are enabled for this layer */ projections: Set; } @@ -287,20 +287,44 @@ async function loadAllLayers(): Promise> { return output; } +/** + * The server currently has no way of telling the client the full list of tilesets it could use + * so hard code a few default tilesets with their projections + * + * @param output layers list to add to + */ function addDefaultLayers(output: Map): void { - output.set('aerial', { - id: 'aerial', - name: 'Aerial Imagery', - projections: new Set([EpsgCode.Nztm2000, EpsgCode.Google]), - category: 'Basemaps', - } as LayerInfo); - - output.set('topographic::topographic', { - id: 'topographic::topographic', - name: 'Topographic', - projections: new Set([EpsgCode.Google]), - category: 'Basemaps', - } as LayerInfo); + const layers: LayerInfo[] = [ + { + id: 'aerial', + name: 'Aerial Imagery', + projections: new Set([EpsgCode.Nztm2000, EpsgCode.Google]), + category: 'Basemaps', + }, + + { + id: 'topographic::topographic', + name: 'Topographic', + projections: new Set([EpsgCode.Google]), + category: 'Basemaps', + }, + + { + id: 'scanned-aerial-imagery-pre-1990-01-01', + name: 'Scanned Aerial Imagery pre 1 January 1990', + projections: new Set([EpsgCode.Nztm2000, EpsgCode.Google]), + category: 'Scanned Aerial Imagery Basemaps', + }, + + { + id: 'scanned-aerial-imagery-post-1989-12-31"', + name: 'Scanned Aerial Imagery post 31 December 1989', + projections: new Set([EpsgCode.Nztm2000, EpsgCode.Google]), + category: 'Scanned Aerial Imagery Basemaps', + }, + ]; + + for (const l of layers) output.set(l.id, l); } /** Lookup a projection from either "EPSG:3857" or "WebMercatorQuad" */ function tmsIdToEpsg(id: string): Epsg | null {