@conduction/nextcloud-vue 2.182.0 → 2.183.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/esm/components/CnMapWidget/CnMapWidget.vue.js +1 -1
- package/dist/esm/components/CnMapWidget/CnMapWidget2.vue.js +36 -7
- package/dist/esm/components/CnMapWidget/CnMapWidget2.vue.js.map +1 -1
- package/dist/esm/components/CnMapWidget/CnMapWidget3.vue.js.map +1 -1
- package/dist/esm/components/CnMapWidget/spatialFilter.js +136 -0
- package/dist/esm/components/CnMapWidget/spatialFilter.js.map +1 -0
- package/dist/esm/library-style.js +1 -1
- package/dist/esm/nextcloud-vue.css +17 -17
- package/dist/nextcloud-vue.cjs.js +167 -8
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/dist/nextcloud-vue.css +17 -17
- package/package.json +1 -1
- package/src/components/CnMapWidget/CnMapWidget.vue +41 -7
- package/src/components/CnMapWidget/spatialFilter.js +132 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*
|
|
5
|
+
* Spatial filters and detail links for a map that plots OpenRegister objects.
|
|
6
|
+
*
|
|
7
|
+
* `markers.dataSource.spatialFilter` narrows the objects to an area, through
|
|
8
|
+
* OpenRegister's geo filters:
|
|
9
|
+
* - `{ bbox: [west, south, east, north] }` → `GET ?geo.bbox=w,s,e,n`
|
|
10
|
+
* - `{ near: [lon, lat], radius: meters }` → `GET ?geo.near=lon,lat&geo.radius=m`
|
|
11
|
+
* - `{ within: <GeoJSON Polygon|MultiPolygon> }` → `POST …/geo-search`
|
|
12
|
+
* The map's `markers.geoProperty`, when set, is sent as `geo.property` so the
|
|
13
|
+
* filter reads the same property the map draws.
|
|
14
|
+
*
|
|
15
|
+
* `markers.detailLink` is the address a clicked feature opens in a new tab: a
|
|
16
|
+
* template whose `{id}`, `{register}`, `{schema}` and `{<property>}` tokens are
|
|
17
|
+
* filled from the object. Without a template, a `url` the object carries (the
|
|
18
|
+
* address OpenRegister's deep-link registry stamps) is opened instead. An
|
|
19
|
+
* app-absolute path gets the instance's webroot.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { prefixUrl } from '../../utils/headers.js'
|
|
23
|
+
import { safeHref } from '../../utils/safeHref.js'
|
|
24
|
+
|
|
25
|
+
const POLYGON_TYPES = ['Polygon', 'MultiPolygon']
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Whether every entry is a finite number and there are `length` of them.
|
|
29
|
+
*
|
|
30
|
+
* @param {unknown} list The value.
|
|
31
|
+
* @param {number} length The expected length.
|
|
32
|
+
* @return {boolean}
|
|
33
|
+
*/
|
|
34
|
+
function isNumberTuple(list, length) {
|
|
35
|
+
return Array.isArray(list) && list.length === length && list.every((n) => Number.isFinite(Number(n)) && n !== '' && n !== null)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The OpenRegister request a spatial filter makes, or null when there is no
|
|
40
|
+
* usable filter. A malformed filter is ignored rather than sent, so a typo in
|
|
41
|
+
* a widget's config never empties the map with a 422.
|
|
42
|
+
*
|
|
43
|
+
* @param {object|null|undefined} spatialFilter The `dataSource.spatialFilter` block.
|
|
44
|
+
* @param {string} [geoProperty] The property the map draws, sent as `geo.property`.
|
|
45
|
+
* @return {{params: object}|{body: object}|null} Query params for the listing, or a geo-search body.
|
|
46
|
+
* @spec openspec/changes/map-spatial-filter-and-detail-link/specs/map-spatial-filter-and-detail-link/spec.md#requirement-a-map-can-narrow-its-objects-to-an-area
|
|
47
|
+
*/
|
|
48
|
+
export function spatialFilterRequest(spatialFilter, geoProperty) {
|
|
49
|
+
if (!spatialFilter || typeof spatialFilter !== 'object') {
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
const property = typeof geoProperty === 'string' && geoProperty !== '' ? { 'geo.property': geoProperty } : {}
|
|
53
|
+
|
|
54
|
+
const within = spatialFilter.within
|
|
55
|
+
if (within && typeof within === 'object' && POLYGON_TYPES.includes(within.type) && Array.isArray(within.coordinates)) {
|
|
56
|
+
const body = { geometry: { within } }
|
|
57
|
+
if (property['geo.property']) {
|
|
58
|
+
body.property = property['geo.property']
|
|
59
|
+
}
|
|
60
|
+
return { body }
|
|
61
|
+
}
|
|
62
|
+
if (isNumberTuple(spatialFilter.bbox, 4)) {
|
|
63
|
+
return { params: { 'geo.bbox': spatialFilter.bbox.map(Number).join(','), ...property } }
|
|
64
|
+
}
|
|
65
|
+
if (isNumberTuple(spatialFilter.near, 2) && Number(spatialFilter.radius) > 0) {
|
|
66
|
+
return {
|
|
67
|
+
params: {
|
|
68
|
+
'geo.near': spatialFilter.near.map(Number).join(','),
|
|
69
|
+
'geo.radius': String(Number(spatialFilter.radius)),
|
|
70
|
+
...property,
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The value a detail-link token reads from an object.
|
|
79
|
+
*
|
|
80
|
+
* @param {object} object The feature's properties (the OpenRegister object).
|
|
81
|
+
* @param {string} token The token name.
|
|
82
|
+
* @return {unknown}
|
|
83
|
+
*/
|
|
84
|
+
function tokenValue(object, token) {
|
|
85
|
+
const self = object['@self'] && typeof object['@self'] === 'object' ? object['@self'] : {}
|
|
86
|
+
if (token === 'id') {
|
|
87
|
+
return self.id ?? object.id ?? object.uuid
|
|
88
|
+
}
|
|
89
|
+
if (token === 'register' || token === 'schema') {
|
|
90
|
+
return self[token] ?? object[token]
|
|
91
|
+
}
|
|
92
|
+
return object[token]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The address a clicked feature opens, or null when it has none. A template
|
|
97
|
+
* with a token the object cannot fill gives null, so a click never opens a
|
|
98
|
+
* half-built address.
|
|
99
|
+
*
|
|
100
|
+
* @param {object|null} feature The clicked GeoJSON feature.
|
|
101
|
+
* @param {string} [template] The `markers.detailLink` template.
|
|
102
|
+
* @return {string|null} A safe href, or null.
|
|
103
|
+
* @spec openspec/changes/map-spatial-filter-and-detail-link/specs/map-spatial-filter-and-detail-link/spec.md#requirement-a-clicked-object-opens-its-detail-page
|
|
104
|
+
*/
|
|
105
|
+
export function featureDetailUrl(feature, template) {
|
|
106
|
+
const object = feature && feature.properties && typeof feature.properties === 'object' ? feature.properties : null
|
|
107
|
+
if (object === null) {
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
110
|
+
let href = null
|
|
111
|
+
if (typeof template === 'string' && template !== '') {
|
|
112
|
+
let missing = false
|
|
113
|
+
href = template.replace(/\{([\w@.-]+)\}/g, (_match, token) => {
|
|
114
|
+
const value = tokenValue(object, token)
|
|
115
|
+
if (value === undefined || value === null || value === '' || typeof value === 'object') {
|
|
116
|
+
missing = true
|
|
117
|
+
return ''
|
|
118
|
+
}
|
|
119
|
+
return encodeURIComponent(String(value))
|
|
120
|
+
})
|
|
121
|
+
if (missing) {
|
|
122
|
+
return null
|
|
123
|
+
}
|
|
124
|
+
} else if (typeof object.url === 'string' && object.url !== '') {
|
|
125
|
+
href = object.url
|
|
126
|
+
}
|
|
127
|
+
if (href === null) {
|
|
128
|
+
return null
|
|
129
|
+
}
|
|
130
|
+
const safe = safeHref(href)
|
|
131
|
+
return safe === '#' ? null : prefixUrl(safe)
|
|
132
|
+
}
|