From 7aa82b0d0335193a940d8695bbe66ebc047ba3ef Mon Sep 17 00:00:00 2001 From: Mathias Boeck Date: Fri, 15 Mar 2024 14:45:28 +0100 Subject: [PATCH] refactor: use clone function from utilities --- .../src/lib/maplibre-layers.helpers.ts | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/projects/map-maplibre/src/lib/maplibre-layers.helpers.ts b/projects/map-maplibre/src/lib/maplibre-layers.helpers.ts index a99f69d4..9626ca06 100644 --- a/projects/map-maplibre/src/lib/maplibre-layers.helpers.ts +++ b/projects/map-maplibre/src/lib/maplibre-layers.helpers.ts @@ -7,7 +7,7 @@ import { WmtsLayer as ukisWmtsLayer, VectorLayer as ukisVectorLayer, CustomLayer as ukisCustomLayer, Layer as ukisLayer, StackedLayer, XyzLayertype, WmsLayertype, WmtsLayertype, TmsLayertype, GeojsonLayertype, KmlLayertype, WfsLayertype, CustomLayertype, StackedLayertype } from '@dlr-eoc/services-layers'; import { LayerSourceSpecification, SourceIdSpecification, UKIS_METADATA, getAllLayers, getOpacityPaintProperty } from "./maplibre.helpers"; -import { propsEqual } from '@dlr-eoc/utilities'; +import { propsEqual, clone } from '@dlr-eoc/utilities'; export function addUkisLayerMetadata(l: ukisLayer) { const metadata = {}; @@ -186,7 +186,7 @@ export function createTmsLayer(l: T } else if (l instanceof ukisVectorLayer) { if(l?.options?.style){ - const style = cloneStyle(l?.options?.style) as StyleSpecification; + const style = clone(l?.options?.style) as StyleSpecification; style.layers.forEach(ls => { (ls.metadata as any) = Object.assign(ls.metadata as any || {}, addUkisLayerMetadata(l)); @@ -432,25 +432,6 @@ export function createKmlLayer(l: ukisVectorLayer) { return returnSourcesAndLayers(l, source, layers); } -/** - * simple clone function to clone styles of CustomLayer - */ -function cloneStyle(obj:any){ - const newObj = {} as T; - Object.entries(obj).forEach(s => { - const key = s[0]; - const value = s[1]; - if(Array.isArray(value)){ - newObj[key] = value.map(i => { return {...i}}); - }else if(typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' ){ - newObj[key] = value; - }else if(typeof value === 'object'){ - newObj[key] = {...value}; - } - }); - - return newObj; -} export function createCustomLayer(l: ukisCustomLayer) { @@ -460,7 +441,7 @@ export function createCustomLayer(l: ukisCustomLayer) { console.error('custom_layer is not a StyleSpecification'); } - const style = cloneStyle(l.custom_layer) as StyleSpecification; + const style = clone(l.custom_layer) as StyleSpecification; const sources: SourceIdSpecification = style.sources; Object.keys(sources).forEach(key => {