your personal website on atproto - mirror blento.app

fixed focus in viewmode and zoom on mobile view

+51 -27
+50 -26
src/lib/cards/core/MapCard/Map.svelte
··· 1 1 <script lang="ts"> 2 2 import type { Item } from '$lib/types'; 3 3 import { MapLibre, Projection, Marker } from 'svelte-maplibre-gl'; 4 + import type maplibregl from 'maplibre-gl'; 4 5 5 - let { item = $bindable() }: { item: Item } = $props(); 6 + let { item = $bindable(), isEditing = false }: { item: Item; isEditing?: boolean } = $props(); 6 7 7 8 let center = $state({ lng: parseFloat(item.cardData.lon), lat: parseFloat(item.cardData.lat) }); 8 9 let showAttribution = $state(false); 10 + let map: maplibregl.Map | undefined = $state(); 11 + 12 + const fixedCenter = { lng: parseFloat(item.cardData.lon), lat: parseFloat(item.cardData.lat) }; 13 + 14 + function handleZoom() { 15 + if (!isEditing && map) { 16 + map.setCenter(fixedCenter); 17 + } 18 + } 19 + 20 + $effect(() => { 21 + if (!isEditing && map) { 22 + map.getCanvas().style.touchAction = 'pan-x pan-y'; 23 + } 24 + }); 9 25 </script> 10 26 11 - <div class="absolute inset-0 isolate h-full w-full"> 12 - <MapLibre 13 - class="h-full w-full" 14 - style="https://tiles.openfreemap.org/styles/liberty" 15 - zoom={item.cardData.zoom} 16 - {center} 17 - attributionControl={false} 18 - dragPan={false} 19 - dragRotate={false} 20 - keyboard={false} 21 - touchZoomRotate={true} 22 - scrollZoom={true} 23 - boxZoom={false} 24 - pitchWithRotate={false} 25 - touchPitch={false} 26 - > 27 - <Projection type="globe" /> 27 + <div 28 + class="absolute inset-0 isolate h-full w-full" 29 + onfocusin={(e) => { 30 + if (!isEditing && e.target instanceof HTMLElement) e.target.blur(); 31 + }}> 32 + <div class="h-full w-full"> 33 + <MapLibre 34 + bind:map 35 + class="h-full w-full" 36 + style="https://tiles.openfreemap.org/styles/liberty" 37 + zoom={item.cardData.zoom} 38 + {center} 39 + attributionControl={false} 40 + dragPan={false} 41 + dragRotate={false} 42 + keyboard={false} 43 + touchZoomRotate={true} 44 + scrollZoom={true} 45 + boxZoom={false} 46 + pitchWithRotate={false} 47 + touchPitch={false} 48 + onzoom={handleZoom} 49 + > 50 + <Projection type="globe" /> 28 51 29 - <Marker bind:lnglat={center}> 30 - {#snippet content()} 31 - <div class="from-accent-400 size-10 rounded-full bg-radial via-transparent p-3"> 32 - <div class="bg-accent-500 size-4 rounded-full ring-2 ring-white"></div> 33 - </div> 34 - {/snippet} 35 - </Marker> 36 - </MapLibre> 52 + <Marker bind:lnglat={center}> 53 + {#snippet content()} 54 + <div class="from-accent-400 size-10 rounded-full bg-radial via-transparent p-3"> 55 + <div class="bg-accent-500 size-4 rounded-full ring-2 ring-white"></div> 56 + </div> 57 + {/snippet} 58 + </Marker> 59 + </MapLibre> 60 + </div> 37 61 38 62 {#snippet infoIcon()} 39 63 <svg
+1 -1
src/lib/cards/core/MapCard/MapCard.svelte
··· 11 11 ); 12 12 </script> 13 13 14 - <Map bind:item /> 14 + <Map bind:item {isEditing} /> 15 15 16 16 {#if item.cardData.linkToGoogleMaps && !isEditing} 17 17 <a