Skip to content

Commit e541bcc

Browse files
authored
Reset map size on screen size change (#19)
* add margin on small screens for github buttons * reset map size when screens are changing and adjust mb for github buttons.
1 parent 1123963 commit e541bcc

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

components/MyLeafletMap.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,30 @@ function clearLegend() {
289289
290290
defineExpose({
291291
resetSelectedMarker,
292+
invalidateMapSize,
292293
});
293294
295+
function invalidateMapSize() {
296+
if (leafletMap) {
297+
leafletMap.invalidateSize({ animate: false });
298+
}
299+
}
300+
294301
onMounted(() => {
295302
if (!map.value)
296303
return;
297304
298-
leafletMap = L.map(map.value).setView([54.2194, 9.6961], 8);
305+
leafletMap = L.map(map.value, { preferCanvas: true }).setView([54.2194, 9.6961], 8);
299306
300307
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
301308
attribution: '© OpenStreetMap contributors',
302309
}).addTo(leafletMap);
310+
setTimeout(() => invalidateMapSize(), 300);
311+
window.addEventListener('resize', invalidateMapSize);
312+
});
313+
314+
onUnmounted(() => {
315+
window.removeEventListener('resize', invalidateMapSize);
303316
});
304317
305318
watch(() => props.fetchedData, (newData) => {

pages/index.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</ul>
5151
</div>
5252

53-
<div class="flex flex-col p-4 mb-10 space-y-1">
53+
<div class="flex flex-col p-4 mb-20 lg:mb-10 space-y-1">
5454
<a
5555
href="https://github.com/geprog/openkarte/discussions"
5656
target="_blank"
@@ -230,4 +230,10 @@ watch(feature, async (newval) => {
230230
watch(locale, (newLocale) => {
231231
setLocale(newLocale);
232232
});
233+
234+
watch(sidebarOpen, () => {
235+
setTimeout(() => {
236+
leafletMapRef.value?.invalidateMapSize?.();
237+
}, 300);
238+
});
233239
</script>

0 commit comments

Comments
 (0)