import { constants } from '@amsterdam/arm-core' ; import type { LatLngLiteral , LatLngTuple , WMSOptions } from 'leaflet' ; import { PANO_LABELS } from './components/PanoramaViewer/constants' ; import { normalizeCoordinate } from '../../shared/utils/coordinateReferenceSystem' ; import type { UrlParam } from '../../shared/hooks/useParam' ; const { DEFAULT_AMSTERDAM_MAPS_OPTIONS } = constants ; export type BaseLayer = 'topografie' | 'topo_rd_light' | 'topo_rd_zw' | 'lf2019' | 'lf2018' | 'ir2018' | 'lf2017' | 'lf2016' | 'lf2015' | 'lf2014' | 'lf2013' | 'lf2012' | 'lf2011' | 'lf2010' | 'lf2009' | 'lf2008' | 'lf2007' | 'lf2006' | 'lf2005' | 'lf2004' | 'lf2003' ; export interface MapLayer { id : string ; isVisible : boolean ; } export interface Pano { heading : number ; pitch : number ; fov : number ; } export const isEmbeddedParam = { name : 'embed' , defaultValue : false , decode : ( value ) => value === 'true' , encode : ( value ) => value . toString ( ) , } ; export const COORDINATE_PRECISION = 7 ; function encodeLatLngLiteral ( value ) { return [ value . lat , value . lng ] . map ( ( coordinate ) => normalizeCoordinate ( coordinate , COORDINATE_PRECISION ) ) . join ( ',' ) ; } function decodeLatLngLiteral ( value ) { const [ lat , lng ] = value . split ( ',' ) . map ( ( part ) => parseFloat ( part ) ) ; return { lat , lng , } ; } const defaultCenter = DEFAULT_AMSTERDAM_MAPS_OPTIONS . center as LatLngTuple ; export const centerParam = { name : 'center' , defaultValue : { lat : defaultCenter [ 0 ] , lng : defaultCenter [ 1 ] } , decode : decodeLatLngLiteral , encode : encodeLatLngLiteral , } ; export const zoomParam = { name : 'zoom' , defaultValue : DEFAULT_AMSTERDAM_MAPS_OPTIONS . zoom as number , decode : ( value ) => parseInt ( value , 10 ) , encode : ( value ) => value . toString ( ) , } ; export const locationParam = { name : 'locatie' , defaultValue : null , decode : decodeLatLngLiteral , encode : ( value ) => encodeLatLngLiteral ( value ) , } ; export const mapLayersParam = { name : 'lagen' , defaultValue : [ ] , decode : ( value ) => { const cleanedValue = value . replaceAll ( ':1' , '' ) ; return cleanedValue . split ( '|' ) ; } , encode : ( value ) => value . join ( '|' ) , } ; export const legendOpenParam = { name : 'legenda' , defaultValue : false , decode : ( value ) => Boolean ( value === 'true' ) , encode : ( value ) => value . toString ( ) , } ; export const baseLayerParam = { name : 'achtergrond' , defaultValue : 'topografie' , decode : ( value ) => value as BaseLayer , encode : ( value ) => value , } ; export const panoPitchParam = { name : 'pitch' , defaultValue : null , initialValue : 10 , decode : ( value ) => parseFloat ( value ) , encode : ( value ) => value . toString ( ) , } ; export const panoFovParam = { name : 'fov' , defaultValue : null , initialValue : 30 , decode : ( value ) => parseInt ( value , 10 ) , encode : ( value ) => value . toFixed ( 0 ) . toString ( ) , } ; export const panoHeadingParam = { name : 'heading' , defaultValue : null , initialValue : 24 , decode : ( value ) => parseFloat ( value ) , encode : ( value ) => value . toString ( ) , } ; export const panoTagParam = { name : 'tags' , defaultValue : PANO_LABELS [ 0 ] . id , decode : ( value ) => { const matched = PANO_LABELS . find ( ( { id } ) => id === value ) ; if ( matched ) { return matched . id ; } const legacyTags = value . split ( ',' ) ; const legacyMatched = PANO_LABELS . find ( ( { tags } ) => legacyTags . every ( ( tag ) => tags . includes ( tag ) ) ) ; if ( legacyMatched ) { return legacyMatched . id ; } return panoTagParam . defaultValue ; } , encode : ( value ) => value , } ; export interface PolyDrawing { id : string ; polygon : LatLngLiteral [ ] ; } export const polygonParam = { name : 'geo' , defaultValue : null , decode : decodePolyDrawing , encode : ( value ) => encodePolyDrawing ( value ) , } ; export const polylineParam = { name : 'meten' , defaultValue : null , decode : decodePolyDrawing , encode : ( value ) => encodePolyDrawing ( value ) , } ; interface RawPolyDrawing { id : string ; polygon : LatLngTuple [ ] ; } interface RawPolyDrawingLegacy { description : string ; markers : string ; } function decodePolyDrawing ( value ) { const parsedValue = JSON . parse ( value ) ; if ( 'markers' in parsedValue ) { return decodeLegacyPolyDrawing ( parsedValue ) ; } return { id : parsedValue . id , polygon : parsedValue . polygon . map ( ( [ lat , lng ] ) => ( { lat , lng } ) ) , } ; } function encodePolyDrawing ( value ) { const encodedValue = { id : value . id , polygon : value . polygon . map ( ( { lat , lng } ) => [ lat , lng ] ) , } ; return JSON . stringify ( encodedValue ) ; } function decodeLegacyPolyDrawing ( value ) { const id = btoa ( value . description ) ; const polygon = value . markers . split ( '|' ) . map ( ( coordinate ) => { const [ lat , lng ] = coordinate . split ( ':' ) . map ( parseFloat ) ; return { lat , lng } ; } ) ; return { id , polygon , } ; } export const panoFullScreenParam = { name : 'panoFullScreen' , defaultValue : true , decode : ( value ) => value === 'true' , encode : ( value ) => value . toString ( ) , } ; export enum ViewMode { Map = 'kaart' , Split = 'gesplitst' , Full = 'volledig' } export const viewParam = { name : 'modus' , defaultValue : ViewMode . Split , decode : ( value ) => value as ViewMode , encode : ( value ) => value , } ; export interface DataSelectionFilters { [ key ] : string ; } export const dataSelectionFiltersParam = { name : 'filters' , defaultValue : null , decode : ( value ) => { try { return JSON . parse ( value ) ; } catch ( error ) { return null ; } } , encode : ( value ) => JSON . stringify ( value ) , } ; export interface CustomMapLayer { id : string ; title : string ; url : string ; iconUrl : string ; imageRule : string ; layers : string [ ] ; options : WMSOptions ; legendItems ? : Array < { id : string ; title : string ; imageRule : string ; notSelectable : boolean ; } > ; } export const customMapLayer = { name : 'customMapLayer' , defaultValue : null , decode : ( value ) => { try { return JSON . parse ( value ) ; } catch ( error ) { return null ; } } , encode : ( value ) => JSON . stringify ( value ) , } ;