@conduction/nextcloud-vue 2.181.1 → 2.182.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 +7 -4
- 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/basemapPresets.js +81 -0
- package/dist/esm/components/CnMapWidget/basemapPresets.js.map +1 -0
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm.vue.js +1 -1
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm2.vue.js +37 -12
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm2.vue.js.map +1 -1
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm3.vue.js +27 -9
- package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm3.vue.js.map +1 -1
- package/dist/esm/l10n/nl.json.js +5 -1
- package/dist/esm/l10n/nl.json.js.map +1 -1
- package/dist/esm/library-style.js +1 -1
- package/dist/esm/nextcloud-vue.css +23 -23
- package/dist/esm/utils/geo.js +49 -10
- package/dist/esm/utils/geo.js.map +1 -1
- package/dist/nextcloud-vue.cjs.js +203 -36
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/dist/nextcloud-vue.css +23 -23
- package/l10n/nl.json +5 -1
- package/package.json +1 -1
- package/src/components/CnMapWidget/CnMapWidget.vue +7 -4
- package/src/components/CnMapWidget/basemapPresets.js +78 -0
- package/src/components/CnMapWidgetForm/CnMapWidgetForm.vue +53 -13
- package/src/utils/geo.js +48 -9
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*
|
|
5
|
+
* The base maps the map widget form offers. Each entry has the same shape as a
|
|
6
|
+
* `basemaps[]` item of CnMapWidget (`name`, `url`, `attribution`, `options`), so
|
|
7
|
+
* a chosen preset is stored as an ordinary base map and renders on any version.
|
|
8
|
+
*
|
|
9
|
+
* The PDOK tiles are the Dutch government's open base maps, served in
|
|
10
|
+
* EPSG:3857 so Leaflet's default projection draws them. A consuming app must
|
|
11
|
+
* allow `service.pdok.nl` in its Content-Security-Policy `img-src`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const PDOK_ATTRIBUTION = 'Kaartgegevens © <a href="https://www.kadaster.nl">Kadaster</a>'
|
|
15
|
+
|
|
16
|
+
export const BASEMAP_PRESETS = Object.freeze([
|
|
17
|
+
Object.freeze({
|
|
18
|
+
id: 'osm',
|
|
19
|
+
name: 'OpenStreetMap',
|
|
20
|
+
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
21
|
+
attribution: '© OpenStreetMap contributors',
|
|
22
|
+
options: Object.freeze({ maxZoom: 19 }),
|
|
23
|
+
}),
|
|
24
|
+
Object.freeze({
|
|
25
|
+
id: 'pdok-brt',
|
|
26
|
+
name: 'PDOK BRT achtergrondkaart',
|
|
27
|
+
url: 'https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/standaard/EPSG:3857/{z}/{x}/{y}.png',
|
|
28
|
+
attribution: PDOK_ATTRIBUTION,
|
|
29
|
+
options: Object.freeze({ maxZoom: 19 }),
|
|
30
|
+
}),
|
|
31
|
+
Object.freeze({
|
|
32
|
+
id: 'pdok-brt-grijs',
|
|
33
|
+
name: 'PDOK BRT achtergrondkaart grijs',
|
|
34
|
+
url: 'https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/grijs/EPSG:3857/{z}/{x}/{y}.png',
|
|
35
|
+
attribution: PDOK_ATTRIBUTION,
|
|
36
|
+
options: Object.freeze({ maxZoom: 19 }),
|
|
37
|
+
}),
|
|
38
|
+
Object.freeze({
|
|
39
|
+
id: 'pdok-brt-pastel',
|
|
40
|
+
name: 'PDOK BRT achtergrondkaart pastel',
|
|
41
|
+
url: 'https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/pastel/EPSG:3857/{z}/{x}/{y}.png',
|
|
42
|
+
attribution: PDOK_ATTRIBUTION,
|
|
43
|
+
options: Object.freeze({ maxZoom: 19 }),
|
|
44
|
+
}),
|
|
45
|
+
Object.freeze({
|
|
46
|
+
id: 'pdok-luchtfoto',
|
|
47
|
+
name: 'PDOK luchtfoto',
|
|
48
|
+
url: 'https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_orthoHR/EPSG:3857/{z}/{x}/{y}.jpeg',
|
|
49
|
+
attribution: PDOK_ATTRIBUTION,
|
|
50
|
+
options: Object.freeze({ maxZoom: 19 }),
|
|
51
|
+
}),
|
|
52
|
+
])
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The stored base map for a preset id, as a plain `basemaps[]` item.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} id The preset id.
|
|
58
|
+
* @return {{name: string, url: string, attribution: string, options: object}|null} The base map, or null.
|
|
59
|
+
*/
|
|
60
|
+
export function basemapFromPreset(id) {
|
|
61
|
+
const preset = BASEMAP_PRESETS.find((entry) => entry.id === id)
|
|
62
|
+
if (!preset) {
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
return { name: preset.name, url: preset.url, attribution: preset.attribution, options: { ...preset.options } }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The preset a stored base map came from, matched on its tile URL.
|
|
70
|
+
*
|
|
71
|
+
* @param {object|undefined} basemap A `basemaps[]` item.
|
|
72
|
+
* @return {string|null} The preset id, or null for a custom base map.
|
|
73
|
+
*/
|
|
74
|
+
export function presetOf(basemap) {
|
|
75
|
+
const url = basemap && basemap.url
|
|
76
|
+
const preset = BASEMAP_PRESETS.find((entry) => entry.url === url)
|
|
77
|
+
return preset ? preset.id : null
|
|
78
|
+
}
|
|
@@ -23,10 +23,25 @@
|
|
|
23
23
|
:label="t('nextcloud-vue', 'Popup field')"
|
|
24
24
|
@input="popupField = $event" />
|
|
25
25
|
|
|
26
|
+
<CnFieldPicker
|
|
27
|
+
v-if="source.register && source.schema"
|
|
28
|
+
:value="geoProperty"
|
|
29
|
+
:register="source.register"
|
|
30
|
+
:schema="source.schema"
|
|
31
|
+
:label="t('nextcloud-vue', 'Location field')"
|
|
32
|
+
@input="geoProperty = $event" />
|
|
33
|
+
|
|
26
34
|
<p v-if="source.register && source.schema" class="cn-map-widget-form__hint">
|
|
27
|
-
{{ t('nextcloud-vue', 'Objects are plotted from their location (@self.geo). Objects without
|
|
35
|
+
{{ t('nextcloud-vue', 'Objects are plotted from the location field: a point, line or area. Without one, from their location (@self.geo). Objects without a location are skipped.') }}
|
|
28
36
|
</p>
|
|
29
37
|
|
|
38
|
+
<NcSelect
|
|
39
|
+
:modelValue="basemapOption"
|
|
40
|
+
:options="basemapOptions"
|
|
41
|
+
:inputLabel="t('nextcloud-vue', 'Base map')"
|
|
42
|
+
:clearable="false"
|
|
43
|
+
@update:modelValue="onBasemap($event)" />
|
|
44
|
+
|
|
30
45
|
<label class="cn-map-widget-form__field">
|
|
31
46
|
<span class="cn-map-widget-form__label">
|
|
32
47
|
{{ t('nextcloud-vue', 'Zoom') }} ({{ zoom }})
|
|
@@ -80,9 +95,10 @@
|
|
|
80
95
|
|
|
81
96
|
<script>
|
|
82
97
|
import { translate as t } from '@nextcloud/l10n'
|
|
83
|
-
import { NcCheckboxRadioSwitch, NcTextField } from '@nextcloud/vue'
|
|
98
|
+
import { NcCheckboxRadioSwitch, NcSelect, NcTextField } from '@nextcloud/vue'
|
|
84
99
|
import CnFieldPicker from '../CnFieldPicker/CnFieldPicker.vue'
|
|
85
100
|
import CnRegisterSchemaSelect from '../CnRegisterSchemaSelect/CnRegisterSchemaSelect.vue'
|
|
101
|
+
import { BASEMAP_PRESETS, basemapFromPreset, presetOf } from '../CnMapWidget/basemapPresets.js'
|
|
86
102
|
|
|
87
103
|
// The Netherlands, roughly — a sane default centre for a Dutch-government library.
|
|
88
104
|
// autoFit is on by default, so this only shows before any object is plotted.
|
|
@@ -90,14 +106,7 @@ const DEFAULT_CENTRE = [52.13, 5.29]
|
|
|
90
106
|
|
|
91
107
|
// Without a basemap the widget renders a grey box: CnMapWidget's `basemaps` prop is
|
|
92
108
|
// opt-in and empty by default. The Nextcloud CSP already allows *.tile.openstreetmap.org.
|
|
93
|
-
const DEFAULT_BASEMAPS = [
|
|
94
|
-
{
|
|
95
|
-
name: 'OpenStreetMap',
|
|
96
|
-
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
97
|
-
attribution: '© OpenStreetMap contributors',
|
|
98
|
-
options: { maxZoom: 19 },
|
|
99
|
-
},
|
|
100
|
-
]
|
|
109
|
+
const DEFAULT_BASEMAPS = [basemapFromPreset('osm')]
|
|
101
110
|
|
|
102
111
|
const DEFAULT_CONTENT = {
|
|
103
112
|
register: '',
|
|
@@ -123,7 +132,7 @@ const DEFAULT_CONTENT = {
|
|
|
123
132
|
export default {
|
|
124
133
|
name: 'CnMapWidgetForm',
|
|
125
134
|
|
|
126
|
-
components: { NcTextField, NcCheckboxRadioSwitch, CnRegisterSchemaSelect, CnFieldPicker },
|
|
135
|
+
components: { NcTextField, NcCheckboxRadioSwitch, NcSelect, CnRegisterSchemaSelect, CnFieldPicker },
|
|
127
136
|
|
|
128
137
|
props: {
|
|
129
138
|
/**
|
|
@@ -173,11 +182,12 @@ export default {
|
|
|
173
182
|
zoom: Number.isFinite(initial.zoom) ? initial.zoom : 7,
|
|
174
183
|
height: initial.height || '400px',
|
|
175
184
|
popupField: initial.popupField ?? '',
|
|
185
|
+
geoProperty: initial.markers?.geoProperty ?? '',
|
|
176
186
|
clustering: initial.clustering === true,
|
|
177
187
|
autoFit: initial.autoFit !== false,
|
|
178
188
|
centerMarker: initial.markers?.centerMarker === true,
|
|
179
|
-
// Preserved verbatim
|
|
180
|
-
//
|
|
189
|
+
// Preserved verbatim unless a preset is chosen: dropping it on save would
|
|
190
|
+
// turn the user's map into a grey box, and a custom base map has no preset.
|
|
181
191
|
basemaps: Array.isArray(initial.basemaps) && initial.basemaps.length
|
|
182
192
|
? initial.basemaps
|
|
183
193
|
: DEFAULT_BASEMAPS,
|
|
@@ -185,6 +195,21 @@ export default {
|
|
|
185
195
|
},
|
|
186
196
|
|
|
187
197
|
computed: {
|
|
198
|
+
/** The base map choices: the presets, plus the stored one when it is custom. */
|
|
199
|
+
basemapOptions() {
|
|
200
|
+
const presets = BASEMAP_PRESETS.map((preset) => ({ id: preset.id, label: preset.name }))
|
|
201
|
+
if (presetOf(this.basemaps[0]) === null) {
|
|
202
|
+
return [{ id: 'custom', label: this.basemaps[0]?.name || t('nextcloud-vue', 'Custom base map') }, ...presets]
|
|
203
|
+
}
|
|
204
|
+
return presets
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
/** The option of the first stored base map. */
|
|
208
|
+
basemapOption() {
|
|
209
|
+
const id = presetOf(this.basemaps[0]) ?? 'custom'
|
|
210
|
+
return this.basemapOptions.find((option) => option.id === id) ?? null
|
|
211
|
+
},
|
|
212
|
+
|
|
188
213
|
/** The assembled content blob from the current field values. */
|
|
189
214
|
assembledContent() {
|
|
190
215
|
return {
|
|
@@ -202,6 +227,7 @@ export default {
|
|
|
202
227
|
markers: {
|
|
203
228
|
dataSource: { register: this.source.register, schema: this.source.schema },
|
|
204
229
|
popupField: this.popupField,
|
|
230
|
+
...(this.geoProperty ? { geoProperty: this.geoProperty } : {}),
|
|
205
231
|
clustering: this.clustering,
|
|
206
232
|
centerMarker: this.centerMarker,
|
|
207
233
|
},
|
|
@@ -235,6 +261,20 @@ export default {
|
|
|
235
261
|
if (key === 'register') {
|
|
236
262
|
this.source.schema = ''
|
|
237
263
|
this.popupField = ''
|
|
264
|
+
this.geoProperty = ''
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Store the chosen preset as the base map. Choosing the custom entry keeps
|
|
270
|
+
* the stored base maps as they are.
|
|
271
|
+
*
|
|
272
|
+
* @param {{id: string}|null} option The chosen option.
|
|
273
|
+
*/
|
|
274
|
+
onBasemap(option) {
|
|
275
|
+
const basemap = option && basemapFromPreset(option.id)
|
|
276
|
+
if (basemap) {
|
|
277
|
+
this.basemaps = [basemap]
|
|
238
278
|
}
|
|
239
279
|
},
|
|
240
280
|
|
package/src/utils/geo.js
CHANGED
|
@@ -93,16 +93,44 @@ export function parseGeoPoint(geo) {
|
|
|
93
93
|
)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
const GEOMETRY_TYPES = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon']
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The GeoJSON geometry a property value holds: a geometry, or a Feature's
|
|
100
|
+
* geometry. Returns null for anything else, so a point-shaped value falls
|
|
101
|
+
* through to parseGeoPoint().
|
|
102
|
+
*
|
|
103
|
+
* @param {unknown} value The property value.
|
|
104
|
+
* @return {?object} The geometry, or null.
|
|
105
|
+
*/
|
|
106
|
+
export function parseGeoGeometry(value) {
|
|
107
|
+
if (!value || typeof value !== 'object') {
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
110
|
+
const geometry = value.type === 'Feature' ? value.geometry : value
|
|
111
|
+
if (!geometry || !GEOMETRY_TYPES.includes(geometry.type) || !Array.isArray(geometry.coordinates)) {
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
if (geometry.type === 'Point') {
|
|
115
|
+
const point = parseGeoPoint(geometry)
|
|
116
|
+
return point ? { type: 'Point', coordinates: [point.lng, point.lat] } : null
|
|
117
|
+
}
|
|
118
|
+
return geometry.coordinates.length > 0 ? geometry : null
|
|
119
|
+
}
|
|
120
|
+
|
|
96
121
|
/**
|
|
97
|
-
* Turn an OpenRegister object into a GeoJSON
|
|
122
|
+
* Turn an OpenRegister object into a GeoJSON Feature, or null when it has no
|
|
98
123
|
* usable location.
|
|
99
124
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
125
|
+
* With `geoProperty` set, that property is read first: a GeoJSON geometry of any
|
|
126
|
+
* type (point, line, polygon or a multi-geometry), a Feature, or a lat/lng value.
|
|
127
|
+
* Otherwise, or when it is empty, `@self.geo` is read (where the geo widget writes
|
|
128
|
+
* it), and then plain lat/lng fields on the object itself, so a schema that models
|
|
129
|
+
* coordinates as its own properties still plots.
|
|
103
130
|
*
|
|
104
131
|
* @param {object} obj The OpenRegister object.
|
|
105
132
|
* @param {object} [options] Options.
|
|
133
|
+
* @param {string} [options.geoProperty] Property holding the object's geometry.
|
|
106
134
|
* @param {string} [options.latField] Property holding latitude, for the fallback.
|
|
107
135
|
* @param {string} [options.lngField] Property holding longitude, for the fallback.
|
|
108
136
|
* @return {?object} A GeoJSON Feature whose `properties` is the object, or null.
|
|
@@ -112,14 +140,25 @@ export function objectToGeoFeature(obj, options = {}) {
|
|
|
112
140
|
return null
|
|
113
141
|
}
|
|
114
142
|
|
|
143
|
+
const { geoProperty, latField, lngField } = options
|
|
144
|
+
if (geoProperty) {
|
|
145
|
+
const value = obj[geoProperty]
|
|
146
|
+
const geometry = parseGeoGeometry(value)
|
|
147
|
+
const point = geometry ? null : parseGeoPoint(value)
|
|
148
|
+
if (geometry || point) {
|
|
149
|
+
return {
|
|
150
|
+
type: 'Feature',
|
|
151
|
+
geometry: geometry || { type: 'Point', coordinates: [point.lng, point.lat] },
|
|
152
|
+
properties: { ...obj },
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
115
157
|
const self = obj['@self'] || {}
|
|
116
158
|
let point = parseGeoPoint(self.geo)
|
|
117
159
|
|
|
118
|
-
if (!point) {
|
|
119
|
-
|
|
120
|
-
if (latField && lngField) {
|
|
121
|
-
point = finitePoint(obj[latField], obj[lngField])
|
|
122
|
-
}
|
|
160
|
+
if (!point && latField && lngField) {
|
|
161
|
+
point = finitePoint(obj[latField], obj[lngField])
|
|
123
162
|
}
|
|
124
163
|
if (!point) {
|
|
125
164
|
return null
|