@m3ui-vue/m3ui-vue 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/API.md +666 -12
- package/dist/MMenuItem-BOkcVtEe.js +809 -0
- package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
- package/dist/MSlider-BXsBv0ox.js +1402 -0
- package/dist/MSlider-BXsBv0ox.js.map +1 -0
- package/dist/MTextField-rML9jnXs.js +671 -0
- package/dist/MTextField-rML9jnXs.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +20 -1
- package/dist/components/MDialog.vue.d.ts +17 -8
- package/dist/components/MDragDropList.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +74 -0
- package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
- package/dist/components/MMapControl.vue.d.ts +40 -0
- package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
- package/dist/components/MMapFilter.vue.d.ts +19 -0
- package/dist/components/MMapGeoJson.vue.d.ts +34 -0
- package/dist/components/MMapHover.vue.d.ts +17 -0
- package/dist/components/MMapIdentify.vue.d.ts +37 -0
- package/dist/components/MMapLayers.vue.d.ts +31 -0
- package/dist/components/MMapMarker.vue.d.ts +45 -0
- package/dist/components/MMapMeasure.vue.d.ts +43 -0
- package/dist/components/MMapPopup.vue.d.ts +45 -0
- package/dist/components/MMapSearch.vue.d.ts +28 -0
- package/dist/components/MMenuItem.vue.d.ts +2 -2
- package/dist/components/MSeekBar.vue.d.ts +122 -0
- package/dist/components/MSplitButton.vue.d.ts +2 -2
- package/dist/components/_MMapAttribution.vue.d.ts +7 -0
- package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
- package/dist/composables/_mapGeometry.d.ts +13 -0
- package/dist/composables/_mapPin.d.ts +5 -0
- package/dist/composables/_popupPosition.d.ts +12 -0
- package/dist/composables/_ssrState.d.ts +30 -0
- package/dist/composables/_storageKeys.d.ts +3 -0
- package/dist/composables/_useCalendarMonth.d.ts +24 -0
- package/dist/composables/_useEscapeStack.d.ts +3 -0
- package/dist/composables/_useScrollLock.d.ts +8 -0
- package/dist/composables/_useSheetMotion.d.ts +16 -1
- package/dist/composables/_useThemeTokens.d.ts +7 -0
- package/dist/composables/mapAdapters.d.ts +111 -0
- package/dist/composables/mapSearch.d.ts +31 -0
- package/dist/composables/themeInitScript.d.ts +4 -3
- package/dist/composables/useColorPalette.d.ts +173 -7
- package/dist/composables/useLocale.d.ts +38 -0
- package/dist/composables/useMap.d.ts +47 -0
- package/dist/composables/useMapFilter.d.ts +10 -0
- package/dist/composables/useMapLayers.d.ts +30 -0
- package/dist/composables/useTheme.d.ts +2 -1
- package/dist/index.d.ts +4 -1
- package/dist/locales/index.js +273 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7913 -8625
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +24 -0
- package/dist/map.js +2067 -0
- package/dist/map.js.map +1 -0
- package/dist/plugin.d.ts +18 -2
- package/dist/rich-text-editor.js +26 -25
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CuvWRZ1h.js → useLocale-CqQrhWFl.js} +40 -2
- package/dist/useLocale-CqQrhWFl.js.map +1 -0
- package/package.json +11 -2
- package/src/__tests__/MDialog.test.ts +30 -0
- package/src/__tests__/MFab.test.ts +52 -6
- package/src/__tests__/MMap.test.ts +422 -0
- package/src/__tests__/MMapLayers.test.ts +257 -0
- package/src/__tests__/MMapTools.test.ts +233 -0
- package/src/__tests__/MSeekBar.test.ts +170 -0
- package/src/__tests__/MTooltip.test.ts +110 -0
- package/src/__tests__/_fakeMaplibre.ts +161 -0
- package/src/__tests__/calendarMonth.test.ts +59 -0
- package/src/__tests__/hydration.test.ts +33 -0
- package/src/__tests__/pickerModals.test.ts +128 -0
- package/src/__tests__/popupPosition.test.ts +224 -0
- package/src/__tests__/scrollLock.test.ts +110 -0
- package/src/__tests__/sheets.test.ts +158 -0
- package/src/__tests__/ssr.test.ts +63 -1
- package/src/__tests__/ssrState.test.ts +155 -0
- package/src/__tests__/themeInitScript.test.ts +18 -0
- package/src/components/MAutocomplete.vue +2 -4
- package/src/components/MBottomSheet.vue +211 -13
- package/src/components/MCommandPalette.vue +4 -6
- package/src/components/MContextMenu.vue +19 -5
- package/src/components/MDatePicker.vue +29 -70
- package/src/components/MDatePickerModal.vue +116 -172
- package/src/components/MDateRangePicker.vue +29 -51
- package/src/components/MDateRangePickerModal.vue +84 -162
- package/src/components/MDialog.vue +87 -63
- package/src/components/MFab.vue +29 -7
- package/src/components/MIconButton.vue +1 -1
- package/src/components/MLightbox.vue +12 -5
- package/src/components/MMap.vue +568 -0
- package/src/components/MMapBaseLayers.vue +67 -0
- package/src/components/MMapControl.vue +175 -0
- package/src/components/MMapFeatureInfo.vue +41 -0
- package/src/components/MMapFilter.vue +80 -0
- package/src/components/MMapGeoJson.vue +136 -0
- package/src/components/MMapHover.vue +131 -0
- package/src/components/MMapIdentify.vue +104 -0
- package/src/components/MMapLayers.vue +111 -0
- package/src/components/MMapMarker.vue +109 -0
- package/src/components/MMapMeasure.vue +452 -0
- package/src/components/MMapPopup.vue +103 -0
- package/src/components/MMapSearch.vue +162 -0
- package/src/components/MMenu.vue +31 -12
- package/src/components/MMenuItem.vue +21 -4
- package/src/components/MMultiAutocomplete.vue +2 -4
- package/src/components/MMultiSelect.vue +2 -4
- package/src/components/MNavigationDrawer.vue +2 -8
- package/src/components/MNavigationRail.vue +2 -3
- package/src/components/MSearchBar.vue +2 -5
- package/src/components/MSeekBar.vue +593 -0
- package/src/components/MSelect.vue +2 -8
- package/src/components/MSplitButton.vue +23 -7
- package/src/components/MSpotlightSearch.vue +4 -6
- package/src/components/MTimePicker.vue +23 -6
- package/src/components/MTimePickerModal.vue +213 -226
- package/src/components/MTooltip.vue +99 -3
- package/src/components/_MMapAttribution.vue +81 -0
- package/src/components/_MMapLayerItem.vue +77 -0
- package/src/composables/_mapGeometry.ts +75 -0
- package/src/composables/_mapPin.ts +25 -0
- package/src/composables/_popupPosition.ts +39 -0
- package/src/composables/_ssrState.ts +80 -0
- package/src/composables/_storageKeys.ts +6 -0
- package/src/composables/_useCalendarMonth.ts +74 -0
- package/src/composables/_useEscapeStack.ts +33 -0
- package/src/composables/_useScrollLock.ts +41 -0
- package/src/composables/_useSheetMotion.ts +82 -20
- package/src/composables/_useThemeTokens.ts +42 -0
- package/src/composables/mapAdapters.ts +208 -0
- package/src/composables/mapSearch.ts +56 -0
- package/src/composables/themeInitScript.ts +6 -4
- package/src/composables/useColorPalette.ts +23 -9
- package/src/composables/useLocale.ts +78 -0
- package/src/composables/useMap.ts +98 -0
- package/src/composables/useMapFilter.ts +45 -0
- package/src/composables/useMapLayers.ts +124 -0
- package/src/composables/useTheme.ts +8 -3
- package/src/composables/useWindowSizeClass.ts +14 -5
- package/src/index.ts +4 -1
- package/src/locales/de.ts +39 -1
- package/src/locales/es.ts +39 -1
- package/src/locales/fr.ts +39 -1
- package/src/locales/ja.ts +39 -1
- package/src/locales/ko.ts +39 -1
- package/src/locales/pt.ts +39 -1
- package/src/locales/zh.ts +39 -1
- package/src/map.ts +32 -0
- package/src/plugin.ts +54 -3
- package/dist/MTextField-BPbFeI9M.js +0 -1368
- package/dist/MTextField-BPbFeI9M.js.map +0 -1
- package/dist/useLocale-CuvWRZ1h.js.map +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The base layer switcher of an `MMap` with an `adapter`: a round thumbnail per base layer (the adapter's `image`,
|
|
4
|
+
* after `imageBase`), one shown at a time, plus "no base layer". Only the thumbnails: put them in an `MMapControl`
|
|
5
|
+
* (`:group="false"`), an `MFab`'s `#content` or a panel. Available from the `/map` entry point.
|
|
6
|
+
*/
|
|
7
|
+
import MIcon from './MIcon.vue'
|
|
8
|
+
import { useLocale } from '../composables/useLocale'
|
|
9
|
+
import { useMapLayers } from '../composables/useMapLayers'
|
|
10
|
+
|
|
11
|
+
withDefaults(
|
|
12
|
+
defineProps<{
|
|
13
|
+
/** Prefix for the thumbnails' paths (e.g. `/images/`); full URLs are used as they are */
|
|
14
|
+
imageBase?: string
|
|
15
|
+
/** Offer "no base layer" */
|
|
16
|
+
none?: boolean
|
|
17
|
+
/** Lay them out in a column */
|
|
18
|
+
vertical?: boolean
|
|
19
|
+
}>(),
|
|
20
|
+
{ imageBase: '', none: true, vertical: false },
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const t = useLocale()
|
|
24
|
+
const { baseLayers, baseLayer, setBaseLayer } = useMapLayers()
|
|
25
|
+
|
|
26
|
+
const src = (image: string, base: string) => (/^(https?:|data:|\/\/)/.test(image) ? image : `${base}${image}`)
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<div class="flex gap-2" :class="vertical ? 'flex-col' : 'flex-row flex-wrap'" role="radiogroup">
|
|
31
|
+
<button
|
|
32
|
+
v-for="layer in baseLayers"
|
|
33
|
+
:key="layer.id"
|
|
34
|
+
type="button"
|
|
35
|
+
role="radio"
|
|
36
|
+
class="m3-map-base grid size-12 shrink-0 cursor-pointer place-items-center overflow-hidden rounded-full border-2 bg-surface-variant transition-[border-color,transform] duration-150 hover:scale-110"
|
|
37
|
+
:class="baseLayer === layer.id ? 'm3-map-base--active border-primary' : 'border-transparent'"
|
|
38
|
+
:title="layer.title"
|
|
39
|
+
:aria-label="layer.title"
|
|
40
|
+
:aria-checked="baseLayer === layer.id"
|
|
41
|
+
@click="setBaseLayer(layer.id)"
|
|
42
|
+
>
|
|
43
|
+
<img v-if="layer.base?.image" :src="src(layer.base.image, imageBase)" alt="" class="size-full object-cover">
|
|
44
|
+
<MIcon v-else name="map" :size="22" class="text-on-surface-variant" />
|
|
45
|
+
</button>
|
|
46
|
+
<button
|
|
47
|
+
v-if="none"
|
|
48
|
+
type="button"
|
|
49
|
+
role="radio"
|
|
50
|
+
class="m3-map-base grid size-12 shrink-0 cursor-pointer place-items-center rounded-full border-2 bg-surface-variant transition-[border-color,transform] duration-150 hover:scale-110"
|
|
51
|
+
:class="baseLayer === null ? 'm3-map-base--active border-primary' : 'border-transparent'"
|
|
52
|
+
:title="t.mapNoBaseLayer"
|
|
53
|
+
:aria-label="t.mapNoBaseLayer"
|
|
54
|
+
:aria-checked="baseLayer === null"
|
|
55
|
+
@click="setBaseLayer(null)"
|
|
56
|
+
>
|
|
57
|
+
<MIcon name="layers_clear" :size="22" class="text-on-surface-variant" />
|
|
58
|
+
</button>
|
|
59
|
+
</div>
|
|
60
|
+
</template>
|
|
61
|
+
|
|
62
|
+
<style>
|
|
63
|
+
/* Inactive thumbnails in gray, the active one in color */
|
|
64
|
+
.m3-map-base:not(.m3-map-base--active) img {
|
|
65
|
+
filter: grayscale(1) opacity(0.6);
|
|
66
|
+
}
|
|
67
|
+
</style>
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Your own control in a corner of an `MMap`, stacked with MapLibre's (zoom, geolocate…) in that corner. With `group`
|
|
4
|
+
* (the default) it's a control group like the zoom buttons: put `<button>`s with a Material Symbols icon in it and
|
|
5
|
+
* they get the same M3 look. Without it, anything goes (an `MFab`, an `MSearchBar`, a card). With a `#panel` slot it
|
|
6
|
+
* expands in place: a button in it calls `toggle` and the control grows into a panel with your content (a layer
|
|
7
|
+
* picker, filters, a legend), and back. Its size springs whenever its content changes size, so the other controls in
|
|
8
|
+
* the corner move along instead of jumping. Available from the `/map` entry point.
|
|
9
|
+
*
|
|
10
|
+
* @slot default The control's content; `{ expanded, toggle }` when it has a `#panel`
|
|
11
|
+
* @slot panel What the control expands into (`v-model:expanded`); `{ close }`. Escape or a press outside it closes it
|
|
12
|
+
* @event update:expanded Emitted when the panel opens or closes — powers v-model:expanded
|
|
13
|
+
*/
|
|
14
|
+
import { computed, onBeforeUnmount, onMounted, ref, useSlots, watch } from 'vue'
|
|
15
|
+
import type * as Maplibre from 'maplibre-gl'
|
|
16
|
+
import { useMap } from '../composables/useMap'
|
|
17
|
+
import { motionSprings } from '../composables/motion'
|
|
18
|
+
import { playSamples, prefersReducedMotion, sampleAt, sampleSpring } from '../composables/_springAnimation'
|
|
19
|
+
import type { MapControlPosition } from './MMap.vue'
|
|
20
|
+
|
|
21
|
+
// Attributes (class, style…) go on what's shown on the map, not on the hidden wrapper it's rendered in
|
|
22
|
+
defineOptions({ inheritAttrs: false })
|
|
23
|
+
|
|
24
|
+
const props = withDefaults(
|
|
25
|
+
defineProps<{
|
|
26
|
+
/** The corner */
|
|
27
|
+
position?: MapControlPosition
|
|
28
|
+
/** Draw it as a control group (a surface with dividers between buttons), like MapLibre's zoom buttons */
|
|
29
|
+
group?: boolean
|
|
30
|
+
/** Expanded into its `#panel` (v-model:expanded) */
|
|
31
|
+
expanded?: boolean
|
|
32
|
+
/** Springs the control's size when its content changes size (expanding, or anything else) */
|
|
33
|
+
animate?: boolean
|
|
34
|
+
}>(),
|
|
35
|
+
{ position: 'top-right', group: true, expanded: false, animate: true },
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{ 'update:expanded': [boolean] }>()
|
|
39
|
+
const slots = useSlots()
|
|
40
|
+
|
|
41
|
+
const el = ref<HTMLElement>()
|
|
42
|
+
const { onReady } = useMap()
|
|
43
|
+
|
|
44
|
+
// ── Expanding into the panel ────────────────────────────────────────────────────────────────────────────
|
|
45
|
+
const open = ref(props.expanded)
|
|
46
|
+
watch(() => props.expanded, (v) => { open.value = v })
|
|
47
|
+
const showPanel = computed(() => open.value && !!slots.panel)
|
|
48
|
+
function setOpen(v: boolean) {
|
|
49
|
+
if (v === open.value) return
|
|
50
|
+
open.value = v
|
|
51
|
+
emit('update:expanded', v)
|
|
52
|
+
}
|
|
53
|
+
const toggle = () => setOpen(!open.value)
|
|
54
|
+
const close = () => setOpen(false)
|
|
55
|
+
|
|
56
|
+
function onOutside(e: PointerEvent) {
|
|
57
|
+
if (showPanel.value && !el.value?.contains(e.target as Node)) close()
|
|
58
|
+
}
|
|
59
|
+
function onKeyDown(e: KeyboardEvent) {
|
|
60
|
+
if (e.key === 'Escape' && showPanel.value) {
|
|
61
|
+
close()
|
|
62
|
+
e.stopPropagation()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ── Size: a spring between the old and the new size whenever the content resizes (Standard DefaultSpatial).
|
|
67
|
+
// The new layout is already there when the ResizeObserver reports it, before it paints, so the animation starts
|
|
68
|
+
// from the old size without a flash; the content is clipped while it runs. Width/height can't run on the
|
|
69
|
+
// compositor, but a control is small. ──────────────────────────────────────────────────────────────────────
|
|
70
|
+
let size: { w: number; h: number } | null = null
|
|
71
|
+
let anim: Animation | null = null
|
|
72
|
+
let samples: number[] = []
|
|
73
|
+
let from = { w: 0, h: 0 }
|
|
74
|
+
let to = { w: 0, h: 0 }
|
|
75
|
+
let observer: ResizeObserver | null = null
|
|
76
|
+
|
|
77
|
+
function measure(): { w: number; h: number } {
|
|
78
|
+
return { w: el.value!.offsetWidth, h: el.value!.offsetHeight }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function onResize() {
|
|
82
|
+
const node = el.value
|
|
83
|
+
if (!node || anim) return
|
|
84
|
+
const next = measure()
|
|
85
|
+
if (size && (next.w !== size.w || next.h !== size.h) && props.animate && !prefersReducedMotion()) grow(node, size, next)
|
|
86
|
+
size = next
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function grow(node: HTMLElement, a: { w: number; h: number }, b: { w: number; h: number }) {
|
|
90
|
+
from = a
|
|
91
|
+
to = b
|
|
92
|
+
samples = sampleSpring(0, 1, 0, motionSprings.standard.defaultSpatial, 0.002)
|
|
93
|
+
node.style.overflow = 'hidden'
|
|
94
|
+
const lerp = (p: number) => ({ width: `${a.w + (b.w - a.w) * p}px`, height: `${a.h + (b.h - a.h) * p}px` })
|
|
95
|
+
anim = playSamples(node, samples, lerp)
|
|
96
|
+
if (!anim) return finish(node)
|
|
97
|
+
anim.onfinish = () => finish(node)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function finish(node: HTMLElement) {
|
|
101
|
+
anim?.cancel()
|
|
102
|
+
anim = null
|
|
103
|
+
node.style.overflow = ''
|
|
104
|
+
// The content may have changed size again while it ran
|
|
105
|
+
const now = measure()
|
|
106
|
+
if (now.w !== to.w || now.h !== to.h) {
|
|
107
|
+
size = to
|
|
108
|
+
onResize()
|
|
109
|
+
} else size = now
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// A size change while it runs (closed mid-opening) starts from where it is, not from the old size
|
|
113
|
+
function retarget() {
|
|
114
|
+
const node = el.value
|
|
115
|
+
if (!node || !anim) return
|
|
116
|
+
const p = sampleAt(samples, anim.currentTime)
|
|
117
|
+
const at = { w: from.w + (to.w - from.w) * p, h: from.h + (to.h - from.h) * p }
|
|
118
|
+
anim.onfinish = null
|
|
119
|
+
anim.cancel()
|
|
120
|
+
anim = null
|
|
121
|
+
size = at
|
|
122
|
+
onResize()
|
|
123
|
+
}
|
|
124
|
+
watch(showPanel, retarget, { flush: 'post' })
|
|
125
|
+
|
|
126
|
+
let map: Maplibre.Map | undefined
|
|
127
|
+
// MapLibre's IControl: the element it places in the corner
|
|
128
|
+
const control: Maplibre.IControl = {
|
|
129
|
+
onAdd: () => el.value!,
|
|
130
|
+
onRemove: () => el.value?.remove(),
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
onReady((m) => {
|
|
134
|
+
map = m
|
|
135
|
+
if (el.value) m.addControl(control, props.position)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
watch(() => props.position, (position) => {
|
|
139
|
+
if (!map || !el.value) return
|
|
140
|
+
map.removeControl(control)
|
|
141
|
+
map.addControl(control, position)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
onMounted(() => {
|
|
145
|
+
document.addEventListener('pointerdown', onOutside, true)
|
|
146
|
+
if (typeof ResizeObserver === 'undefined' || !el.value) return
|
|
147
|
+
observer = new ResizeObserver(onResize)
|
|
148
|
+
observer.observe(el.value)
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
onBeforeUnmount(() => {
|
|
152
|
+
document.removeEventListener('pointerdown', onOutside, true)
|
|
153
|
+
observer?.disconnect()
|
|
154
|
+
anim?.cancel()
|
|
155
|
+
if (map?.hasControl(control)) map.removeControl(control)
|
|
156
|
+
})
|
|
157
|
+
</script>
|
|
158
|
+
|
|
159
|
+
<template>
|
|
160
|
+
<!-- Moved into the map's corner by MapLibre -->
|
|
161
|
+
<div class="hidden">
|
|
162
|
+
<div
|
|
163
|
+
ref="el"
|
|
164
|
+
class="maplibregl-ctrl m3-map-control"
|
|
165
|
+
:class="showPanel ? 'm3-map-control-panel' : group ? 'maplibregl-ctrl-group' : ''"
|
|
166
|
+
v-bind="$attrs"
|
|
167
|
+
@keydown="onKeyDown"
|
|
168
|
+
>
|
|
169
|
+
<div v-if="showPanel" class="m3-map-control-panel-in">
|
|
170
|
+
<slot name="panel" :close="close" />
|
|
171
|
+
</div>
|
|
172
|
+
<slot v-else :expanded="open" :toggle="toggle" />
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Identify results (from `MMapIdentify`'s `identify` event, or `identifyFeatures()`): a card per feature with its
|
|
4
|
+
* layer's name and its formatted properties. `MMapIdentify` shows it in a popup; use it in a panel of your own (an
|
|
5
|
+
* `MWindow`, an `MSideSheet`) the same way. Values are shown as text. Available from the `/map` entry point.
|
|
6
|
+
*
|
|
7
|
+
* @slot value A property's value (scope: `{ field, result }`), e.g. to turn URLs into links
|
|
8
|
+
*/
|
|
9
|
+
import MIcon from './MIcon.vue'
|
|
10
|
+
import { useLocale } from '../composables/useLocale'
|
|
11
|
+
import type { MapIdentifyResult } from '../composables/mapAdapters'
|
|
12
|
+
|
|
13
|
+
defineProps<{
|
|
14
|
+
/** What was found */
|
|
15
|
+
results: MapIdentifyResult[]
|
|
16
|
+
}>()
|
|
17
|
+
|
|
18
|
+
const t = useLocale()
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<div class="flex flex-col gap-2">
|
|
23
|
+
<div v-for="(result, i) in results" :key="i" class="overflow-hidden rounded-2xl bg-surface-container">
|
|
24
|
+
<div class="flex items-center gap-2 bg-primary-container/40 px-4 py-2">
|
|
25
|
+
<MIcon name="layers" :size="16" class="text-on-primary-container" />
|
|
26
|
+
<span class="text-label-large text-on-primary-container">{{ result.layer.title }}</span>
|
|
27
|
+
</div>
|
|
28
|
+
<dl class="flex flex-col px-4 py-1">
|
|
29
|
+
<div v-for="field in result.fields" :key="field.key" class="flex flex-col gap-0.5 border-b border-outline-variant py-1.5 last:border-b-0">
|
|
30
|
+
<dt class="text-label-small text-on-surface-variant">{{ field.label }}</dt>
|
|
31
|
+
<dd class="text-body-medium text-on-surface">
|
|
32
|
+
<slot name="value" :field="field" :result="result">
|
|
33
|
+
<span v-if="field.value" class="break-words">{{ field.value }}</span>
|
|
34
|
+
<span v-else class="text-body-small italic text-on-surface-variant">{{ t.mapNoValue }}</span>
|
|
35
|
+
</slot>
|
|
36
|
+
</dd>
|
|
37
|
+
</div>
|
|
38
|
+
</dl>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</template>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A simple filter for one layer of an `MMap`: chips for the values of one of its properties; the layer shows only the
|
|
4
|
+
* features with the selected ones (all of them with none selected). The values are `values`, or else the distinct
|
|
5
|
+
* ones among the layer's features loaded in the map. The style's own filter on the layer stays. For anything more
|
|
6
|
+
* involved, build your own on `useMapFilter()`. Available from the `/map` entry point.
|
|
7
|
+
*/
|
|
8
|
+
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
|
9
|
+
import MChip from './MChip.vue'
|
|
10
|
+
import { useMap } from '../composables/useMap'
|
|
11
|
+
import { useMapFilter } from '../composables/useMapFilter'
|
|
12
|
+
|
|
13
|
+
const props = defineProps<{
|
|
14
|
+
/** The layer's id */
|
|
15
|
+
layer: string
|
|
16
|
+
/** The property to filter by */
|
|
17
|
+
property: string
|
|
18
|
+
/** The values to offer (labels in `labels`); by default the ones found in the layer's loaded features */
|
|
19
|
+
values?: (string | number)[]
|
|
20
|
+
/** Labels for the values, by value */
|
|
21
|
+
labels?: Record<string, string>
|
|
22
|
+
/** The selected values (v-model) */
|
|
23
|
+
modelValue?: (string | number)[]
|
|
24
|
+
}>()
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits<{ 'update:modelValue': [values: (string | number)[]] }>()
|
|
27
|
+
|
|
28
|
+
const { onReady, styleVersion } = useMap()
|
|
29
|
+
const { setFilter, valuesOf } = useMapFilter()
|
|
30
|
+
|
|
31
|
+
const found = ref<(string | number)[]>([])
|
|
32
|
+
const options = computed(() => props.values ?? found.value)
|
|
33
|
+
const local = ref<(string | number)[]>([])
|
|
34
|
+
const selected = computed(() => props.modelValue ?? local.value)
|
|
35
|
+
|
|
36
|
+
function apply() {
|
|
37
|
+
const values = selected.value
|
|
38
|
+
setFilter(props.layer, values.length ? ['in', ['get', props.property], ['literal', values]] : null)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function toggle(value: string | number) {
|
|
42
|
+
const next = selected.value.includes(value) ? selected.value.filter((v) => v !== value) : [...selected.value, value]
|
|
43
|
+
local.value = next
|
|
44
|
+
emit('update:modelValue', next)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function refreshValues(map: { once: (type: 'idle', fn: () => void) => unknown }) {
|
|
48
|
+
const read = () => { if (!props.values) found.value = valuesOf(props.layer, props.property) }
|
|
49
|
+
read()
|
|
50
|
+
// And once the layer's data is in, if it wasn't yet (tiles load after the style)
|
|
51
|
+
map.once('idle', read)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onReady((map) => {
|
|
55
|
+
refreshValues(map)
|
|
56
|
+
apply()
|
|
57
|
+
})
|
|
58
|
+
watch(selected, apply, { deep: true })
|
|
59
|
+
watch(styleVersion, () => apply())
|
|
60
|
+
watch(() => [props.layer, props.property], ([layer], [old]) => {
|
|
61
|
+
if (layer !== old) setFilter(old as string, null)
|
|
62
|
+
apply()
|
|
63
|
+
})
|
|
64
|
+
onBeforeUnmount(() => setFilter(props.layer, null))
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<template>
|
|
68
|
+
<div class="flex flex-wrap gap-2">
|
|
69
|
+
<MChip
|
|
70
|
+
v-for="value in options"
|
|
71
|
+
:key="value"
|
|
72
|
+
type="filter"
|
|
73
|
+
clickable
|
|
74
|
+
:selected="selected.includes(value)"
|
|
75
|
+
@click="toggle(value)"
|
|
76
|
+
>
|
|
77
|
+
{{ labels?.[String(value)] ?? value }}
|
|
78
|
+
</MChip>
|
|
79
|
+
</div>
|
|
80
|
+
</template>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* GeoJSON on an `MMap`: a source from `data` (an object, or a URL MapLibre fetches) drawn with `layers`. Without
|
|
4
|
+
* `layers` it draws every geometry in the theme's primary, following palette and dark mode: polygons filled with an
|
|
5
|
+
* outline, lines, and points as circles. Replace `data` (a new object) to update it. It's added again after a style
|
|
6
|
+
* change. Available from the `/map` entry point.
|
|
7
|
+
*
|
|
8
|
+
* @event click A click on one of its features (MapLibre's `MapLayerMouseEvent`: `e.features` holds them)
|
|
9
|
+
*/
|
|
10
|
+
import { computed, onBeforeUnmount, useId, watch } from 'vue'
|
|
11
|
+
import type * as Maplibre from 'maplibre-gl'
|
|
12
|
+
import { useMap } from '../composables/useMap'
|
|
13
|
+
import { useThemeTokens } from '../composables/_useThemeTokens'
|
|
14
|
+
|
|
15
|
+
// Omit over each member of the union (a plain Omit keeps only what all layer types share, losing paint and layout)
|
|
16
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never
|
|
17
|
+
|
|
18
|
+
/** A layer of `MMapGeoJson`: any MapLibre layer without its `source` (and `id`, made up when left out). */
|
|
19
|
+
export type MapGeoJsonLayer = DistributiveOmit<Exclude<Maplibre.LayerSpecification, Maplibre.BackgroundLayerSpecification>, 'id' | 'source'> & { id?: string }
|
|
20
|
+
|
|
21
|
+
// It renders nothing: no element for attributes to land on
|
|
22
|
+
defineOptions({ inheritAttrs: false })
|
|
23
|
+
|
|
24
|
+
const props = withDefaults(
|
|
25
|
+
defineProps<{
|
|
26
|
+
/** A GeoJSON object, or the URL of one */
|
|
27
|
+
data: Maplibre.GeoJSONSourceSpecification['data']
|
|
28
|
+
/** The source's id (and the prefix of its layers' made-up ids). Unique on the map; generated when left out */
|
|
29
|
+
id?: string
|
|
30
|
+
/** How to draw it: MapLibre layers without `source`. Defaults to theme-colored fill, outline, line and circle layers */
|
|
31
|
+
layers?: MapGeoJsonLayer[]
|
|
32
|
+
/** Insert the layers below this layer id (e.g. under the style's labels) */
|
|
33
|
+
before?: string
|
|
34
|
+
/** Show a pointer over its features (set it when you handle `click`) */
|
|
35
|
+
interactive?: boolean
|
|
36
|
+
/** More options for the GeoJSON source (`cluster`, `promoteId`, `tolerance`…) */
|
|
37
|
+
sourceOptions?: Partial<Omit<Maplibre.GeoJSONSourceSpecification, 'type' | 'data'>>
|
|
38
|
+
}>(),
|
|
39
|
+
{ interactive: false },
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const emit = defineEmits<{ click: [event: Maplibre.MapLayerMouseEvent] }>()
|
|
43
|
+
|
|
44
|
+
const sourceId = props.id ?? `m3-geojson-${useId()}`
|
|
45
|
+
const { onReady, styleVersion } = useMap()
|
|
46
|
+
const theme = useThemeTokens(['primary', 'surface'] as const)
|
|
47
|
+
|
|
48
|
+
const is = (...types: string[]): Maplibre.FilterSpecification => ['match', ['geometry-type'], types, true, false]
|
|
49
|
+
|
|
50
|
+
/** The theme-colored default layers. */
|
|
51
|
+
const defaultLayers = computed<MapGeoJsonLayer[]>(() => {
|
|
52
|
+
const { primary, surface } = theme.value
|
|
53
|
+
return [
|
|
54
|
+
{ id: `${sourceId}-fill`, type: 'fill', filter: is('Polygon', 'MultiPolygon'), paint: { 'fill-color': primary, 'fill-opacity': 0.24 } },
|
|
55
|
+
{ id: `${sourceId}-line`, type: 'line', filter: is('Polygon', 'MultiPolygon', 'LineString', 'MultiLineString'), paint: { 'line-color': primary, 'line-width': 2 } },
|
|
56
|
+
{
|
|
57
|
+
id: `${sourceId}-circle`,
|
|
58
|
+
type: 'circle',
|
|
59
|
+
filter: is('Point', 'MultiPoint'),
|
|
60
|
+
paint: { 'circle-color': primary, 'circle-radius': 6, 'circle-stroke-color': surface, 'circle-stroke-width': 2 },
|
|
61
|
+
},
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const layers = computed(() =>
|
|
66
|
+
(props.layers ?? defaultLayers.value).map((l, i) => ({ ...l, id: l.id ?? `${sourceId}-${i}`, source: sourceId }) as Maplibre.LayerSpecification),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
let map: Maplibre.Map | undefined
|
|
70
|
+
let added: string[] = []
|
|
71
|
+
|
|
72
|
+
const onClick = (e: Maplibre.MapLayerMouseEvent) => emit('click', e)
|
|
73
|
+
const onEnter = () => { if (props.interactive && map) map.getCanvas().style.cursor = 'pointer' }
|
|
74
|
+
const onLeave = () => { if (props.interactive && map) map.getCanvas().style.cursor = '' }
|
|
75
|
+
|
|
76
|
+
function removeLayers() {
|
|
77
|
+
if (!map) return
|
|
78
|
+
for (const id of added) {
|
|
79
|
+
map.off('click', id, onClick)
|
|
80
|
+
map.off('mouseenter', id, onEnter)
|
|
81
|
+
map.off('mouseleave', id, onLeave)
|
|
82
|
+
if (map.getLayer(id)) map.removeLayer(id)
|
|
83
|
+
}
|
|
84
|
+
added = []
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function addLayers() {
|
|
88
|
+
if (!map) return
|
|
89
|
+
removeLayers()
|
|
90
|
+
for (const layer of layers.value) {
|
|
91
|
+
map.addLayer(layer, props.before && map.getLayer(props.before) ? props.before : undefined)
|
|
92
|
+
map.on('click', layer.id, onClick)
|
|
93
|
+
map.on('mouseenter', layer.id, onEnter)
|
|
94
|
+
map.on('mouseleave', layer.id, onLeave)
|
|
95
|
+
added.push(layer.id)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The source and its layers, unless they're there already (a style change drops them). */
|
|
100
|
+
function add() {
|
|
101
|
+
if (!map) return
|
|
102
|
+
if (!map.getSource(sourceId)) {
|
|
103
|
+
map.addSource(sourceId, { type: 'geojson', data: props.data, ...props.sourceOptions })
|
|
104
|
+
added = []
|
|
105
|
+
}
|
|
106
|
+
if (!added.length || !map.getLayer(added[0]!)) addLayers()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
onReady((m) => {
|
|
110
|
+
map = m
|
|
111
|
+
add()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
watch(styleVersion, () => add())
|
|
115
|
+
watch(() => props.data, (data) => (map?.getSource(sourceId) as Maplibre.GeoJSONSource | undefined)?.setData(data))
|
|
116
|
+
// Layers by value: an inline `:layers="[...]"` is a new array on every parent render
|
|
117
|
+
watch(() => JSON.stringify(layers.value), () => addLayers())
|
|
118
|
+
watch(() => props.before, () => addLayers())
|
|
119
|
+
|
|
120
|
+
onBeforeUnmount(() => {
|
|
121
|
+
if (!map) return
|
|
122
|
+
removeLayers()
|
|
123
|
+
if (map.getSource(sourceId)) map.removeSource(sourceId)
|
|
124
|
+
map = undefined
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
defineExpose({
|
|
128
|
+
/** The source's id */
|
|
129
|
+
sourceId,
|
|
130
|
+
/** The ids of its layers on the map */
|
|
131
|
+
layerIds: () => [...added],
|
|
132
|
+
})
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<!-- Nothing of its own: it draws on the map -->
|
|
136
|
+
<template></template>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Hover info for an `MMap` with an `adapter`: while on (v-model), the layers with `hover` fields show them for the
|
|
4
|
+
* feature under the pointer, in a small popup that follows it. With `control` (on by default) it adds its own on/off
|
|
5
|
+
* button to the map's controls. Pointer devices only: touch has no hover. Available from the `/map` entry point.
|
|
6
|
+
*
|
|
7
|
+
* @event update:modelValue Turned on or off with its button
|
|
8
|
+
*/
|
|
9
|
+
import { computed, onBeforeUnmount, ref, shallowRef, watch } from 'vue'
|
|
10
|
+
import type * as Maplibre from 'maplibre-gl'
|
|
11
|
+
import MIcon from './MIcon.vue'
|
|
12
|
+
import MMapControl from './MMapControl.vue'
|
|
13
|
+
import MMapPopup from './MMapPopup.vue'
|
|
14
|
+
import { useLocale } from '../composables/useLocale'
|
|
15
|
+
import { useMap } from '../composables/useMap'
|
|
16
|
+
import { useMapLayers } from '../composables/useMapLayers'
|
|
17
|
+
import { formatFieldValue, fieldLabel, type MapLayerInfo } from '../composables/mapAdapters'
|
|
18
|
+
import type { MapControlPosition } from './MMap.vue'
|
|
19
|
+
|
|
20
|
+
const props = withDefaults(
|
|
21
|
+
defineProps<{
|
|
22
|
+
/** On (v-model) */
|
|
23
|
+
modelValue?: boolean
|
|
24
|
+
/** Its on/off button: `false`, or a corner (`true` is top-right) */
|
|
25
|
+
control?: boolean | MapControlPosition
|
|
26
|
+
}>(),
|
|
27
|
+
{ modelValue: false, control: true },
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{ 'update:modelValue': [on: boolean] }>()
|
|
31
|
+
|
|
32
|
+
const t = useLocale()
|
|
33
|
+
const { onReady } = useMap()
|
|
34
|
+
const { model } = useMapLayers()
|
|
35
|
+
|
|
36
|
+
const hoverLayers = computed(() => (model.value?.layers ?? []).filter((l) => l.hover && l.hover.fields.length))
|
|
37
|
+
const shown = shallowRef<{ layer: MapLayerInfo; fields: { key: string; label: string; value: string }[] } | null>(null)
|
|
38
|
+
const lngLat = ref<[number, number]>([0, 0])
|
|
39
|
+
const open = ref(false)
|
|
40
|
+
|
|
41
|
+
let map: Maplibre.Map | undefined
|
|
42
|
+
let bound: string[] = []
|
|
43
|
+
|
|
44
|
+
function move(e: Maplibre.MapLayerMouseEvent) {
|
|
45
|
+
const feature = e.features?.[0]
|
|
46
|
+
const layer = hoverLayers.value.find((l) => l.id === feature?.layer.id)
|
|
47
|
+
if (!feature || !layer || !layer.hover) return
|
|
48
|
+
const props = feature.properties ?? {}
|
|
49
|
+
shown.value = {
|
|
50
|
+
layer,
|
|
51
|
+
fields: layer.hover.fields
|
|
52
|
+
.map((f) => ({ key: f.key, label: fieldLabel(f.key, f), value: formatFieldValue(props[f.key], f) }))
|
|
53
|
+
.filter((f) => f.value),
|
|
54
|
+
}
|
|
55
|
+
lngLat.value = [e.lngLat.lng, e.lngLat.lat]
|
|
56
|
+
open.value = true
|
|
57
|
+
}
|
|
58
|
+
function leave() {
|
|
59
|
+
open.value = false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function bind() {
|
|
63
|
+
if (!map) return
|
|
64
|
+
for (const id of bound) {
|
|
65
|
+
map.off('mousemove', id, move)
|
|
66
|
+
map.off('mouseleave', id, leave)
|
|
67
|
+
}
|
|
68
|
+
bound = props.modelValue ? hoverLayers.value.map((l) => l.id) : []
|
|
69
|
+
for (const id of bound) {
|
|
70
|
+
map.on('mousemove', id, move)
|
|
71
|
+
map.on('mouseleave', id, leave)
|
|
72
|
+
}
|
|
73
|
+
if (!props.modelValue) open.value = false
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onReady((m) => {
|
|
77
|
+
map = m
|
|
78
|
+
bind()
|
|
79
|
+
})
|
|
80
|
+
watch([() => props.modelValue, hoverLayers], bind)
|
|
81
|
+
onBeforeUnmount(() => {
|
|
82
|
+
for (const id of bound) {
|
|
83
|
+
map?.off('mousemove', id, move)
|
|
84
|
+
map?.off('mouseleave', id, leave)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const corner = computed(() => (props.control === true ? 'top-right' : props.control || 'top-right'))
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<template>
|
|
92
|
+
<div class="hidden">
|
|
93
|
+
<MMapControl v-if="control && hoverLayers.length" :position="corner">
|
|
94
|
+
<button
|
|
95
|
+
type="button"
|
|
96
|
+
class="grid place-items-center"
|
|
97
|
+
:title="t.mapHoverInfo"
|
|
98
|
+
:aria-label="t.mapHoverInfo"
|
|
99
|
+
:aria-pressed="modelValue"
|
|
100
|
+
@click="emit('update:modelValue', !modelValue)"
|
|
101
|
+
>
|
|
102
|
+
<MIcon name="ads_click" :size="20" />
|
|
103
|
+
</button>
|
|
104
|
+
</MMapControl>
|
|
105
|
+
<MMapPopup
|
|
106
|
+
v-if="shown"
|
|
107
|
+
v-model:open="open"
|
|
108
|
+
:lng-lat="lngLat"
|
|
109
|
+
:close-button="false"
|
|
110
|
+
:close-on-click="false"
|
|
111
|
+
:offset="12"
|
|
112
|
+
max-width="280px"
|
|
113
|
+
class="m3-map-hover"
|
|
114
|
+
>
|
|
115
|
+
<p class="-mx-4 -mt-3 mb-1 bg-primary-container px-3 py-1.5 text-label-medium text-on-primary-container">{{ shown.layer.title }}</p>
|
|
116
|
+
<dl class="flex flex-col">
|
|
117
|
+
<div v-for="field in shown.fields" :key="field.key" class="border-b border-outline-variant py-1 last:border-b-0">
|
|
118
|
+
<dt class="text-label-small text-on-surface-variant">{{ field.label }}</dt>
|
|
119
|
+
<dd class="text-body-small text-on-surface">{{ field.value }}</dd>
|
|
120
|
+
</div>
|
|
121
|
+
</dl>
|
|
122
|
+
</MMapPopup>
|
|
123
|
+
</div>
|
|
124
|
+
</template>
|
|
125
|
+
|
|
126
|
+
<style>
|
|
127
|
+
/* The hover popup ignores the pointer, so it never steals the mousemove that keeps it open */
|
|
128
|
+
.maplibregl-popup:has(.m3-map-hover) {
|
|
129
|
+
pointer-events: none;
|
|
130
|
+
}
|
|
131
|
+
</style>
|