From 1e29779e6811cfa77a0109ad7b41dd61eda75f55 Mon Sep 17 00:00:00 2001 From: Pascal Barth Date: Fri, 30 Jan 2026 11:20:53 +0100 Subject: [PATCH 1/3] PB-2064: fix drawing test --- .../tests/cypress/support/drawing.ts | 32 ++++++++------- .../tests/cypress/tests-e2e/drawing.cy.ts | 39 ++++++++----------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/packages/mapviewer/tests/cypress/support/drawing.ts b/packages/mapviewer/tests/cypress/support/drawing.ts index fbe89d1455..d107d94f5d 100644 --- a/packages/mapviewer/tests/cypress/support/drawing.ts +++ b/packages/mapviewer/tests/cypress/support/drawing.ts @@ -21,12 +21,18 @@ function transformHeaders(headers: { [key: string]: string | string[] }): Header } export function addIconFixtureAndIntercept(): void { - cy.intercept(`**/api/icons/sets/default/icons/**${featureStyleUtils.generateRGBFillString(featureStyleUtils.RED)}.png`, { - fixture: 'service-icons/placeholder.png', - }).as('icon-default') - cy.intercept(`**/api/icons/sets/default/icons/**${featureStyleUtils.generateRGBFillString(featureStyleUtils.GREEN)}.png`, { - fixture: 'service-icons/placeholder.png', - }).as('icon-default-green') + cy.intercept( + `**/api/icons/sets/default/icons/**${featureStyleUtils.generateRGBFillString(featureStyleUtils.RED)}.png`, + { + fixture: 'service-icons/placeholder.png', + } + ).as('icon-default') + cy.intercept( + `**/api/icons/sets/default/icons/**${featureStyleUtils.generateRGBFillString(featureStyleUtils.GREEN)}.png`, + { + fixture: 'service-icons/placeholder.png', + } + ).as('icon-default-green') cy.intercept(`**/api/icons/sets/babs/icons/*@*.png`, { fixture: 'service-icons/placeholder.png', }).as('icon-babs') @@ -52,7 +58,9 @@ function addProfileFixtureAndIntercept(): void { }).as('profileAsCsv') } -async function handlePostKmlRequest(req: CyHttpMessages.IncomingHttpRequest): Promise { +async function handlePostKmlRequest( + req: CyHttpMessages.IncomingHttpRequest +): Promise { try { return await getKmlFromRequest(req) } catch (error) { @@ -266,17 +274,15 @@ Cypress.Commands.add('goToDrawing', (queryParams = {}, withHash = true) => { const drawingStore = useDrawingStore(pinia) expect(drawingStore.overlay.show).to.be.true }) - cy.waitUntilState((pinia) => { - const drawingStore = useDrawingStore(pinia) - return drawingStore.iconSets.length > 0 - }) + // it should load all icon sets as soon as we enter the drawing module + cy.wait('@icon-sets') + cy.wait('@icon-set-default') }) Cypress.Commands.add('openDrawingMode', () => { cy.openMenuIfMobile() cy.get('[data-cy="menu-tray-drawing-section"]:visible').click() - // Make sure that the map pointer events are unregistered to avoid interference with drawing - // pointer events + // Make sure that the map pointer events are unregistered to avoid interference with drawing pointer events cy.window().its('mapPointerEventReady').should('be.false') }) diff --git a/packages/mapviewer/tests/cypress/tests-e2e/drawing.cy.ts b/packages/mapviewer/tests/cypress/tests-e2e/drawing.cy.ts index 28d1f94fff..7d0e262dc7 100644 --- a/packages/mapviewer/tests/cypress/tests-e2e/drawing.cy.ts +++ b/packages/mapviewer/tests/cypress/tests-e2e/drawing.cy.ts @@ -22,7 +22,7 @@ import { kmlMetadataTemplate, } from 'support/drawing' -import { DEFAULT_PROJECTION } from '@/config' +import { DEFAULT_PROJECTION, ENVIRONMENT } from '@/config' import useDrawingStore from '@/store/modules/drawing' import useFeaturesStore from '@/store/modules/features' import useLayersStore from '@/store/modules/layers' @@ -129,15 +129,11 @@ describe('Drawing module tests', () => { cy.goToDrawing() }) it('can create marker/icons and edit them', () => { - // it should load all icon sets as soon as we enter the drawing module - cy.wait('@icon-sets') - cy.wait('@icon-set-default') - cy.clickDrawingTool('MARKER') cy.get('[data-cy="ol-map"]:visible').click() cy.wait('@post-kml').then((interception) => { - const kmlUrl = `${getServiceKmlBaseUrl()}api/kml/files/${interception.response?.body.id}` + const kmlUrl = `${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${interception.response?.body.id}` const bgLayer = 'test.background.layer2' cy.log( @@ -250,7 +246,7 @@ describe('Drawing module tests', () => { cy.log('Test text placement and offset') cy.get('[data-cy="drawing-style-text-button"]').click() cy.get('[data-cy="drawing-style-placement-selector-top-left"]').click() - cy.getPinia().then((pinia) => { + cy.getPinia().should((pinia) => { const drawingStore = useDrawingStore(pinia) expect(drawingStore.feature.current?.textPlacement).to.eq('top-left') const offset = drawingStore.feature.current?.textOffset @@ -279,12 +275,9 @@ describe('Drawing module tests', () => { description ) waitForKmlUpdate(`${description}`) - cy.getPinia().then((pinia) => { - const featuresStore2 = useFeaturesStore(pinia) - cy.wrap(featuresStore2.selectedFeatures[0]?.description).should( - 'eq', - description - ) + cy.getPinia().should((pinia) => { + const featuresStore = useFeaturesStore(pinia) + expect(featuresStore.selectedFeatures[0]?.description).to.eq(description) }) cy.log('Can generate and display media links') @@ -1010,7 +1003,7 @@ describe('Drawing module tests', () => { cy.log(`Check that the drawings has been added to the active layers: ${kmlId}`) cy.get( - `[data-cy^="active-layer-name-${getServiceKmlBaseUrl()}api/kml/files/${kmlId}-"]` + `[data-cy^="active-layer-name-${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${kmlId}-"]` ) .should('be.visible') .contains('Drawing') @@ -1030,7 +1023,7 @@ describe('Drawing module tests', () => { cy.log(`Check that the KML file ${kmlId} is present on the active layer list`) cy.get( - `[data-cy^="active-layer-name-${getServiceKmlBaseUrl()}api/kml/files/${kmlId}-"]` + `[data-cy^="active-layer-name-${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${kmlId}-"]` ) .should('be.visible') .contains('Drawing') @@ -1049,7 +1042,7 @@ describe('Drawing module tests', () => { // if closing the drawing module without changing anything, no copy must be made cy.closeDrawingMode() cy.get( - `[data-cy^="active-layer-name-${getServiceKmlBaseUrl()}api/kml/files/${kmlId}-"]` + `[data-cy^="active-layer-name-${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${kmlId}-"]` ) .should('be.visible') .contains('Drawing') @@ -1092,10 +1085,10 @@ describe('Drawing module tests', () => { `Check that the old kml has been removed from the active layer and that the new one has been added` ) cy.get( - `[data-cy^="active-layer-name-${getServiceKmlBaseUrl()}api/kml/files/${kmlId}-"]` + `[data-cy^="active-layer-name-${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${kmlId}-"]` ).should('not.exist') cy.get( - `[data-cy^="active-layer-name-${getServiceKmlBaseUrl()}api/kml/files/${newNewKmlId}-"]` + `[data-cy^="active-layer-name-${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${newNewKmlId}-"]` ) .should('be.visible') .contains('Drawing') @@ -1115,7 +1108,7 @@ describe('Drawing module tests', () => { // load map with an injected kml layer containing a text const kmlFileId = 'test-fileID12345678900' const kmlFileAdminId = 'test-fileAdminID12345678900' - const kmlFileUrl = `${getServiceKmlBaseUrl()}api/kml/files/${kmlFileId}` + const kmlFileUrl = `${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${kmlFileId}` const kmlUrlParam = `KML|${kmlFileUrl}@adminId=${kmlFileAdminId}` cy.log( @@ -1173,8 +1166,8 @@ describe('Drawing module tests', () => { // load map with an injected kml layer containing a text const kmlFileId = 'test-fileID12345678900' const kmlFileAdminId = 'test-fileAdminID12345678900' - const kmlFileUrl = `${getServiceKmlBaseUrl()}api/kml/files/${kmlFileId}` - const kmlAdminUrl = `${getServiceKmlBaseUrl()}api/kml/admin/${kmlFileId}` + const kmlFileUrl = `${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${kmlFileId}` + const kmlAdminUrl = `${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/admin/${kmlFileId}` const kmlMetadata = { admin_id: kmlFileAdminId, author: 'mf-geoadmin3', @@ -1569,7 +1562,7 @@ describe('Drawing module tests', () => { ) cy.readClipboardValue().should((clipboardText) => { expect(clipboardText).to.contain( - `KML%7C${getServiceKmlBaseUrl()}api/kml/files/${kmlId}` + `KML%7C${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${kmlId}` ) expect(clipboardText).to.not.contain(`@adminId`) }) @@ -1578,7 +1571,7 @@ describe('Drawing module tests', () => { cy.get('[data-cy="drawing-share-admin-link"]').realClick() cy.readClipboardValue().should((clipboardText) => { expect(clipboardText).to.contain( - `KML%7C${getServiceKmlBaseUrl()}api/kml/files/${kmlId}` + `KML%7C${getServiceKmlBaseUrl(ENVIRONMENT)}api/kml/files/${kmlId}` ) expect(clipboardText).to.contain(`@adminId=${adminId}`) }) From 641339661a0fb90f8ec1f04cf82aa1cbe8b3ed3f Mon Sep 17 00:00:00 2001 From: Pascal Barth Date: Fri, 27 Feb 2026 11:49:43 +0100 Subject: [PATCH 2/3] PB-2064: remove all TS enums expect in @swissgeo/logs, where I find it doesn't really make sense to have something else here (especially with colors). --- packages/api/src/features.ts | 8 +- packages/api/src/search.ts | 5 +- .../__tests__/legacyLayerParamUtils.spec.ts | 7 +- packages/api/src/utils/kmlUtils.ts | 3 +- .../api/src/utils/legacyLayerParamUtils.ts | 8 +- .../staging/src/constants/print.config.ts | 10 +-- .../layers/src/api/__test__/internal.spec.ts | 4 +- packages/layers/src/api/internal.ts | 12 +-- .../src/parsers/WMTSCapabilitiesParser.ts | 6 +- packages/layers/src/types/layers.ts | 57 +++++++------- .../utils/__test__/timeConfigUtils.spec.ts | 3 +- packages/layers/src/utils/layerUtils.ts | 43 +++++------ packages/layers/src/utils/timeConfigUtils.ts | 20 ++--- .../check-external-layers-providers.ts | 5 +- .../src/modules/drawing/DrawingModule.vue | 8 +- .../drawing/components/AddVertexButton.vue | 3 +- .../components/DrawingInteractions.vue | 7 +- .../drawing/components/DrawingToolbox.vue | 15 ++-- .../useDrawingModeInteraction.composable.ts | 3 +- .../useModifyInteraction.composable.ts | 13 +--- .../modules/drawing/lib/modifyInteraction.ts | 19 ++--- .../components/ShowGeometryProfileButton.vue | 3 +- .../modules/map/components/CompareSlider.vue | 3 +- .../cesium/CesiumHighlightedFeatures.vue | 7 +- .../components/cesium/CesiumInteractions.vue | 18 ++--- .../components/cesium/CesiumInternalLayer.vue | 17 ++-- .../components/cesium/CesiumVisibleLayers.vue | 5 +- .../map/components/cesium/CesiumWMTSLayer.vue | 3 +- .../components/common/z-index.composable.ts | 8 +- .../openlayers/OpenLayersCrossHair.vue | 26 +++---- .../OpenLayersGeolocationFeedback.vue | 3 +- .../OpenLayersHighlightedFeatures.vue | 15 ++-- .../openlayers/OpenLayersInternalLayer.vue | 21 +++-- .../openlayers/OpenLayersMarker.vue | 9 ++- .../openlayers/OpenLayersPinnedLocation.vue | 5 +- .../openlayers/utils/markerStyle.ts | 49 ++++++------ .../utils/useDragBoxSelect.composable.ts | 12 ++- .../utils/useMapInteractions.composable.ts | 13 ++-- .../menu/components/LayerCatalogueItem.vue | 5 +- .../activeLayers/MenuActiveLayersListItem.vue | 32 ++++---- .../ImportCatalogue/NodeType.enum.ts | 5 -- .../ImportCatalogue/ProviderList.vue | 31 ++++---- .../components/debug/DebugLayerFinder.vue | 5 +- .../components/help/ReportProblemButton.vue | 11 ++- .../components/menu/MenuDrawingSection.vue | 9 +-- .../drawing/actions/clearDrawingFeatures.ts | 4 +- .../modules/drawing/actions/closeDrawing.ts | 17 ++-- .../drawing/actions/deleteCurrentDrawing.ts | 3 +- .../drawing/actions/initiateDrawing.ts | 3 +- .../actions/setCurrentlyDrawnFeature.ts | 5 +- .../modules/drawing/actions/setEditingMode.ts | 6 +- .../actions/updateCurrentDrawingFeature.ts | 7 +- .../drawing/getters/isDrawingModified.ts | 8 +- .../getters/showNotSharedDrawingWarning.ts | 7 +- .../src/store/modules/drawing/index.ts | 7 +- .../src/store/modules/drawing/types.ts | 77 ++++++++++--------- .../utils/addKmlFeaturesToDrawingLayer.ts | 5 +- .../drawing/utils/debounceSaveDrawing.ts | 13 ++-- .../modules/drawing/utils/isOnlineMode.ts | 8 +- .../modules/layers/actions/removeLayer.ts | 4 +- .../layers/actions/setKmlGpxLayerData.ts | 8 +- .../modules/layers/actions/setPreviewLayer.ts | 3 +- .../modules/layers/getters/activeKmlLayer.ts | 4 +- .../layers/getters/hasDataDisclaimer.ts | 3 +- .../modules/layers/getters/isLocalFile.ts | 4 +- .../modules/layers/getters/visibleLayers.ts | 5 +- .../layers/utils/afterAddOperations.ts | 9 +-- .../layers/utils/cloneActiveLayerConfig.ts | 3 +- .../layers/utils/loadLayerFromCapabilities.ts | 8 +- .../src/store/modules/map/actions/click.ts | 17 ++-- .../mapviewer/src/store/modules/map/types.ts | 22 +++--- .../modules/position/actions/setCrossHair.ts | 10 +-- .../src/store/modules/position/types.ts | 11 +-- .../search/actions/selectResultEntry.ts | 5 +- .../ui/actions/setFeatureInfoPosition.ts | 4 +- .../src/store/modules/ui/actions/setSize.ts | 10 +-- .../src/store/modules/ui/actions/setUiMode.ts | 16 +--- .../store/modules/ui/getters/isDesktopMode.ts | 4 +- .../modules/ui/getters/isMenuTrayShown.ts | 4 +- .../store/modules/ui/getters/isPhoneMode.ts | 4 +- .../ui/getters/showFeatureInfoInTooltip.ts | 2 +- .../mapviewer/src/store/modules/ui/index.ts | 3 +- .../mapviewer/src/store/modules/ui/types.ts | 11 +-- .../__tests__/LayerParamConfig.class.spec.ts | 17 ++-- .../__tests__/layersParamParser.spec.ts | 12 +-- .../plugins/storeSync/layersParamParser.ts | 27 ++++--- .../storeSync/params/crosshair.param.ts | 28 ++----- .../storeSync/params/featureInfo.param.ts | 4 +- .../plugins/storeSync/params/layers.param.ts | 28 +++---- .../src/utils/__tests__/utils.spec.ts | 27 ------- packages/mapviewer/src/utils/layerUtils.ts | 3 +- packages/mapviewer/src/utils/utils.ts | 28 ------- packages/mapviewer/src/views/MapView.vue | 34 ++++---- .../tests/cypress/tests-e2e/3d/click.cy.ts | 4 +- .../tests/cypress/tests-e2e/crosshair.cy.ts | 29 ++++--- .../tests/cypress/tests-e2e/drawing.cy.ts | 16 ++-- .../cypress/tests-e2e/featureSelection.cy.ts | 4 +- .../tests/cypress/tests-e2e/footer.cy.ts | 3 +- .../cypress/tests-e2e/importToolFile.cy.ts | 3 +- .../tests/cypress/tests-e2e/layers.cy.ts | 5 +- .../cypress/tests-e2e/legacyParamImport.cy.ts | 9 +-- .../tests-e2e/search/search-results.cy.ts | 13 ++-- 102 files changed, 499 insertions(+), 713 deletions(-) delete mode 100644 packages/mapviewer/src/modules/menu/components/advancedTools/ImportCatalogue/NodeType.enum.ts diff --git a/packages/api/src/features.ts b/packages/api/src/features.ts index 085623c000..2ff64c51cc 100644 --- a/packages/api/src/features.ts +++ b/packages/api/src/features.ts @@ -6,7 +6,7 @@ import type Feature from 'ol/Feature' import type { LineString, MultiLineString, MultiPolygon, Point, Polygon } from 'ol/geom' import { allCoordinateSystems, extentUtils, LV95 } from '@swissgeo/coordinates' -import { ALL_YEARS_TIMESTAMP, CURRENT_YEAR_TIMESTAMP, LayerType } from '@swissgeo/layers' +import { ALL_YEARS_TIMESTAMP, CURRENT_YEAR_TIMESTAMP } from '@swissgeo/layers' import { geoJsonUtils, layerUtils } from '@swissgeo/layers/utils' import log from '@swissgeo/log' import { getApi3BaseUrl } from '@swissgeo/staging-config' @@ -236,7 +236,7 @@ async function identifyOnExternalLayer(config: IdentifyConfig): Promise { - if (currentLayer.type === LayerType.KML) { + if (currentLayer.type === 'KML') { const kmlLayer = currentLayer as KMLLayer return returnLayers.concat( searchFeatures( @@ -338,7 +337,7 @@ function searchLayerFeaturesKMLGPX( ) ) } - if (currentLayer.type === LayerType.GPX) { + if (currentLayer.type === 'GPX') { const gpxLayer = currentLayer as GPXLayer const gpxData = gpxLayer.gpxData if (!gpxData) { diff --git a/packages/api/src/utils/__tests__/legacyLayerParamUtils.spec.ts b/packages/api/src/utils/__tests__/legacyLayerParamUtils.spec.ts index 8f88b10ab8..755664c40f 100644 --- a/packages/api/src/utils/__tests__/legacyLayerParamUtils.spec.ts +++ b/packages/api/src/utils/__tests__/legacyLayerParamUtils.spec.ts @@ -1,6 +1,5 @@ import type { ExternalWMSLayer, GeoAdminLayer, Layer } from '@swissgeo/layers' -import { LayerType } from '@swissgeo/layers' import { layerUtils, timeConfigUtils } from '@swissgeo/layers/utils' import { describe, expect, it } from 'vitest' @@ -162,7 +161,7 @@ describe('Test parsing of legacy URL param into new params', () => { expect(result).to.be.an('Array').length(1) const [kmlLayer] = result expect(kmlLayer.id).to.eq(`KML|${kmlFileUrl}`) - expect(kmlLayer.type).to.eq(LayerType.KML) + expect(kmlLayer.type).to.eq('KML') expect(kmlLayer.baseUrl).to.eq(kmlFileUrl) }) it('Handles opacity/visibility correctly with external layers', () => { @@ -194,7 +193,7 @@ describe('Test parsing of legacy URL param into new params', () => { ) expect(result).to.be.an('Array').length(1) const [externalWmsLayer] = result - expect(externalWmsLayer.type).to.eq(LayerType.WMS) + expect(externalWmsLayer.type).to.eq('WMS') expect(externalWmsLayer.opacity).to.eq(0.45) expect((externalWmsLayer as ExternalWMSLayer).wmsVersion).to.eq(wmsVersion) expect(externalWmsLayer.id).to.eq(wmsLayerId) @@ -216,7 +215,7 @@ describe('Test parsing of legacy URL param into new params', () => { ) expect(result).to.be.an('Array').length(1) const [externalWmtsLayer] = result - expect(externalWmtsLayer.type).to.eq(LayerType.WMTS) + expect(externalWmtsLayer.type).to.eq('WMTS') expect(externalWmtsLayer.opacity).to.eq(0.77) expect(externalWmtsLayer.isVisible).to.be.false expect(externalWmtsLayer.id).to.eq(wmtsLayerId) diff --git a/packages/api/src/utils/kmlUtils.ts b/packages/api/src/utils/kmlUtils.ts index 489b07359a..3e604642a8 100644 --- a/packages/api/src/utils/kmlUtils.ts +++ b/packages/api/src/utils/kmlUtils.ts @@ -9,7 +9,6 @@ import type { Size } from 'ol/size' import type Style from 'ol/style/Style' import { registerProj4, WGS84 } from '@swissgeo/coordinates' -import { KMLStyle } from '@swissgeo/layers' import log, { LogPreDefinedColor } from '@swissgeo/log' import { DEFAULT_TITLE_OFFSET, @@ -776,7 +775,7 @@ function parseKml( featureProjection: projection.epsg, }) - if (kmlLayer.style === KMLStyle.GEOADMIN) { + if (kmlLayer.style === 'GEOADMIN') { features.forEach((olFeature) => { const editableFeature = getEditableFeatureFromKmlFeature( olFeature, diff --git a/packages/api/src/utils/legacyLayerParamUtils.ts b/packages/api/src/utils/legacyLayerParamUtils.ts index 9e4dae0011..ff4c9c889a 100644 --- a/packages/api/src/utils/legacyLayerParamUtils.ts +++ b/packages/api/src/utils/legacyLayerParamUtils.ts @@ -1,7 +1,6 @@ import type { GeoAdminLayer, KMLLayer, Layer } from '@swissgeo/layers' import type { Staging } from '@swissgeo/staging-config' -import { KMLStyle } from '@swissgeo/layers' import { layerUtils, timeConfigUtils } from '@swissgeo/layers/utils' import log from '@swissgeo/log' @@ -114,7 +113,7 @@ function getLayersFromLegacyUrlParams( layer = layerUtils.makeKMLLayer({ kmlFileUrl: url, isVisible: true, - style: KMLStyle.GEOADMIN, + style: 'GEOADMIN', }) } if (layerId.startsWith('GPX||')) { @@ -219,7 +218,10 @@ function getBackgroundLayerFromLegacyUrlParams( * @param adminId KML admin ID * @returns KML Layer */ -async function getKmlLayerFromLegacyAdminIdParam(adminId: string, staging: Staging = 'production'): Promise { +async function getKmlLayerFromLegacyAdminIdParam( + adminId: string, + staging: Staging = 'production' +): Promise { const kmlMetadata = await filesAPI.getKmlMetadataByAdminId(adminId, staging) return layerUtils.makeKMLLayer({ kmlFileUrl: kmlMetadata.links.kml, diff --git a/packages/config/staging/src/constants/print.config.ts b/packages/config/staging/src/constants/print.config.ts index 36018b28a1..b0d162408c 100644 --- a/packages/config/staging/src/constants/print.config.ts +++ b/packages/config/staging/src/constants/print.config.ts @@ -6,15 +6,7 @@ export const PRINT_DPI_COMPENSATION: number = 144 //So when there is a non 0 scale, we set its minimum to 0.0001 export const MIN_PRINT_SCALE_SIZE: number = 0.0001 -export enum PrintLayout { - A0 = 'A0', - A1 = 'A1', - A2 = 'A2', - A3 = 'A3', - A4 = 'A4', - A5 = 'A5', - A6 = 'A6', -} +export type PrintLayout = 'A0' | 'A1' | 'A2' | 'A3' | 'A4' | 'A5' | 'A6' /** Dimensions in mm of the viewport for each print format */ export const PRINT_DIMENSIONS: Record = { diff --git a/packages/layers/src/api/__test__/internal.spec.ts b/packages/layers/src/api/__test__/internal.spec.ts index a847d7eb15..36da2d2876 100644 --- a/packages/layers/src/api/__test__/internal.spec.ts +++ b/packages/layers/src/api/__test__/internal.spec.ts @@ -9,7 +9,7 @@ import type { } from '@/types' import { generateLayerObject } from '@/api' -import { LayerType, YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA } from '@/types' +import { YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA } from '@/types' import rawLayerConfig from './rawLayerConfig.json' @@ -251,7 +251,7 @@ describe('Test layer config parsing', () => { const layer = parseLayer(layerId) expect(layer).to.not.be.undefined - expect(layer.type).to.eq(LayerType.GEOJSON) + expect(layer.type).to.eq('GEOJSON') const geoJsonLayer = layer as GeoAdminGeoJSONLayer expect(geoJsonLayer.geoJsonUrl).to.eq( diff --git a/packages/layers/src/api/internal.ts b/packages/layers/src/api/internal.ts index c7f3eb29db..56569d1270 100644 --- a/packages/layers/src/api/internal.ts +++ b/packages/layers/src/api/internal.ts @@ -14,7 +14,6 @@ import type { } from '@/index' import { DEFAULT_GEOADMIN_MAX_WMTS_RESOLUTION } from '@/config' -import { LayerType } from '@/index' import { layerUtils, timeConfigUtils } from '@/utils' export interface LayerConfigResponse { @@ -150,7 +149,7 @@ export function generateLayerObject( break case 'wmts': { return layerUtils.makeGeoAdminWMTSLayer({ - type: LayerType.WMTS, + type: 'WMTS', name, id, baseUrl: _urlWithTrailingSlash(getWmtsBaseUrl(staging)), @@ -173,7 +172,7 @@ export function generateLayerObject( } case 'wms': { return layerUtils.makeGeoAdminWMSLayer({ - type: LayerType.WMS, + type: 'WMS', name, id: id, idIn3d: layerConfig.config3d, @@ -197,7 +196,7 @@ export function generateLayerObject( } case 'geojson': { return layerUtils.makeGeoAdminGeoJSONLayer({ - type: LayerType.GEOJSON, + type: 'GEOJSON', name, id, opacity, @@ -250,10 +249,7 @@ export function generateLayerObject( lang, staging ) - if ( - subLayer && - (subLayer.type === LayerType.WMS || subLayer.type === LayerType.WMTS) - ) { + if (subLayer && (subLayer.type === 'WMS' || subLayer.type === 'WMTS')) { subLayers.push( layerUtils.makeAggregateSubLayer({ subLayerId, diff --git a/packages/layers/src/parsers/WMTSCapabilitiesParser.ts b/packages/layers/src/parsers/WMTSCapabilitiesParser.ts index a7ea1e6391..2fcc82ed98 100644 --- a/packages/layers/src/parsers/WMTSCapabilitiesParser.ts +++ b/packages/layers/src/parsers/WMTSCapabilitiesParser.ts @@ -23,10 +23,10 @@ import type { WMTSLegendURL, WMTSOnlineResource, WMTSTileMatrixSetLink, + WMTSEncodingType, } from '@/types' import type { TileMatrix } from '@/types/layers' -import { LayerType, WMTSEncodingType } from '@/types' import layerUtils from '@/utils/layerUtils' import timeConfigUtils from '@/utils/timeConfigUtils' import { CapabilitiesError } from '@/validation' @@ -331,7 +331,7 @@ function getLayerAttributes( getCapUrl = capabilities.originUrl.toString() } - let getTileEncoding: WMTSEncodingType = WMTSEncodingType.REST + let getTileEncoding: WMTSEncodingType = 'REST' if ( capabilities.OperationsMetadata && 'GetTile' in capabilities.OperationsMetadata && @@ -471,7 +471,7 @@ function getExternalLayer( } return layerUtils.makeExternalWMTSLayer({ - type: LayerType.WMTS, + type: 'WMTS', ...attributes, opacity, isVisible, diff --git a/packages/layers/src/types/layers.ts b/packages/layers/src/types/layers.ts index 1744067491..d222e761b2 100644 --- a/packages/layers/src/types/layers.ts +++ b/packages/layers/src/types/layers.ts @@ -11,17 +11,18 @@ export type * from '@/types/geoJsonStyle' export const DEFAULT_OPACITY = 1.0 export const WMS_SUPPORTED_VERSIONS = ['1.3.0'] -export enum LayerType { - WMTS = 'WMTS', - WMS = 'WMS', - GEOJSON = 'GEOJSON', - AGGREGATE = 'AGGREGATE', - KML = 'KML', - GPX = 'GPX', - VECTOR = 'VECTOR', - GROUP = 'GROUP', - COG = 'COG', -} +export const LayerTypes = [ + 'WMTS', + 'WMS', + 'GEOJSON', + 'AGGREGATE', + 'KML', + 'GPX', + 'VECTOR', + 'GROUP', + 'COG', +] as const +export type LayerType = (typeof LayerTypes)[number] export interface LayerAttribution { name: string @@ -154,7 +155,7 @@ export interface GeoAdminLayer extends Layer { /** Represent a WMS Layer from geo.admin.ch */ export interface GeoAdminWMSLayer extends GeoAdminLayer { - readonly type: LayerType.WMS + readonly type: 'WMS' /** * How much of a gutter (extra pixels around the image) we want. This is specific for tiled WMS, * if unset this layer will be a considered a single tile WMS. @@ -173,7 +174,7 @@ export interface GeoAdminWMSLayer extends GeoAdminLayer { /** Represent a WMTS layer from geo.admin.ch */ export interface GeoAdminWMTSLayer extends GeoAdminLayer { - readonly type: LayerType.WMTS + readonly type: 'WMTS' /** Define the maximum resolution the layer can reach */ readonly maxResolution: number /** In which image format the backend must be requested. */ @@ -181,7 +182,7 @@ export interface GeoAdminWMTSLayer extends GeoAdminLayer { } export interface GeoAdmin3DLayer extends GeoAdminLayer { - readonly type: LayerType.VECTOR + readonly type: 'VECTOR' /* If the JSON file stored in the /3d-tiles/ sub-folder on the S3 bucket */ readonly use3dTileSubFolder: boolean /** @@ -193,7 +194,7 @@ export interface GeoAdmin3DLayer extends GeoAdminLayer { } export interface GeoAdminGeoJSONLayer extends GeoAdminLayer { - readonly type: LayerType.GEOJSON + readonly type: 'GEOJSON' /** * Delay after which the data of this layer should be re-requested (if null is given, no further * data reload will be triggered). A good example would be layer @@ -209,7 +210,7 @@ export interface GeoAdminGeoJSONLayer extends GeoAdminLayer { } export interface GeoAdminVectorLayer extends GeoAdminLayer { - readonly type: LayerType.VECTOR + readonly type: 'VECTOR' } // #endregion @@ -221,7 +222,7 @@ export interface FileLayer extends Layer { } export interface CloudOptimizedGeoTIFFLayer extends FileLayer { - readonly type: LayerType.COG + readonly type: 'COG' readonly fileSource?: string /** Data/content of the COG file, as a string. */ data?: string | Blob @@ -274,13 +275,10 @@ export interface KMLMetadata { readonly links: KMLMetadataLinks } -export enum KMLStyle { - DEFAULT = 'DEFAULT', - GEOADMIN = 'GEOADMIN', -} +export type KMLStyle = 'DEFAULT' | 'GEOADMIN' export interface KMLLayer extends FileLayer { - readonly type: LayerType.KML + readonly type: 'KML' /** The URL to access the KML data. */ kmlFileUrl: string /** @@ -355,7 +353,7 @@ export interface GPXMetadata { } export interface GPXLayer extends FileLayer { - readonly type: LayerType.GPX + readonly type: 'GPX' /** URL to the GPX file (can also be a local file URI) */ readonly gpxFileUrl?: string /** Data/content of the GPX file, as a string. */ @@ -407,10 +405,7 @@ export interface BoundingBox { readonly dimensions?: number } -export enum WMTSEncodingType { - KVP = 'KVP', - REST = 'REST', -} +export type WMTSEncodingType = 'KVP' | 'REST' /** Configuration describing how to request this layer's server to get feature information. */ export interface ExternalLayerGetFeatureInfoCapability { @@ -435,7 +430,7 @@ export interface ExternalLayer extends Layer { } export interface ExternalWMTSLayer extends ExternalLayer { - readonly type: LayerType.WMTS + readonly type: 'WMTS' /** WMTS Get Capabilities options */ readonly options?: Partial /** WMTS Get Tile encoding (KVP or REST). */ @@ -452,7 +447,7 @@ export interface ExternalWMTSLayer extends ExternalLayer { } export interface ExternalWMSLayer extends ExternalLayer { - readonly type: LayerType.WMS + readonly type: 'WMS' /** * Description of the layers being part of this WMS layer (they will all be displayed at the * same time, in contrast to an aggregate layer) @@ -482,12 +477,12 @@ export interface AggregateSubLayer { } export interface GeoAdminAggregateLayer extends GeoAdminLayer { - readonly type: LayerType.AGGREGATE + readonly type: 'AGGREGATE' readonly subLayers: AggregateSubLayer[] } export interface GeoAdminGroupOfLayers extends GeoAdminLayer { - readonly type: LayerType.GROUP + readonly type: 'GROUP' /** Description of the layers being part of this group */ readonly layers: GeoAdminLayer[] } diff --git a/packages/layers/src/utils/__test__/timeConfigUtils.spec.ts b/packages/layers/src/utils/__test__/timeConfigUtils.spec.ts index bbc7841099..a2cad7bfbe 100644 --- a/packages/layers/src/utils/__test__/timeConfigUtils.spec.ts +++ b/packages/layers/src/utils/__test__/timeConfigUtils.spec.ts @@ -3,7 +3,6 @@ import { describe, it } from 'vitest' import type { Layer } from '@/types/layers' -import { LayerType } from '@/types/layers' import timeConfigUtils from '@/utils/timeConfigUtils' describe('Test utility functions', () => { @@ -14,7 +13,7 @@ describe('Test utility functions', () => { id: 'ch.bgdi.simple', opacity: 0, isVisible: true, - type: LayerType.WMTS, + type: 'WMTS', attributions: [], hasTooltip: false, hasDescription: false, diff --git a/packages/layers/src/utils/layerUtils.ts b/packages/layers/src/utils/layerUtils.ts index 1593557904..e3a3c76776 100644 --- a/packages/layers/src/utils/layerUtils.ts +++ b/packages/layers/src/utils/layerUtils.ts @@ -20,12 +20,13 @@ import type { GeoAdminWMTSLayer, GPXLayer, KMLLayer, + KMLStyle, Layer, LayerAttribution, } from '@/types/layers' import { DEFAULT_GEOADMIN_MAX_WMTS_RESOLUTION } from '@/config' -import { DEFAULT_OPACITY, KMLStyle, LayerType, WMTSEncodingType } from '@/types/layers' +import { DEFAULT_OPACITY } from '@/types/layers' import timeConfigUtils from '@/utils/timeConfigUtils' import { InvalidLayerDataError } from '@/validation' @@ -33,10 +34,6 @@ export const EMPTY_KML_DATA = '' const ENC_PIPE = '%7C' -function transformToLayerTypeEnum(value: string): LayerType | undefined { - return Object.values(LayerType).includes(value as LayerType) ? (value as LayerType) : undefined -} - /** * Determine if a file URL is a local file or a remote URL. * @@ -84,7 +81,7 @@ function makeGeoAdminWMSLayer(values: Partial): GeoAdminWMSLay const defaults: DefaultLayerConfig = { uuid: uuidv4(), isExternal: false, - type: LayerType.WMS, + type: 'WMS', opacity: DEFAULT_OPACITY, isVisible: true, isLoading: false, @@ -123,7 +120,7 @@ function makeGeoAdminWMSLayer(values: Partial): GeoAdminWMSLay function makeGeoAdminWMTSLayer(values: Partial): GeoAdminWMTSLayer { const defaults: DefaultLayerConfig = { uuid: uuidv4(), - type: LayerType.WMTS, + type: 'WMTS', idIn3d: undefined, technicalName: undefined, opacity: 1.0, @@ -169,13 +166,13 @@ function makeExternalWMTSLayer(values: Partial): ExternalWMTS const defaults: DefaultLayerConfig = { uuid: uuidv4(), isExternal: true, - type: LayerType.WMTS, + type: 'WMTS', opacity: DEFAULT_OPACITY, isVisible: true, abstract: '', legends: [], availableProjections: [], - getTileEncoding: WMTSEncodingType.REST, + getTileEncoding: 'REST', urlTemplate: '', style: '', tileMatrixSets: [], @@ -238,7 +235,7 @@ function makeExternalWMSLayer(values: Partial): ExternalWMSLay dimensions: [], currentYear: undefined, customAttributes: undefined, - type: LayerType.WMS, + type: 'WMS', isExternal: true, hasError: false, hasWarning: false, @@ -299,7 +296,7 @@ function makeKMLLayer(values: Partial): KMLLayer { if (values.style !== undefined) { style = values.style } else { - style = isExternal ? KMLStyle.DEFAULT : KMLStyle.GEOADMIN + style = isExternal ? 'DEFAULT' : 'GEOADMIN' } let fileId = values.fileId @@ -345,7 +342,7 @@ function makeKMLLayer(values: Partial): KMLLayer { isLocalFile: isLocal, attributions, style, - type: LayerType.KML, + type: 'KML', hasTooltip: false, hasError: false, hasWarning: false, @@ -400,7 +397,7 @@ function makeGPXLayer(values: Partial): GPXLayer { extent: undefined, name: name, id: `GPX|${encodeExternalLayerParam(values.gpxFileUrl)}`, - type: LayerType.GPX, + type: 'GPX', opacity: 0, isVisible: false, attributions, @@ -436,7 +433,7 @@ function makeGeoAdminVectorLayer(values: Partial): GeoAdmin const defaults: DefaultLayerConfig = { uuid: uuidv4(), - type: LayerType.VECTOR, + type: 'VECTOR', technicalName: '', attributions, opacity: 0, @@ -480,7 +477,7 @@ function makeGeoAdmin3DLayer(values: Partial): GeoAdmin3DLayer use3dTileSubFolder: false, urlTimestampToUse: undefined, name: values.name ?? values.id ?? '3D layer', - type: LayerType.VECTOR, + type: 'VECTOR', opacity: 1, isVisible: true, attributions, @@ -528,7 +525,7 @@ function makeCloudOptimizedGeoTIFFLayer( const defaults: CloudOptimizedGeoTIFFLayer = { uuid: uuidv4(), baseUrl: fileSource, - type: LayerType.COG, + type: 'COG', isLocalFile: isLocal, fileSource: undefined, data: undefined, @@ -565,7 +562,7 @@ function makeGeoAdminAggregateLayer( ): GeoAdminAggregateLayer { const defaults: DefaultLayerConfig = { uuid: uuidv4(), - type: LayerType.AGGREGATE, + type: 'AGGREGATE', subLayers: [], opacity: 1, isVisible: true, @@ -600,7 +597,7 @@ function makeGeoAdminAggregateLayer( function makeGeoAdminGeoJSONLayer(values: Partial): GeoAdminGeoJSONLayer { const defaults: DefaultLayerConfig = { uuid: uuidv4(), - type: LayerType.GEOJSON, + type: 'GEOJSON', updateDelay: 0, styleUrl: '', geoJsonUrl: '', @@ -642,7 +639,7 @@ function makeGeoAdminGroupOfLayers(values: Partial): GeoA const defaults: DefaultLayerConfig = { uuid: uuidv4(), layers: [], - type: LayerType.GROUP, + type: 'GROUP', opacity: 1, isVisible: true, attributions: [], @@ -735,7 +732,7 @@ function getWmtsXyzUrl( } ): string | undefined { const { addTimestamp = false, baseUrlOverride } = options ?? {} - if (wmtsLayerConfig?.type === LayerType.WMTS && projection) { + if (wmtsLayerConfig?.type === 'WMTS' && projection) { let timestamp = '{Time}' if (addTimestamp) { timestamp = timeConfigUtils.getTimestampFromConfig(wmtsLayerConfig) ?? '{Time}' @@ -757,8 +754,7 @@ function getWmtsXyzUrl( return } -export interface GeoadminLayerUtils { - transformToLayerTypeEnum: typeof transformToLayerTypeEnum +export interface SwissGeoLayerUtils { makeGPXLayer: typeof makeGPXLayer makeKMLLayer: typeof makeKMLLayer makeGeoAdminWMSLayer: typeof makeGeoAdminWMSLayer @@ -779,8 +775,7 @@ export interface GeoadminLayerUtils { getWmtsXyzUrl: typeof getWmtsXyzUrl } -export const layerUtils: GeoadminLayerUtils = { - transformToLayerTypeEnum, +export const layerUtils: SwissGeoLayerUtils = { makeGPXLayer, makeKMLLayer, makeGeoAdminWMSLayer, diff --git a/packages/layers/src/utils/timeConfigUtils.ts b/packages/layers/src/utils/timeConfigUtils.ts index 3c91bcba32..d151a36239 100644 --- a/packages/layers/src/utils/timeConfigUtils.ts +++ b/packages/layers/src/utils/timeConfigUtils.ts @@ -2,16 +2,12 @@ import log from '@swissgeo/log' import { isTimestampYYYYMMDD } from '@swissgeo/numbers' import { Interval } from 'luxon' -import type {Layer, LayerTimeConfig, LayerTimeConfigEntry} from '@/types'; +import type { Layer, LayerTimeConfig, LayerTimeConfigEntry } from '@/types' import { ALL_YEARS_TIMESTAMP, CURRENT_YEAR_TIMESTAMP, - - - - LayerType, - YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA + YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA, } from '@/types' const hasTimestamp = (timeConfig: LayerTimeConfig, timestamp: string): boolean => @@ -23,7 +19,10 @@ const getTimeEntryForYear = ( ): LayerTimeConfigEntry | undefined => { const yearAsInterval = Interval.fromISO(`${year}-01-01/P1Y`) return timeConfig.timeEntries.find((entry: LayerTimeConfigEntry) => { - if (entry.nonTimeBasedValue && [ALL_YEARS_TIMESTAMP, CURRENT_YEAR_TIMESTAMP].includes(entry.nonTimeBasedValue)) { + if ( + entry.nonTimeBasedValue && + [ALL_YEARS_TIMESTAMP, CURRENT_YEAR_TIMESTAMP].includes(entry.nonTimeBasedValue) + ) { return year === YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA } if (yearAsInterval.isValid && entry.interval) { @@ -156,7 +155,10 @@ const hasMultipleTimestamps = (layer: Layer): boolean => { } export function getYearFromLayerTimeEntry(timeEntry: LayerTimeConfigEntry): number | undefined { - if (timeEntry.nonTimeBasedValue && [ALL_YEARS_TIMESTAMP, CURRENT_YEAR_TIMESTAMP].includes(timeEntry.nonTimeBasedValue)) { + if ( + timeEntry.nonTimeBasedValue && + [ALL_YEARS_TIMESTAMP, CURRENT_YEAR_TIMESTAMP].includes(timeEntry.nonTimeBasedValue) + ) { return YEAR_TO_DESCRIBE_ALL_OR_CURRENT_DATA } if (timeEntry.interval && timeEntry.interval.start?.year !== undefined) { @@ -183,7 +185,7 @@ const getTimeEntryForInterval = ( /** Returns timestamp for WMS or WMTS layer from config data */ function getTimestampFromConfig(layer: Layer): string | undefined { let timestamp = layer.timeConfig?.currentTimeEntry?.timestamp - if (!timestamp && layer.type === LayerType.WMTS) { + if (!timestamp && layer.type === 'WMTS') { // for WMTS layer fallback to current timestamp = CURRENT_YEAR_TIMESTAMP } diff --git a/packages/mapviewer/scripts/check-external-layers-providers.ts b/packages/mapviewer/scripts/check-external-layers-providers.ts index 813b96ba10..251d633f8c 100644 --- a/packages/mapviewer/scripts/check-external-layers-providers.ts +++ b/packages/mapviewer/scripts/check-external-layers-providers.ts @@ -16,7 +16,6 @@ import type { } from 'axios' import { LV95 } from '@swissgeo/coordinates' -import { LayerType } from '@swissgeo/layers' import { EXTERNAL_SERVER_TIMEOUT, setWmsGetMapParams } from '@swissgeo/layers/api' import { wmsCapabilitiesParser, wmtsCapabilitiesParser } from '@swissgeo/layers/parsers' import axios, { AxiosError } from 'axios' @@ -221,7 +220,7 @@ async function handleWmts(provider: string, content: string, result: Result): Pr }) const firstLayer = findFirstLeaf(layers) - if (!firstLayer || firstLayer.type !== LayerType.WMTS) { + if (!firstLayer || firstLayer.type !== 'WMTS') { return false } const firstWmtsLayer = firstLayer as ExternalWMTSLayer @@ -326,7 +325,7 @@ function findFirstLeaf(layers: ExternalLayer[]): ExternalLayer | undefined { } for (const layer of layers) { - if (layer.type !== LayerType.WMS) { + if (layer.type !== 'WMS') { return layer } diff --git a/packages/mapviewer/src/modules/drawing/DrawingModule.vue b/packages/mapviewer/src/modules/drawing/DrawingModule.vue index d145a2bc49..087f99d2f5 100644 --- a/packages/mapviewer/src/modules/drawing/DrawingModule.vue +++ b/packages/mapviewer/src/modules/drawing/DrawingModule.vue @@ -7,7 +7,6 @@ import type { ComponentPublicInstance } from 'vue' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { kmlUtils } from '@swissgeo/api/utils' -import { LayerType } from '@swissgeo/layers' import log, { LogPreDefinedColor } from '@swissgeo/log' import { WarningMessage } from '@swissgeo/log/Message' import { computed, inject, onBeforeUnmount, onMounted, ref, useTemplateRef, watch } from 'vue' @@ -23,7 +22,6 @@ import DrawingToolbox from '@/modules/drawing/components/DrawingToolbox.vue' import DrawingTooltip from '@/modules/drawing/components/DrawingTooltip.vue' import ShareWarningPopup from '@/modules/drawing/components/ShareWarningPopup.vue' import useDrawingStore from '@/store/modules/drawing' -import { EditMode } from '@/store/modules/drawing/types' import addKmlFeaturesToDrawingLayer from '@/store/modules/drawing/utils/addKmlFeaturesToDrawingLayer' import useLayersStore from '@/store/modules/layers' import ModalWithBackdrop from '@/utils/components/ModalWithBackdrop.vue' @@ -114,7 +112,7 @@ watch(availableIconSets, () => { onMounted(() => { const kmlLayerWithAdminId: KMLLayer | undefined = layersStore.activeLayers - .filter((layer) => layer.type === LayerType.KML) + .filter((layer) => layer.type === 'KML') .map((layer) => layer as KMLLayer) .find((kmlLayer) => !!kmlLayer.adminId) @@ -179,7 +177,7 @@ const beforeUnloadHandler = (event: BeforeUnloadEvent) => { function removeLastPoint() { // Only delete the last point when we are drawing a feature (or editing it) - if (!!drawingStore.edit.featureType || drawingStore.edit.mode === EditMode.Extend) { + if (!!drawingStore.edit.featureType || drawingStore.edit.mode === 'EXTEND') { drawingInteractions.value?.removeLastPoint() } } @@ -222,7 +220,7 @@ function closeDrawing() { { }) function addVertex() { - drawingStore.setEditingMode(EditMode.Extend, !!reverse, dispatcher) + drawingStore.setEditingMode('EXTEND', !!reverse, dispatcher) } diff --git a/packages/mapviewer/src/modules/drawing/components/DrawingInteractions.vue b/packages/mapviewer/src/modules/drawing/components/DrawingInteractions.vue index 48e5eecdd8..e0d835bd41 100644 --- a/packages/mapviewer/src/modules/drawing/components/DrawingInteractions.vue +++ b/packages/mapviewer/src/modules/drawing/components/DrawingInteractions.vue @@ -18,7 +18,6 @@ import DrawingTextInteraction from '@/modules/drawing/components/DrawingTextInte import ExtendLineInteraction from '@/modules/drawing/components/ExtendLineInteraction.vue' import ExtendMeasureInteraction from '@/modules/drawing/components/ExtendMeasureInteraction.vue' import useDrawingStore from '@/store/modules/drawing' -import { EditMode } from '@/store/modules/drawing/types' const selectInteraction = useTemplateRef>('selectInteraction') @@ -44,7 +43,7 @@ const specializedInteractionComponent = computed(() => { selectedInteraction = DrawingMeasureInteraction break } - if (drawingStore.edit.mode === EditMode.Extend) { + if (drawingStore.edit.mode === 'EXTEND') { const isMeasure = selectedLineFeature.value?.get('editableFeature')?.featureType === 'MEASURE' const isLine = @@ -69,7 +68,7 @@ const specializedInteractionComponent = computed(() => { }) const specializedProps = computed(() => { - if (drawingStore.edit.mode === EditMode.Extend) { + if (drawingStore.edit.mode === 'EXTEND') { return { startingFeature: selectedLineFeature.value, } @@ -83,7 +82,7 @@ function onDrawEnd(feature: Feature | undefined) { function removeLastPoint() { currentInteraction.value?.removeLastPoint() - if (drawingStore.edit.mode !== EditMode.Off) { + if (drawingStore.edit.mode !== 'OFF') { selectInteraction.value?.removeLastPoint() } } diff --git a/packages/mapviewer/src/modules/drawing/components/DrawingToolbox.vue b/packages/mapviewer/src/modules/drawing/components/DrawingToolbox.vue index f29d300a0e..7e9ea6b704 100644 --- a/packages/mapviewer/src/modules/drawing/components/DrawingToolbox.vue +++ b/packages/mapviewer/src/modules/drawing/components/DrawingToolbox.vue @@ -16,7 +16,6 @@ import DrawingToolboxButton from '@/modules/drawing/components/DrawingToolboxBut import SharePopup from '@/modules/drawing/components/SharePopup.vue' import ShareWarningPopup from '@/modules/drawing/components/ShareWarningPopup.vue' import useDrawingStore from '@/store/modules/drawing' -import { DrawingSaveState, EditMode } from '@/store/modules/drawing/types' import { isOnlineMode } from '@/store/modules/drawing/utils/isOnlineMode' import useFeaturesStore from '@/store/modules/features' import useLayersStore from '@/store/modules/layers' @@ -86,7 +85,7 @@ const isAllowDeleteLastPoint = computed( // Allow deleting the last point only if we are drawing line or measure // or when extending line isDrawingLineOrMeasure.value || - (drawingStore.edit.mode === EditMode.Extend && + (drawingStore.edit.mode === 'EXTEND' && selectedLineString.value !== undefined && selectedLineCoordinates.value !== undefined && selectedLineCoordinates.value.length > 2) @@ -96,20 +95,18 @@ const drawingName = computed({ set: (value) => debounceSaveDrawingName(value), }) const isDrawingStateError = computed( - () => - drawingStore.save.state === DrawingSaveState.LoadError || - drawingStore.save.state === DrawingSaveState.SaveError + () => drawingStore.save.state === 'LOAD_ERROR' || drawingStore.save.state === 'SAVE_ERROR' ) /** Return a different translation key depending on the saving status */ const drawingStateMessage = computed(() => { switch (drawingStore.save.state) { - case DrawingSaveState.Saving: + case 'SAVING': return t('draw_file_saving') - case DrawingSaveState.Saved: + case 'SAVED': return t('draw_file_saved') - case DrawingSaveState.SaveError: + case 'SAVE_ERROR': return t('draw_file_load_error') - case DrawingSaveState.LoadError: + case 'LOAD_ERROR': return t('draw_file_save_error') default: return undefined diff --git a/packages/mapviewer/src/modules/drawing/components/useDrawingModeInteraction.composable.ts b/packages/mapviewer/src/modules/drawing/components/useDrawingModeInteraction.composable.ts index f24e8075d3..a5955caf3c 100644 --- a/packages/mapviewer/src/modules/drawing/components/useDrawingModeInteraction.composable.ts +++ b/packages/mapviewer/src/modules/drawing/components/useDrawingModeInteraction.composable.ts @@ -26,7 +26,6 @@ import type { ActionDispatcher } from '@/store/types' import { updateStoreFeatureCoordinatesGeometry } from '@/modules/drawing/lib/drawingUtils' import { editingFeatureStyleFunction } from '@/modules/drawing/lib/style' import useDrawingStore from '@/store/modules/drawing' -import { EditMode } from '@/store/modules/drawing/types' import usePositionStore from '@/store/modules/position' import { GeodesicGeometries } from '@/utils/geodesicManager' @@ -254,7 +253,7 @@ export default function useDrawingModeInteraction(config?: UseDrawingModeInterac drawingStore.edit.reverseLineStringExtension ) drawingStore.setEditingMode( - EditMode.Modify, + 'MODIFY', drawingStore.edit.reverseLineStringExtension, dispatcher ) diff --git a/packages/mapviewer/src/modules/drawing/components/useModifyInteraction.composable.ts b/packages/mapviewer/src/modules/drawing/components/useModifyInteraction.composable.ts index cc9fd1c2e2..fa535206b8 100644 --- a/packages/mapviewer/src/modules/drawing/components/useModifyInteraction.composable.ts +++ b/packages/mapviewer/src/modules/drawing/components/useModifyInteraction.composable.ts @@ -18,7 +18,6 @@ import type { ActionDispatcher } from '@/store/types' import { updateStoreFeatureCoordinatesGeometry } from '@/modules/drawing/lib/drawingUtils' import { editingVertexStyleFunction } from '@/modules/drawing/lib/style' import useDrawingStore from '@/store/modules/drawing' -import { EditMode } from '@/store/modules/drawing/types' const dispatcher: ActionDispatcher = { name: 'useModifyInteraction.composable' } const cursorGrabbingClass = 'cursor-grabbing' @@ -68,7 +67,7 @@ export default function useModifyInteraction(features: Collection drawingStore.edit.mode, (newValue) => { - if (newValue === EditMode.Extend && features.getLength() > 0) { + if (newValue === 'EXTEND' && features.getLength() > 0) { const selectedFeature = features.item(0) if (selectedFeature && drawingStore.edit.reverseLineStringExtension) { const geom = selectedFeature.getGeometry() @@ -79,7 +78,7 @@ export default function useModifyInteraction(features: Collection { - drawingStore.setEditingMode( - EditMode.Off, - drawingStore.edit.reverseLineStringExtension, - dispatcher - ) + drawingStore.setEditingMode('OFF', drawingStore.edit.reverseLineStringExtension, dispatcher) olMap.removeInteraction(modifyInteraction) @@ -109,7 +104,7 @@ export default function useModifyInteraction(features: Collection { } }) const visibleLayerOnTop = computed(() => layersStore.visibleLayerOnTop) -const shouldUseWebGlContext = computed(() => visibleLayerOnTop.value?.type === LayerType.COG) +const shouldUseWebGlContext = computed(() => visibleLayerOnTop.value?.type === 'COG') watch(storeCompareRatio, (newValue) => { if (newValue) { diff --git a/packages/mapviewer/src/modules/map/components/cesium/CesiumHighlightedFeatures.vue b/packages/mapviewer/src/modules/map/components/cesium/CesiumHighlightedFeatures.vue index 6cb95af972..c470a31c3f 100644 --- a/packages/mapviewer/src/modules/map/components/cesium/CesiumHighlightedFeatures.vue +++ b/packages/mapviewer/src/modules/map/components/cesium/CesiumHighlightedFeatures.vue @@ -5,7 +5,6 @@ import type { Viewer } from 'cesium' import type { ShallowRef } from 'vue' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' -import { LayerType } from '@swissgeo/layers' import log from '@swissgeo/log' import { LineString, Point, Polygon } from 'ol/geom' import { computed, inject, onMounted, ref, watch } from 'vue' @@ -91,11 +90,7 @@ function highlightSelectedFeatures(): void { const hasLayer = (obj: LayerFeature | EditableFeature): obj is LayerFeature => !!obj && typeof obj === 'object' && 'layer' in obj - if ( - hasLayer(f) && - f.layer.type === LayerType.VECTOR && - 'use3dTileSubFolder' in f.layer - ) { + if (hasLayer(f) && f.layer.type === 'VECTOR' && 'use3dTileSubFolder' in f.layer) { return } diff --git a/packages/mapviewer/src/modules/map/components/cesium/CesiumInteractions.vue b/packages/mapviewer/src/modules/map/components/cesium/CesiumInteractions.vue index 7295890e29..01565f6e88 100644 --- a/packages/mapviewer/src/modules/map/components/cesium/CesiumInteractions.vue +++ b/packages/mapviewer/src/modules/map/components/cesium/CesiumInteractions.vue @@ -6,7 +6,6 @@ import type { LayerTooltipConfig } from '@swissgeo/staging-config/constants' import type { ShallowRef } from 'vue' import { extentUtils, WEBMERCATOR, WGS84 } from '@swissgeo/coordinates' -import { LayerType } from '@swissgeo/layers' import log, { LogPreDefinedColor } from '@swissgeo/log' import { get3dTilesBaseUrl } from '@swissgeo/staging-config' import { bbox, centroid } from '@turf/turf' @@ -40,7 +39,6 @@ import useCesiumStore from '@/store/modules/cesium' import useFeaturesStore from '@/store/modules/features' import useLayersStore from '@/store/modules/layers' import useMapStore from '@/store/modules/map' -import { ClickType } from '@/store/modules/map/types' import usePositionStore from '@/store/modules/position' import { identifyGeoJSONFeatureAt } from '@/utils/identifyOnVectorLayer' @@ -60,9 +58,7 @@ const mapStore = useMapStore() const selectedFeatures = computed(() => featuresStore.selectedFeatures) const visiblePrimitiveLayers = computed(() => - layersStore.visibleLayers.filter((l: Layer) => - [LayerType.GEOJSON, LayerType.KML, LayerType.GPX].includes(l.type) - ) + layersStore.visibleLayers.filter((l: Layer) => ['GEOJSON', 'KML', 'GPX'].includes(l.type)) ) const viewer = inject>('viewer') @@ -184,7 +180,7 @@ function getCoordinateAtScreenCoordinate(x: number, y: number): SingleCoordinate titleColor: LogPreDefinedColor.Orange, messages: ['Using camera fallback for coordinate (test mode)', [x, y]], }) - + // Use camera position as approximate coordinate for tests const camera = viewerInstance.camera const cartographic = camera.positionCartographic @@ -199,7 +195,7 @@ function getCoordinateAtScreenCoordinate(x: number, y: number): SingleCoordinate messages: ['no coordinate found at this screen coordinates', [x, y]], }) } - + return coordinates } catch (error) { log.error({ @@ -339,7 +335,7 @@ function onClick(event: ScreenSpaceEventHandler.PositionedEvent): void { // if there is a GeoJSON layer currently visible, we will find it and search for features under the mouse cursor if (Array.isArray(coordinates) && coordinates.length === 2) { visiblePrimitiveLayers.value - .filter((layer: Layer) => layer.type === LayerType.GEOJSON) + .filter((layer: Layer) => layer.type === 'GEOJSON') .forEach((geoJSonLayer: Layer) => { const identified = identifyGeoJSONFeatureAt( geoJSonLayer as GeoAdminGeoJSONLayer, @@ -354,7 +350,7 @@ function onClick(event: ScreenSpaceEventHandler.PositionedEvent): void { } visiblePrimitiveLayers.value - .filter((layer: Layer) => layer.type === LayerType.KML) + .filter((layer: Layer) => layer.type === 'KML') .forEach((kmlLayer: Layer) => { objects .filter((obj) => obj.id?.layerId === kmlLayer.id) @@ -400,7 +396,7 @@ function onClick(event: ScreenSpaceEventHandler.PositionedEvent): void { coordinate: coordinates, pixelCoordinate: [event.position.x, event.position.y], features: features as SelectableFeature[], - clickType: ClickType.LeftSingleClick, + clickType: 'LEFT_SINGLE_CLICK', }, dispatcher ) @@ -498,7 +494,7 @@ function onContextMenu(event: ScreenSpaceEventHandler.PositionedEvent): void { { coordinate: coordinates, pixelCoordinate: [event.position.x, event.position.y], - clickType: ClickType.ContextMenu, + clickType: 'CONTEXT_MENU', }, dispatcher ) diff --git a/packages/mapviewer/src/modules/map/components/cesium/CesiumInternalLayer.vue b/packages/mapviewer/src/modules/map/components/cesium/CesiumInternalLayer.vue index 609c15a7ec..8a0e5b3eb3 100644 --- a/packages/mapviewer/src/modules/map/components/cesium/CesiumInternalLayer.vue +++ b/packages/mapviewer/src/modules/map/components/cesium/CesiumInternalLayer.vue @@ -16,7 +16,6 @@ import type { Layer, } from '@swissgeo/layers' -import { LayerType } from '@swissgeo/layers' import { computed } from 'vue' import CesiumGeoJSONLayer from '@/modules/map/components/cesium/CesiumGeoJSONLayer.vue' @@ -38,13 +37,13 @@ const { layerConfig, zIndex, projection, isTimeSliderActive, parentLayerOpacity const positionStore = usePositionStore() const resolution = computed(() => positionStore.resolution) -const isWMTS = computed(() => layerConfig.type === LayerType.WMTS) +const isWMTS = computed(() => layerConfig.type === 'WMTS') const wmtsLayerConfig = computed(() => layerConfig as GeoAdminWMTSLayer | ExternalWMTSLayer) -const isWMS = computed(() => layerConfig.type === LayerType.WMS) +const isWMS = computed(() => layerConfig.type === 'WMS') const wmsLayerConfig = computed(() => layerConfig as GeoAdminWMSLayer | ExternalWMSLayer) -const isGroup = computed(() => layerConfig.type === LayerType.GROUP) +const isGroup = computed(() => layerConfig.type === 'GROUP') const groupConfig = computed(() => layerConfig as GeoAdminGroupOfLayers) -const isAggregate = computed(() => layerConfig.type === LayerType.AGGREGATE) +const isAggregate = computed(() => layerConfig.type === 'AGGREGATE') const aggregateConfig = computed(() => layerConfig as GeoAdminAggregateLayer) function shouldAggregateSubLayerBeVisible(subLayer: { @@ -59,7 +58,7 @@ function shouldAggregateSubLayerBeVisible(subLayer: {