From e40617e17d943765a1f580c3fdbecaf66c9b7179 Mon Sep 17 00:00:00 2001 From: Vijayan Balasubramanian Date: Fri, 3 Feb 2023 22:27:39 -0800 Subject: [PATCH] Refactor layer properties as own interface (#225) * Remove unused methods * Create layer interface to abstract common properties. Signed-off-by: Vijayan Balasubramanian --- public/model/customLayerFunctions.ts | 4 ---- public/model/map/layer_operations.ts | 24 ++++++++++-------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/public/model/customLayerFunctions.ts b/public/model/customLayerFunctions.ts index 2c675434..5da7fe92 100644 --- a/public/model/customLayerFunctions.ts +++ b/public/model/customLayerFunctions.ts @@ -7,10 +7,6 @@ interface MaplibreRef { current: Maplibre | null; } -const getCurrentStyleLayers = (maplibreRef: MaplibreRef) => { - return maplibreRef.current?.getStyle().layers || []; -}; - const updateLayerConfig = (layerConfig: CustomLayerSpecification, maplibreRef: MaplibreRef) => { const maplibreInstance = maplibreRef.current; if (maplibreInstance) { diff --git a/public/model/map/layer_operations.ts b/public/model/map/layer_operations.ts index 7c3cfd99..06241b2f 100644 --- a/public/model/map/layer_operations.ts +++ b/public/model/map/layer_operations.ts @@ -48,16 +48,20 @@ export const updateLayerVisibility = (map: Maplibre, layerId: string, visibility }); }; -export interface LineLayerSpecification { +// Common properties that every DashboardMap layer contains +interface Layer { sourceId: string; - visibility: string; - color: string; opacity: number; - width: number; minZoom: number; maxZoom: number; } +export interface LineLayerSpecification extends Layer { + visibility: string; + color: string; + width: number; +} + export const addLineLayer = ( map: Maplibre, specification: LineLayerSpecification, @@ -90,16 +94,12 @@ export const updateLineLayer = ( return lineLayerId; }; -export interface CircleLayerSpecification { - sourceId: string; +export interface CircleLayerSpecification extends Layer { visibility: string; fillColor: string; outlineColor: string; radius: number; - opacity: number; width: number; - minZoom: number; - maxZoom: number; } export const addCircleLayer = ( @@ -137,15 +137,11 @@ export const updateCircleLayer = ( return circleLayerId; }; -export interface PolygonLayerSpecification { - sourceId: string; +export interface PolygonLayerSpecification extends Layer { visibility: string; fillColor: string; outlineColor: string; - opacity: number; width: number; - minZoom: number; - maxZoom: number; } export const addPolygonLayer = (