Skip to content

Commit

Permalink
Make layerId easier to use in non-sketch cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jul 14, 2024
1 parent 2bd3752 commit 5139a22
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lib/maplibre/zorder.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { type Config, map as mapStore } from "$lib/config";
import { map as mapStore } from "$lib/config";
import { get } from "svelte/store";

interface LayerProps {
id: string;
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<F, S>(cfg: Config<F, S>, layerId: string): LayerProps {
export function layerId(cfg: ConfigWithZorder, layerId: string): LayerProps {
return {
id: layerId,
beforeId: getBeforeId(cfg, layerId),
Expand All @@ -20,8 +25,8 @@ export function layerId<F, S>(cfg: Config<F, S>, 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<F, S>(
cfg: Config<F, S>,
function getBeforeId(
cfg: ConfigWithZorder,
layerId: string,
): string | undefined {
let map = get(mapStore);
Expand Down

0 comments on commit 5139a22

Please sign in to comment.