Skip to content

Commit 88880b6

Browse files
authored
feat(VectorLayer): Make placeBelow optional (#342)
Removes default value of label-place-major-city
1 parent 03b23b6 commit 88880b6

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

components/src/maplibre/VectorLayer/VectorLayer.stories.svelte

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@
113113
</DesignTokens>
114114
</Story>
115115

116+
<Story asChild name="feat/341">
117+
<DesignTokens theme="light">
118+
<div class="container">
119+
<Map showDebug={true} style={SWRDataLabLight({ places: { showLabels: false } })}>
120+
<GeoJsonSource id="demo" data={SamplePoints as GeoJSON} attribution="Demo attribution" />
121+
<VectorLayer
122+
sourceId="demo"
123+
id="circles"
124+
type="circle"
125+
paint={{
126+
'circle-radius': 12,
127+
'circle-color': 'red'
128+
}}
129+
/>
130+
<AttributionControl position="bottom-left" />
131+
</Map>
132+
</div>
133+
</DesignTokens>
134+
</Story>
135+
116136
<Story asChild name="Filter">
117137
<DesignTokens theme="light">
118138
<div class="controls">

components/src/maplibre/VectorLayer/VectorLayer.svelte

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
sourceId,
4646
sourceLayer,
4747
filter,
48-
visible = true,
49-
placeBelow = 'label-place-major-city',
48+
placeBelow,
5049
type,
5150
paint,
5251
layout,
@@ -80,15 +79,17 @@
8079
$effect(() => {
8180
if (map && styleLoaded) {
8281
const style = map.getStyle();
83-
beforeId = style.layers.find((l) => {
84-
return l.id === placeBelow;
85-
})?.id;
82+
beforeId = placeBelow
83+
? style.layers.find((l) => {
84+
return l.id === placeBelow;
85+
})?.id
86+
: undefined;
8687
}
8788
});
8889
8990
$effect(() => {
90-
if (map && styleLoaded && beforeId) {
91-
map.addLayer(layerSpec, beforeId);
91+
if (map && styleLoaded) {
92+
beforeId ? map.addLayer(layerSpec, beforeId) : map.addLayer(layerSpec);
9293
}
9394
});
9495

0 commit comments

Comments
 (0)