tangled
alpha
login
or
join now
flo-bit.dev
/
blento
21
fork
atom
your personal website on atproto - mirror
blento.app
21
fork
atom
overview
issues
pulls
pipelines
fixed focus in viewmode and zoom on mobile view
unbedenklich
4 weeks ago
e7ab4466
d55a4f08
+51
-27
2 changed files
expand all
collapse all
unified
split
src
lib
cards
core
MapCard
Map.svelte
MapCard.svelte
+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
4
+
import type maplibregl from 'maplibre-gl';
4
5
5
5
-
let { item = $bindable() }: { item: Item } = $props();
6
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
10
+
let map: maplibregl.Map | undefined = $state();
11
11
+
12
12
+
const fixedCenter = { lng: parseFloat(item.cardData.lon), lat: parseFloat(item.cardData.lat) };
13
13
+
14
14
+
function handleZoom() {
15
15
+
if (!isEditing && map) {
16
16
+
map.setCenter(fixedCenter);
17
17
+
}
18
18
+
}
19
19
+
20
20
+
$effect(() => {
21
21
+
if (!isEditing && map) {
22
22
+
map.getCanvas().style.touchAction = 'pan-x pan-y';
23
23
+
}
24
24
+
});
9
25
</script>
10
26
11
11
-
<div class="absolute inset-0 isolate h-full w-full">
12
12
-
<MapLibre
13
13
-
class="h-full w-full"
14
14
-
style="https://tiles.openfreemap.org/styles/liberty"
15
15
-
zoom={item.cardData.zoom}
16
16
-
{center}
17
17
-
attributionControl={false}
18
18
-
dragPan={false}
19
19
-
dragRotate={false}
20
20
-
keyboard={false}
21
21
-
touchZoomRotate={true}
22
22
-
scrollZoom={true}
23
23
-
boxZoom={false}
24
24
-
pitchWithRotate={false}
25
25
-
touchPitch={false}
26
26
-
>
27
27
-
<Projection type="globe" />
27
27
+
<div
28
28
+
class="absolute inset-0 isolate h-full w-full"
29
29
+
onfocusin={(e) => {
30
30
+
if (!isEditing && e.target instanceof HTMLElement) e.target.blur();
31
31
+
}}>
32
32
+
<div class="h-full w-full">
33
33
+
<MapLibre
34
34
+
bind:map
35
35
+
class="h-full w-full"
36
36
+
style="https://tiles.openfreemap.org/styles/liberty"
37
37
+
zoom={item.cardData.zoom}
38
38
+
{center}
39
39
+
attributionControl={false}
40
40
+
dragPan={false}
41
41
+
dragRotate={false}
42
42
+
keyboard={false}
43
43
+
touchZoomRotate={true}
44
44
+
scrollZoom={true}
45
45
+
boxZoom={false}
46
46
+
pitchWithRotate={false}
47
47
+
touchPitch={false}
48
48
+
onzoom={handleZoom}
49
49
+
>
50
50
+
<Projection type="globe" />
28
51
29
29
-
<Marker bind:lnglat={center}>
30
30
-
{#snippet content()}
31
31
-
<div class="from-accent-400 size-10 rounded-full bg-radial via-transparent p-3">
32
32
-
<div class="bg-accent-500 size-4 rounded-full ring-2 ring-white"></div>
33
33
-
</div>
34
34
-
{/snippet}
35
35
-
</Marker>
36
36
-
</MapLibre>
52
52
+
<Marker bind:lnglat={center}>
53
53
+
{#snippet content()}
54
54
+
<div class="from-accent-400 size-10 rounded-full bg-radial via-transparent p-3">
55
55
+
<div class="bg-accent-500 size-4 rounded-full ring-2 ring-white"></div>
56
56
+
</div>
57
57
+
{/snippet}
58
58
+
</Marker>
59
59
+
</MapLibre>
60
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
14
-
<Map bind:item />
14
14
+
<Map bind:item {isEditing} />
15
15
16
16
{#if item.cardData.linkToGoogleMaps && !isEditing}
17
17
<a