From 5139a2296dd544f9e54fe88bdb6a7ba3a3915c0b Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 14 Jul 2024 12:26:54 +0100 Subject: [PATCH] Make layerId easier to use in non-sketch cases --- src/lib/maplibre/zorder.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/maplibre/zorder.ts b/src/lib/maplibre/zorder.ts index d5129e5..d216c27 100644 --- a/src/lib/maplibre/zorder.ts +++ b/src/lib/maplibre/zorder.ts @@ -1,4 +1,4 @@ -import { type Config, map as mapStore } from "$lib/config"; +import { map as mapStore } from "$lib/config"; import { get } from "svelte/store"; interface LayerProps { @@ -6,10 +6,15 @@ interface LayerProps { beforeId: string | undefined; } +// Just require the subset of config needed, to make it easier for some callers +interface ConfigWithZorder { + layerZorder: string[]; +} + // Use this helper for every svelte-maplibre layer component. It sets the layer // ID, beforeId (for z-ordering between layers), and defaults to only using the // top-most layer for hovering/clicking. -export function layerId(cfg: Config, layerId: string): LayerProps { +export function layerId(cfg: ConfigWithZorder, layerId: string): LayerProps { return { id: layerId, beforeId: getBeforeId(cfg, layerId), @@ -20,8 +25,8 @@ export function layerId(cfg: Config, layerId: string): LayerProps { // Svelte component initialization order being unpredictable, callers might add // layers in any order. Use beforeId to guarantee the layers wind up in an // explicitly defined order. -function getBeforeId( - cfg: Config, +function getBeforeId( + cfg: ConfigWithZorder, layerId: string, ): string | undefined { let map = get(mapStore);