Skip to content

Commit 87692e4

Browse files
committed
Don't set default marker offset to [0,0]
Maplibre sets its own offset by default so that the "center" point of the marker is the bottom of the marker pin. Setting the offset to [0,0] was ovwrriding this, causing the marker to be centered in the middle of the icon which makes it slightly inaccurate and appear to drift as the map zooms. Fixes #237
1 parent 77c50dd commit 87692e4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

.changeset/neat-penguins-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-maplibre': patch
3+
---
4+
5+
Default marker offset is unset instead of [0, 0]

src/lib/DefaultMarker.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@
8989
marker.value?.setLngLat(lngLat);
9090
});
9191
$effect(() => {
92-
marker.value?.setOffset(offset ?? [0, 0]);
92+
if (offset) {
93+
marker.value?.setOffset(offset);
94+
}
9395
});
9496
$effect(() => {
9597
marker.value?.setRotation(rotation);

src/lib/Marker.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@
128128
marker.value?.setLngLat(lngLat);
129129
});
130130
$effect(() => {
131-
marker.value?.setOffset(offset ?? [0, 0]);
131+
if (offset) {
132+
marker.value?.setOffset(offset);
133+
}
132134
});
133135
$effect(() => {
134136
marker.value?.setRotation(rotation);

0 commit comments

Comments
 (0)