Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script module lang="ts">
import { defineMeta } from '@storybook/addon-svelte-csf';

import Map from '../Map/Map.svelte';
import HillshadeLayer from './HillshadeLayer.svelte';
import AttributionControl from '../AttributionControl/AttributionControl.svelte';
import DesignTokens from '../../DesignTokens/DesignTokens.svelte';

import { SWRDataLabLight } from '../MapStyle';

const { Story } = defineMeta({
title: 'Maplibre/Layer/HillshadeLayer',
component: HillshadeLayer
});
</script>

<Story asChild name="Default">
<DesignTokens theme="light">
<div class="container">
<Map showDebug={true} style={SWRDataLabLight()}>
<AttributionControl position="bottom-left" />
</Map>
</div>
</DesignTokens>
</Story>

<style>
.container {
width: 100%;
height: 600px;
}
</style>
59 changes: 59 additions & 0 deletions components/src/maplibre/HillshadeLayer/HillshadeLayer.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<script lang="ts">
import { type AddLayerObject } from 'maplibre-gl';

import { getMapContext } from '../context.svelte.js';
import { onDestroy } from 'svelte';
import { resetLayerEventListener } from '../utils.js';

interface HillshadeLayerProps extends Omit<
maplibregl.HillshadeLayerSpecification,
'id' | 'source' | 'source-layer'
> {
id: string;
sourceId: string;
sourceLayer?: string;
placeBelow?: string;
visible?: boolean;
minZoom?: number;
maxZoom?: number;
}
const {
id,
sourceId,
sourceLayer,
placeBelow,
type,
paint,
layout,
hovered = $bindable(),
selected = $bindable(),
minZoom = 0,
maxZoom = 24,
onclick,
onmousemove,
onmouseleave
}: HillshadeLayerProps = $props();

const ctx = getMapContext();
let beforeId: string | undefined = $state();

const layerSpec = $derived({
id,
type,
source: sourceId,
'source-layer': sourceLayer || '',
layout: layout ?? {},
paint: paint ?? {},
minzoom: minZoom,
maxzoom: maxZoom
}) as AddLayerObject;

$effect(() => {
ctx.waitForStyleLoaded((m) => {
ctx.addLayer(layerSpec, placeBelow);
});
});
onDestroy(() => {
if (ctx.map && ctx.map.getLayer(id)) ctx.map.removeLayer(id);
});
</script>
2 changes: 2 additions & 0 deletions components/src/maplibre/HillshadeLayer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import HillshadeLayer from './HillshadeLayer.svelte';
export default HillshadeLayer;
Loading