@aiaiai-pt/design-system 0.59.0 → 0.61.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/components/ActionFormRenderer.svelte +67 -21
- package/components/ActionFormRenderer.svelte.d.ts +10 -0
- package/components/MapDisplay.svelte +59 -4
- package/components/MapDisplay.svelte.d.ts +11 -1
- package/components/MapPicker.svelte +334 -34
- package/components/MapPicker.svelte.d.ts +33 -3
- package/components/action-form-renderer-widgets.d.ts +30 -0
- package/components/action-form-renderer-widgets.ts +83 -0
- package/components/map-geometry.d.ts +46 -0
- package/components/map-geometry.ts +253 -0
- package/components/map-utils.d.ts +15 -4
- package/components/map-utils.js +60 -1
- package/components/renderer/display.d.ts +12 -1
- package/components/renderer/display.ts +16 -1
- package/package.json +5 -1
- package/tokens/components.css +8 -0
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component MapPicker
|
|
3
3
|
|
|
4
|
-
Interactive map for selecting a point or drawing
|
|
4
|
+
Interactive map for selecting a point or drawing shapes.
|
|
5
5
|
OpenLayers with configurable tiles and Draw interaction.
|
|
6
|
+
Modes and the GeoJSON type each one emits (atelier#2838):
|
|
7
|
+
point → Point (`value` / `onchange` speak [lon, lat]);
|
|
8
|
+
multipoint → MultiPoint; linestring → LineString;
|
|
9
|
+
multilinestring → MultiLineString; polygon → Polygon;
|
|
10
|
+
multipolygon → MultiPolygon. Shape modes take and report a GeoJSON
|
|
11
|
+
geometry of EXACTLY their type through `geometry` / `ongeometry` (null
|
|
12
|
+
when every shape is removed); a `geometry` of another type is not drawn
|
|
13
|
+
and fails loud through the field error. Shape modes add a drawing
|
|
14
|
+
toolbar (clear; multi modes also count + delete selected), select-by-
|
|
15
|
+
click, vertex dragging (alt+click removes a vertex), and keyboard keys
|
|
16
|
+
on the focused map: Enter finishes a sketch, Escape cancels it (or
|
|
17
|
+
deselects), Backspace removes the last sketched vertex, Delete removes
|
|
18
|
+
the selected shape.
|
|
6
19
|
Draw sketch styled with DS tokens (not OL blue default).
|
|
7
20
|
Built-in GeoSearch (Nominatim) for address lookup + pan.
|
|
8
21
|
Consumes --map-* tokens from components.css.
|
|
@@ -14,7 +27,10 @@
|
|
|
14
27
|
<MapPicker mode="point" search={false} onchange={(coords) => console.log(coords)} />
|
|
15
28
|
|
|
16
29
|
@example Polygon drawing
|
|
17
|
-
<MapPicker mode="polygon"
|
|
30
|
+
<MapPicker mode="polygon" ongeometry={(polygon) => console.log(polygon)} />
|
|
31
|
+
|
|
32
|
+
@example Several polygons → one MultiPolygon
|
|
33
|
+
<MapPicker mode="multipolygon" bind:geometry={area} />
|
|
18
34
|
-->
|
|
19
35
|
<script module>
|
|
20
36
|
let _mappickerUid = 0;
|
|
@@ -31,18 +47,34 @@
|
|
|
31
47
|
pointInRings,
|
|
32
48
|
watchTheme,
|
|
33
49
|
renderMapError,
|
|
50
|
+
cssPx,
|
|
34
51
|
} from './map-utils.js';
|
|
52
|
+
import {
|
|
53
|
+
MAP_PICKER_MODES,
|
|
54
|
+
POSITION_DEPTH,
|
|
55
|
+
composeGeometry,
|
|
56
|
+
decomposeGeometry,
|
|
57
|
+
mapPositions,
|
|
58
|
+
} from './map-geometry';
|
|
59
|
+
import { untrack } from 'svelte';
|
|
60
|
+
import Button from './Button.svelte';
|
|
35
61
|
import GeoSearch from './GeoSearch.svelte';
|
|
36
62
|
|
|
37
63
|
let {
|
|
38
|
-
/** @type {'
|
|
64
|
+
/** @type {import('./map-geometry').MapPickerMode} */
|
|
39
65
|
mode = 'point',
|
|
40
66
|
/** @type {[number, number]} — initial center [lon, lat] */
|
|
41
67
|
center = [0, 0],
|
|
42
68
|
/** @type {number} */
|
|
43
69
|
zoom = 12,
|
|
44
|
-
/** @type {[number, number] | undefined} — current point value [lon, lat]
|
|
70
|
+
/** @type {[number, number] | undefined} — current point value [lon, lat]
|
|
71
|
+
* (point mode) */
|
|
45
72
|
value = $bindable(undefined),
|
|
73
|
+
/** @type {import('./map-geometry').GeoJsonGeometry | null | undefined}
|
|
74
|
+
* Shape modes: the current GeoJSON geometry, of exactly the mode's type
|
|
75
|
+
* (see the mode table above). Drawn on mount and whenever it changes
|
|
76
|
+
* from outside; updated (bindable) on every edit. */
|
|
77
|
+
geometry = $bindable(undefined),
|
|
46
78
|
/** @type {string | undefined} */
|
|
47
79
|
label = undefined,
|
|
48
80
|
/** @type {string | undefined} */
|
|
@@ -71,8 +103,28 @@
|
|
|
71
103
|
* `boundary` is set. The pin still lands — surfacing/blocking is the
|
|
72
104
|
* consumer's call (the intake hard-gate is server-side regardless). */
|
|
73
105
|
onoutofbounds = undefined,
|
|
74
|
-
/** @type {((coords: [number, number] | number[][]) => void) | undefined}
|
|
106
|
+
/** @type {((coords: [number, number] | number[][]) => void) | undefined}
|
|
107
|
+
* Legacy payloads: point → [lon, lat]; polygon → the outer ring. Shape
|
|
108
|
+
* modes report through `ongeometry`. */
|
|
75
109
|
onchange = undefined,
|
|
110
|
+
/** @type {((geometry: import('./map-geometry').GeoJsonGeometry | null) => void) | undefined}
|
|
111
|
+
* Shape modes: fired after every draw, vertex edit, delete or clear
|
|
112
|
+
* with the GeoJSON geometry of exactly the mode's type (polygon rings
|
|
113
|
+
* wound per RFC 7946), or null when no shape is left. */
|
|
114
|
+
ongeometry = undefined,
|
|
115
|
+
/** @type {string} — shape modes: delete-selected button (multi modes) */
|
|
116
|
+
deleteSelectedLabel = 'Delete selected',
|
|
117
|
+
/** @type {string} — shape modes: clear-all button */
|
|
118
|
+
clearLabel = 'Clear',
|
|
119
|
+
/** @type {string} — shape modes: accessible name of the toolbar */
|
|
120
|
+
toolbarLabel = 'Drawing tools',
|
|
121
|
+
/** @type {(count: number, drawType: 'Point' | 'LineString' | 'Polygon') => string}
|
|
122
|
+
* Multi modes: the live shape count ("2 polygons"). */
|
|
123
|
+
countLabel = defaultCountLabel,
|
|
124
|
+
/** @type {string | undefined} — shape modes: how to draw with pointer
|
|
125
|
+
* and keyboard; shown as the help text when no `help` is given.
|
|
126
|
+
* Defaults to English copy for the mode. */
|
|
127
|
+
instructionsLabel = undefined,
|
|
76
128
|
/** @type {((displayName: string) => void) | undefined} — the resolved
|
|
77
129
|
* address whenever the pin settles (search pick or reverse geocode of a
|
|
78
130
|
* map click). Feed it to an address field; coords stay `onchange`. */
|
|
@@ -86,10 +138,35 @@
|
|
|
86
138
|
...rest
|
|
87
139
|
} = $props();
|
|
88
140
|
|
|
141
|
+
/** @param {number} count @param {'Point' | 'LineString' | 'Polygon'} drawType */
|
|
142
|
+
function defaultCountLabel(count, drawType) {
|
|
143
|
+
const noun = drawType === 'Point' ? 'point' : drawType === 'LineString' ? 'line' : 'polygon';
|
|
144
|
+
return `${count} ${noun}${count === 1 ? '' : 's'}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** @param {import('./map-geometry').MapPickerModeSpec} spec */
|
|
148
|
+
function defaultInstructions(spec) {
|
|
149
|
+
const replace = spec.multi ? '' : ' Drawing a new one replaces the current one.';
|
|
150
|
+
if (spec.drawType === 'Point') {
|
|
151
|
+
return 'Click the map to add a point. Drag a point to move it; click it to select it and press Delete to remove it.';
|
|
152
|
+
}
|
|
153
|
+
const what = spec.drawType === 'Polygon' ? 'shape' : 'line';
|
|
154
|
+
return `Click to add vertices; double-click or press Enter to finish. Escape cancels, Backspace removes the last vertex. Drag a vertex to move it (alt+click removes it). Click a ${what} to select it and press Delete to remove it.${replace}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const spec = $derived(MAP_PICKER_MODES[mode] ?? MAP_PICKER_MODES.point);
|
|
158
|
+
const shaped = $derived(mode !== 'point' && mode in MAP_PICKER_MODES);
|
|
159
|
+
// Shape modes: `geometry` is the single source of truth for what is
|
|
160
|
+
// drawn — the count and the hydration error derive from it.
|
|
161
|
+
const shapes = $derived(shaped ? decomposeGeometry(mode, geometry) : { parts: [], error: null });
|
|
162
|
+
const shapeCount = $derived(shapes.parts.length);
|
|
163
|
+
const fieldError = $derived(error ?? shapes.error ?? undefined);
|
|
164
|
+
const helpText = $derived(help ?? (shaped ? (instructionsLabel ?? defaultInstructions(spec)) : undefined));
|
|
165
|
+
|
|
89
166
|
const fallbackId = `mappicker-${_mappickerUid++}`;
|
|
90
167
|
const pickerId = $derived(id ?? fallbackId);
|
|
91
168
|
const hintId = $derived(`${pickerId}-hint`);
|
|
92
|
-
const hasHint = $derived(!!
|
|
169
|
+
const hasHint = $derived(!!fieldError || !!helpText);
|
|
93
170
|
|
|
94
171
|
/** @type {HTMLElement | undefined} */
|
|
95
172
|
let container = $state();
|
|
@@ -105,6 +182,107 @@
|
|
|
105
182
|
/** @type {any} */
|
|
106
183
|
let _Point;
|
|
107
184
|
|
|
185
|
+
// ── Shape-mode state ──
|
|
186
|
+
/** @type {any[]} — drawn OL features, in draw order (the emit order) */
|
|
187
|
+
let _drawn = [];
|
|
188
|
+
/** @type {any} — the shape Delete removes */
|
|
189
|
+
let _selected = $state.raw(null);
|
|
190
|
+
/** @type {any} — the Draw interaction */
|
|
191
|
+
let _draw;
|
|
192
|
+
/** @type {any} — OL geometry constructor for the mode's draw type */
|
|
193
|
+
let _ShapeGeom;
|
|
194
|
+
let _sketching = false;
|
|
195
|
+
let _justDrew = false;
|
|
196
|
+
/** JSON of the geometry last drawn or emitted — an incoming `geometry`
|
|
197
|
+
* equal to it is our own echo, not an outside change. */
|
|
198
|
+
let _lastGeometryJson = '';
|
|
199
|
+
|
|
200
|
+
/** @param {any} feature */
|
|
201
|
+
function setSelected(feature) {
|
|
202
|
+
_selected = feature;
|
|
203
|
+
_vectorSource?.changed();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function emitShapes() {
|
|
207
|
+
const depth = POSITION_DEPTH[spec.drawType];
|
|
208
|
+
const parts = _drawn.map((f) =>
|
|
209
|
+
mapPositions(f.getGeometry().getCoordinates(), depth, (c) => toLonLat(c)),
|
|
210
|
+
);
|
|
211
|
+
const next = composeGeometry(mode, parts);
|
|
212
|
+
_lastGeometryJson = JSON.stringify(next);
|
|
213
|
+
geometry = next;
|
|
214
|
+
ongeometry?.(next);
|
|
215
|
+
if (mode === 'polygon' && parts.length) {
|
|
216
|
+
onchange?.(/** @type {number[][]} */ (/** @type {any} */ (parts[parts.length - 1])[0]));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Draw `geom` (outside value) onto the source — never emits. */
|
|
221
|
+
function renderShapes(geom) {
|
|
222
|
+
if (!_vectorSource || !_Feature || !_ShapeGeom) return;
|
|
223
|
+
const depth = POSITION_DEPTH[spec.drawType];
|
|
224
|
+
const { parts } = decomposeGeometry(mode, geom);
|
|
225
|
+
_draw?.abortDrawing();
|
|
226
|
+
_vectorSource.clear();
|
|
227
|
+
_drawn = parts.map(
|
|
228
|
+
(part) =>
|
|
229
|
+
new _Feature({ geometry: new _ShapeGeom(mapPositions(part, depth, (p) => fromLonLat(p))) }),
|
|
230
|
+
);
|
|
231
|
+
_drawn.forEach((f) => _vectorSource.addFeature(f));
|
|
232
|
+
_selected = null;
|
|
233
|
+
_lastGeometryJson = JSON.stringify(geom ?? null);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function deleteSelected() {
|
|
237
|
+
if (!_selected) return;
|
|
238
|
+
_vectorSource?.removeFeature(_selected);
|
|
239
|
+
_drawn = _drawn.filter((f) => f !== _selected);
|
|
240
|
+
setSelected(null);
|
|
241
|
+
emitShapes();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function clearShapes() {
|
|
245
|
+
_draw?.abortDrawing();
|
|
246
|
+
_vectorSource?.clear();
|
|
247
|
+
_drawn = [];
|
|
248
|
+
setSelected(null);
|
|
249
|
+
emitShapes();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** @param {KeyboardEvent} e */
|
|
253
|
+
function handleShapeKeydown(e) {
|
|
254
|
+
if (!shaped || disabled) return;
|
|
255
|
+
if (e.key === 'Escape') {
|
|
256
|
+
if (_sketching) _draw?.abortDrawing();
|
|
257
|
+
else if (_selected) setSelected(null);
|
|
258
|
+
else return;
|
|
259
|
+
} else if (e.key === 'Enter') {
|
|
260
|
+
if (!_sketching) return;
|
|
261
|
+
_draw?.finishDrawing();
|
|
262
|
+
} else if (e.key === 'Backspace') {
|
|
263
|
+
if (_sketching) _draw?.removeLastPoint();
|
|
264
|
+
else if (_selected) deleteSelected();
|
|
265
|
+
else return;
|
|
266
|
+
} else if (e.key === 'Delete') {
|
|
267
|
+
if (!_selected) return;
|
|
268
|
+
deleteSelected();
|
|
269
|
+
} else {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Shape modes: an outside change to `geometry` (an edit form loading its
|
|
276
|
+
// record after mount, a consumer reset) redraws; our own emits echo back
|
|
277
|
+
// unchanged and are skipped.
|
|
278
|
+
$effect(() => {
|
|
279
|
+
const g = geometry;
|
|
280
|
+
const map = _map;
|
|
281
|
+
if (!shaped || !map) return;
|
|
282
|
+
if (JSON.stringify(g ?? null) === _lastGeometryJson) return;
|
|
283
|
+
untrack(() => renderShapes(g));
|
|
284
|
+
});
|
|
285
|
+
|
|
108
286
|
// Bidirectional coords for GeoSearch: search → map, map click → reverse geocode
|
|
109
287
|
let searchCoords = $state(/** @type {[number, number] | undefined} */ (undefined));
|
|
110
288
|
let initialReverseDone = false;
|
|
@@ -149,7 +327,7 @@
|
|
|
149
327
|
$effect(() => {
|
|
150
328
|
const c = center;
|
|
151
329
|
const map = _map;
|
|
152
|
-
if (!map || value) return;
|
|
330
|
+
if (!map || value || shapeCount > 0) return;
|
|
153
331
|
if (!Array.isArray(c) || c.length !== 2) return;
|
|
154
332
|
if (c[0] === 0 && c[1] === 0) return;
|
|
155
333
|
const view = map.getView();
|
|
@@ -230,6 +408,10 @@
|
|
|
230
408
|
{ default: Feature },
|
|
231
409
|
{ default: Point },
|
|
232
410
|
{ default: Draw },
|
|
411
|
+
{ default: Modify },
|
|
412
|
+
{ default: LineString },
|
|
413
|
+
{ default: Polygon },
|
|
414
|
+
{ noModifierKeys },
|
|
233
415
|
] = await Promise.all([
|
|
234
416
|
import('ol/Map.js'),
|
|
235
417
|
import('ol/View.js'),
|
|
@@ -238,6 +420,10 @@
|
|
|
238
420
|
import('ol/Feature.js'),
|
|
239
421
|
import('ol/geom/Point.js'),
|
|
240
422
|
import('ol/interaction/Draw.js'),
|
|
423
|
+
import('ol/interaction/Modify.js'),
|
|
424
|
+
import('ol/geom/LineString.js'),
|
|
425
|
+
import('ol/geom/Polygon.js'),
|
|
426
|
+
import('ol/events/condition.js'),
|
|
241
427
|
]);
|
|
242
428
|
|
|
243
429
|
if (disposed) return;
|
|
@@ -265,6 +451,7 @@
|
|
|
265
451
|
const vectorLayer = new VectorLayer({
|
|
266
452
|
source: vectorSource,
|
|
267
453
|
style: (feature) => {
|
|
454
|
+
if (feature === _selected) return styles.selection;
|
|
268
455
|
const type = feature.getGeometry()?.getType();
|
|
269
456
|
return type === 'Point' ? styles.marker : styles.polygon;
|
|
270
457
|
},
|
|
@@ -276,34 +463,78 @@
|
|
|
276
463
|
styles.marker,
|
|
277
464
|
];
|
|
278
465
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
466
|
+
/** @type {any} */
|
|
467
|
+
let drawInteraction;
|
|
468
|
+
/** @type {any} */
|
|
469
|
+
let modifyInteraction;
|
|
470
|
+
/** @type {((evt: any) => any) | undefined} */
|
|
471
|
+
let hitShape;
|
|
472
|
+
|
|
473
|
+
if (!shaped) {
|
|
474
|
+
drawInteraction = new Draw({
|
|
475
|
+
source: vectorSource,
|
|
476
|
+
type: 'Point',
|
|
477
|
+
style: drawStyle,
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
drawInteraction.on('drawstart', () => {
|
|
481
|
+
vectorSource.clear();
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
drawInteraction.on('drawend', (evt) => {
|
|
485
|
+
const geom = evt.feature.getGeometry();
|
|
486
|
+
if (!geom) return;
|
|
295
487
|
const coords = /** @type {import('ol/geom/Point.js').default} */ (geom).getCoordinates();
|
|
296
488
|
const wgs84 = /** @type {[number, number]} */ (toLonLat(coords));
|
|
297
489
|
value = wgs84;
|
|
298
490
|
handleMapPointPlaced(wgs84[0], wgs84[1]);
|
|
299
491
|
checkBoundary(wgs84);
|
|
300
492
|
onchange?.(wgs84);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
493
|
+
});
|
|
494
|
+
} else {
|
|
495
|
+
// ── Shape modes (atelier#2838) ──
|
|
496
|
+
_ShapeGeom = { Point, LineString, Polygon }[spec.drawType];
|
|
497
|
+
renderShapes(untrack(() => geometry));
|
|
498
|
+
|
|
499
|
+
hitShape = (evt) =>
|
|
500
|
+
map?.forEachFeatureAtPixel(evt.pixel, (f) => f, {
|
|
501
|
+
layerFilter: (l) => l === vectorLayer,
|
|
502
|
+
hitTolerance: cssPx(container, '--space-xs', 4),
|
|
503
|
+
}) ?? null;
|
|
504
|
+
|
|
505
|
+
// A click on an existing shape selects it instead of starting a new
|
|
506
|
+
// sketch; mid-sketch every click is a vertex.
|
|
507
|
+
drawInteraction = new Draw({
|
|
508
|
+
source: vectorSource,
|
|
509
|
+
type: spec.drawType,
|
|
510
|
+
style: drawStyle,
|
|
511
|
+
condition: (evt) => noModifierKeys(evt) && (_sketching || !hitShape?.(evt)),
|
|
512
|
+
});
|
|
513
|
+
_draw = drawInteraction;
|
|
514
|
+
|
|
515
|
+
drawInteraction.on('drawstart', () => {
|
|
516
|
+
_sketching = spec.drawType !== 'Point';
|
|
517
|
+
setSelected(null);
|
|
518
|
+
});
|
|
519
|
+
drawInteraction.on('drawabort', () => {
|
|
520
|
+
_sketching = false;
|
|
521
|
+
});
|
|
522
|
+
drawInteraction.on('drawend', (evt) => {
|
|
523
|
+
_sketching = false;
|
|
524
|
+
_justDrew = true;
|
|
525
|
+
if (!spec.multi) {
|
|
526
|
+
// Replace on COMPLETION (not on drawstart) so an aborted sketch
|
|
527
|
+
// leaves the current shape in place.
|
|
528
|
+
for (const old of _drawn) vectorSource.removeFeature(old);
|
|
529
|
+
_drawn = [];
|
|
530
|
+
}
|
|
531
|
+
_drawn = [..._drawn, evt.feature];
|
|
532
|
+
emitShapes();
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
modifyInteraction = new Modify({ source: vectorSource, style: styles.marker });
|
|
536
|
+
modifyInteraction.on('modifyend', () => emitShapes());
|
|
537
|
+
}
|
|
307
538
|
|
|
308
539
|
const initialCenter = value && mode === 'point' ? fromLonLat(value) : fromLonLat(center);
|
|
309
540
|
|
|
@@ -316,7 +547,32 @@
|
|
|
316
547
|
}),
|
|
317
548
|
});
|
|
318
549
|
|
|
550
|
+
// Modify before Draw (OL's draw-and-modify order): a drag on a vertex
|
|
551
|
+
// edits it, a click elsewhere draws.
|
|
552
|
+
if (modifyInteraction) map.addInteraction(modifyInteraction);
|
|
319
553
|
map.addInteraction(drawInteraction);
|
|
554
|
+
|
|
555
|
+
if (shaped) {
|
|
556
|
+
map.on('click', (evt) => {
|
|
557
|
+
if (_justDrew) {
|
|
558
|
+
_justDrew = false;
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
if (_sketching) return;
|
|
562
|
+
setSelected(hitShape?.(evt) ?? null);
|
|
563
|
+
});
|
|
564
|
+
if (_drawn.length) {
|
|
565
|
+
try {
|
|
566
|
+
const pad = cssPx(container, '--space-xl', 32);
|
|
567
|
+
map.getView().fit(vectorSource.getExtent(), {
|
|
568
|
+
padding: [pad, pad, pad, pad],
|
|
569
|
+
maxZoom: Math.max(zoom, 17),
|
|
570
|
+
});
|
|
571
|
+
} catch {
|
|
572
|
+
/* no viewport size yet — keep the declared centre */
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
320
576
|
_map = map;
|
|
321
577
|
|
|
322
578
|
disposeTheme = watchTheme(() => {
|
|
@@ -330,6 +586,8 @@
|
|
|
330
586
|
disposed = true;
|
|
331
587
|
disposeTheme?.();
|
|
332
588
|
map?.setTarget(undefined);
|
|
589
|
+
_draw = undefined;
|
|
590
|
+
_sketching = false;
|
|
333
591
|
};
|
|
334
592
|
});
|
|
335
593
|
</script>
|
|
@@ -351,22 +609,40 @@
|
|
|
351
609
|
/>
|
|
352
610
|
{/if}
|
|
353
611
|
|
|
612
|
+
{#if shaped && !disabled}
|
|
613
|
+
<div class="map-picker-toolbar" role="group" aria-label={toolbarLabel}>
|
|
614
|
+
{#if spec.multi}
|
|
615
|
+
<span class="map-picker-count" aria-live="polite">{countLabel(shapeCount, spec.drawType)}</span>
|
|
616
|
+
<Button variant="secondary" size="sm" disabled={!_selected} onclick={deleteSelected}>
|
|
617
|
+
{deleteSelectedLabel}
|
|
618
|
+
</Button>
|
|
619
|
+
{/if}
|
|
620
|
+
<Button variant="ghost" size="sm" disabled={shapeCount === 0} onclick={clearShapes}>
|
|
621
|
+
{clearLabel}
|
|
622
|
+
</Button>
|
|
623
|
+
</div>
|
|
624
|
+
{/if}
|
|
625
|
+
|
|
626
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex — role="application"
|
|
627
|
+
is interactive; shape modes take their keyboard on the focused map. -->
|
|
354
628
|
<div
|
|
355
629
|
bind:this={container}
|
|
356
630
|
id={pickerId}
|
|
357
631
|
class="map-picker-canvas"
|
|
358
|
-
class:map-picker-error={!!
|
|
632
|
+
class:map-picker-error={!!fieldError}
|
|
359
633
|
class:map-picker-disabled={disabled}
|
|
360
634
|
style:height
|
|
361
635
|
role="application"
|
|
636
|
+
tabindex={shaped && !disabled ? 0 : undefined}
|
|
637
|
+
onkeydown={handleShapeKeydown}
|
|
362
638
|
aria-label={label ?? 'Map picker'}
|
|
363
639
|
aria-describedby={hasHint ? hintId : undefined}
|
|
364
640
|
></div>
|
|
365
641
|
|
|
366
|
-
{#if
|
|
367
|
-
<span id={hintId} class="map-picker-error-text" role="alert">{
|
|
368
|
-
{:else if
|
|
369
|
-
<span id={hintId} class="map-picker-help">{
|
|
642
|
+
{#if fieldError}
|
|
643
|
+
<span id={hintId} class="map-picker-error-text" role="alert">{fieldError}</span>
|
|
644
|
+
{:else if helpText}
|
|
645
|
+
<span id={hintId} class="map-picker-help">{helpText}</span>
|
|
370
646
|
{/if}
|
|
371
647
|
</div>
|
|
372
648
|
|
|
@@ -393,6 +669,30 @@
|
|
|
393
669
|
cursor: crosshair;
|
|
394
670
|
}
|
|
395
671
|
|
|
672
|
+
.map-picker-canvas:focus-visible {
|
|
673
|
+
outline: var(--focus-ring-width) solid var(--focus-ring-color);
|
|
674
|
+
outline-offset: var(--focus-ring-offset);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
.map-picker-toolbar {
|
|
678
|
+
display: flex;
|
|
679
|
+
flex-wrap: wrap;
|
|
680
|
+
align-items: center;
|
|
681
|
+
gap: var(--space-xs);
|
|
682
|
+
background: var(--map-toolbar-bg);
|
|
683
|
+
border: var(--map-toolbar-border);
|
|
684
|
+
border-radius: var(--map-toolbar-radius);
|
|
685
|
+
padding: var(--map-toolbar-padding);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
.map-picker-count {
|
|
689
|
+
margin-right: auto;
|
|
690
|
+
padding-inline: var(--space-xs);
|
|
691
|
+
font-family: var(--input-help-font);
|
|
692
|
+
font-size: var(--input-help-size);
|
|
693
|
+
color: var(--input-help-color);
|
|
694
|
+
}
|
|
695
|
+
|
|
396
696
|
.map-picker-canvas :global(.ol-viewport) {
|
|
397
697
|
border-radius: inherit;
|
|
398
698
|
}
|
|
@@ -6,8 +6,21 @@ type MapPicker = {
|
|
|
6
6
|
/**
|
|
7
7
|
* MapPicker
|
|
8
8
|
*
|
|
9
|
-
* Interactive map for selecting a point or drawing
|
|
9
|
+
* Interactive map for selecting a point or drawing shapes.
|
|
10
10
|
* OpenLayers with configurable tiles and Draw interaction.
|
|
11
|
+
* Modes and the GeoJSON type each one emits (atelier#2838):
|
|
12
|
+
* point → Point (`value` / `onchange` speak [lon, lat]);
|
|
13
|
+
* multipoint → MultiPoint; linestring → LineString;
|
|
14
|
+
* multilinestring → MultiLineString; polygon → Polygon;
|
|
15
|
+
* multipolygon → MultiPolygon. Shape modes take and report a GeoJSON
|
|
16
|
+
* geometry of EXACTLY their type through `geometry` / `ongeometry` (null
|
|
17
|
+
* when every shape is removed); a `geometry` of another type is not drawn
|
|
18
|
+
* and fails loud through the field error. Shape modes add a drawing
|
|
19
|
+
* toolbar (clear; multi modes also count + delete selected), select-by-
|
|
20
|
+
* click, vertex dragging (alt+click removes a vertex), and keyboard keys
|
|
21
|
+
* on the focused map: Enter finishes a sketch, Escape cancels it (or
|
|
22
|
+
* deselects), Backspace removes the last sketched vertex, Delete removes
|
|
23
|
+
* the selected shape.
|
|
11
24
|
* Draw sketch styled with DS tokens (not OL blue default).
|
|
12
25
|
* Built-in GeoSearch (Nominatim) for address lookup + pan.
|
|
13
26
|
* Consumes --map-* tokens from components.css.
|
|
@@ -19,13 +32,17 @@ type MapPicker = {
|
|
|
19
32
|
* <MapPicker mode="point" search={false} onchange={(coords) => console.log(coords)} />
|
|
20
33
|
*
|
|
21
34
|
* @example Polygon drawing
|
|
22
|
-
* <MapPicker mode="polygon"
|
|
35
|
+
* <MapPicker mode="polygon" ongeometry={(polygon) => console.log(polygon)} />
|
|
36
|
+
*
|
|
37
|
+
* @example Several polygons → one MultiPolygon
|
|
38
|
+
* <MapPicker mode="multipolygon" bind:geometry={area} />
|
|
23
39
|
*/
|
|
24
40
|
declare const MapPicker: import("svelte").Component<{
|
|
25
41
|
mode?: string;
|
|
26
42
|
center?: any[];
|
|
27
43
|
zoom?: number;
|
|
28
44
|
value?: any;
|
|
45
|
+
geometry?: any;
|
|
29
46
|
label?: any;
|
|
30
47
|
help?: any;
|
|
31
48
|
error?: any;
|
|
@@ -38,16 +55,23 @@ declare const MapPicker: import("svelte").Component<{
|
|
|
38
55
|
boundary?: any;
|
|
39
56
|
onoutofbounds?: any;
|
|
40
57
|
onchange?: any;
|
|
58
|
+
ongeometry?: any;
|
|
59
|
+
deleteSelectedLabel?: string;
|
|
60
|
+
clearLabel?: string;
|
|
61
|
+
toolbarLabel?: string;
|
|
62
|
+
countLabel?: (count: number, drawType: "Point" | "LineString" | "Polygon") => string;
|
|
63
|
+
instructionsLabel?: any;
|
|
41
64
|
onaddress?: any;
|
|
42
65
|
height?: string;
|
|
43
66
|
id?: any;
|
|
44
67
|
class?: string;
|
|
45
|
-
} & Record<string, any>, {}, "value">;
|
|
68
|
+
} & Record<string, any>, {}, "value" | "geometry">;
|
|
46
69
|
type $$ComponentProps = {
|
|
47
70
|
mode?: string;
|
|
48
71
|
center?: any[];
|
|
49
72
|
zoom?: number;
|
|
50
73
|
value?: any;
|
|
74
|
+
geometry?: any;
|
|
51
75
|
label?: any;
|
|
52
76
|
help?: any;
|
|
53
77
|
error?: any;
|
|
@@ -60,6 +84,12 @@ type $$ComponentProps = {
|
|
|
60
84
|
boundary?: any;
|
|
61
85
|
onoutofbounds?: any;
|
|
62
86
|
onchange?: any;
|
|
87
|
+
ongeometry?: any;
|
|
88
|
+
deleteSelectedLabel?: string;
|
|
89
|
+
clearLabel?: string;
|
|
90
|
+
toolbarLabel?: string;
|
|
91
|
+
countLabel?: (count: number, drawType: "Point" | "LineString" | "Polygon") => string;
|
|
92
|
+
instructionsLabel?: any;
|
|
63
93
|
onaddress?: any;
|
|
64
94
|
height?: string;
|
|
65
95
|
id?: any;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type GeoJsonGeometry, type MapPickerMode } from "./map-geometry";
|
|
1
2
|
type Entity = Record<string, unknown>;
|
|
2
3
|
/** The render intent for a param: `widget` → `ui_schema.widget` → `type`. */
|
|
3
4
|
export declare function widgetKind(parameter: Entity): string;
|
|
@@ -27,6 +28,35 @@ export declare function geoJsonPointToLonLat(value: unknown): {
|
|
|
27
28
|
};
|
|
28
29
|
/** #39 — serialize a placed pin back onto the GeoJSON wire shape. */
|
|
29
30
|
export declare function lonLatToGeoJsonPoint(coords: [number, number]): GeoJsonPoint;
|
|
31
|
+
/** atelier#2838 — what the `geometry` widget renders, from the parameter's
|
|
32
|
+
* DECLARED geometry type (`geometry_type`, a GeoJSON type name):
|
|
33
|
+
* - absent (undefined / null / "") or "Point" → the #39 point picker over a
|
|
34
|
+
* GeoJSON Point (`coords` + `error` from `geoJsonPointToLonLat`);
|
|
35
|
+
* - a drawable type → that MapPicker shape mode over a GeoJSON value of
|
|
36
|
+
* EXACTLY that type (`geometry` + `error` from `decomposeGeometry`);
|
|
37
|
+
* - anything else (GeometryCollection, unknown names, wrong case) →
|
|
38
|
+
* `mode: null` + `unsupportedType`: the field renders a loud unsupported
|
|
39
|
+
* state and no picker — never a silent point. */
|
|
40
|
+
export type GeometryFieldPlan = {
|
|
41
|
+
mode: "point";
|
|
42
|
+
coords: [number, number] | null;
|
|
43
|
+
geometry: null;
|
|
44
|
+
error: string | null;
|
|
45
|
+
unsupportedType: null;
|
|
46
|
+
} | {
|
|
47
|
+
mode: Exclude<MapPickerMode, "point">;
|
|
48
|
+
coords: null;
|
|
49
|
+
geometry: GeoJsonGeometry | null;
|
|
50
|
+
error: string | null;
|
|
51
|
+
unsupportedType: null;
|
|
52
|
+
} | {
|
|
53
|
+
mode: null;
|
|
54
|
+
coords: null;
|
|
55
|
+
geometry: null;
|
|
56
|
+
error: null;
|
|
57
|
+
unsupportedType: string;
|
|
58
|
+
};
|
|
59
|
+
export declare function geometryFieldPlan(parameter: Entity, value: unknown): GeometryFieldPlan;
|
|
30
60
|
/** #46 — the map picker's INITIAL CENTRE, from its declared home:
|
|
31
61
|
* `ui_schema.map.initial_center` ([lon, lat]). A viewport hint is
|
|
32
62
|
* presentation, not a value — it lives in ui_schema so `default_value`
|