@conduction/nextcloud-vue 2.181.1 → 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.
Files changed (29) hide show
  1. package/dist/esm/components/CnMapWidget/CnMapWidget.vue.js +1 -1
  2. package/dist/esm/components/CnMapWidget/CnMapWidget2.vue.js +43 -11
  3. package/dist/esm/components/CnMapWidget/CnMapWidget2.vue.js.map +1 -1
  4. package/dist/esm/components/CnMapWidget/CnMapWidget3.vue.js.map +1 -1
  5. package/dist/esm/components/CnMapWidget/basemapPresets.js +81 -0
  6. package/dist/esm/components/CnMapWidget/basemapPresets.js.map +1 -0
  7. package/dist/esm/components/CnMapWidget/spatialFilter.js +136 -0
  8. package/dist/esm/components/CnMapWidget/spatialFilter.js.map +1 -0
  9. package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm.vue.js +1 -1
  10. package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm2.vue.js +37 -12
  11. package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm2.vue.js.map +1 -1
  12. package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm3.vue.js +27 -9
  13. package/dist/esm/components/CnMapWidgetForm/CnMapWidgetForm3.vue.js.map +1 -1
  14. package/dist/esm/l10n/nl.json.js +5 -1
  15. package/dist/esm/l10n/nl.json.js.map +1 -1
  16. package/dist/esm/library-style.js +1 -1
  17. package/dist/esm/nextcloud-vue.css +23 -23
  18. package/dist/esm/utils/geo.js +49 -10
  19. package/dist/esm/utils/geo.js.map +1 -1
  20. package/dist/nextcloud-vue.cjs.js +369 -43
  21. package/dist/nextcloud-vue.cjs.js.map +2 -2
  22. package/dist/nextcloud-vue.css +23 -23
  23. package/l10n/nl.json +5 -1
  24. package/package.json +1 -1
  25. package/src/components/CnMapWidget/CnMapWidget.vue +48 -11
  26. package/src/components/CnMapWidget/basemapPresets.js +78 -0
  27. package/src/components/CnMapWidget/spatialFilter.js +132 -0
  28. package/src/components/CnMapWidgetForm/CnMapWidgetForm.vue +53 -13
  29. package/src/utils/geo.js +48 -9
@@ -23945,12 +23945,12 @@ svg.leaflet-image-layer.leaflet-interactive path {
23945
23945
  line-height: 30px;
23946
23946
  }
23947
23947
 
23948
- .cn-map-widget[data-v-683678f9] {
23948
+ .cn-map-widget[data-v-1fc9cf51] {
23949
23949
  position: relative;
23950
23950
  width: 100%;
23951
23951
  min-height: 200px;
23952
23952
  }
23953
- .cn-map-widget__leaflet[data-v-683678f9] {
23953
+ .cn-map-widget__leaflet[data-v-1fc9cf51] {
23954
23954
  width: 100%;
23955
23955
  height: 100%;
23956
23956
  /* Leaflet paints its container #ddd, which reads as a white flash before the
@@ -23959,16 +23959,16 @@ svg.leaflet-image-layer.leaflet-interactive path {
23959
23959
  }
23960
23960
 
23961
23961
  /* With a caption the map keeps its own height and the caption sits under it. */
23962
- .cn-map-widget__leaflet--captioned[data-v-683678f9] {
23962
+ .cn-map-widget__leaflet--captioned[data-v-1fc9cf51] {
23963
23963
  min-height: 200px;
23964
23964
  }
23965
- .cn-map-widget__caption[data-v-683678f9] {
23965
+ .cn-map-widget__caption[data-v-1fc9cf51] {
23966
23966
  margin: 12px 0 0;
23967
23967
  font-size: 15px;
23968
23968
  line-height: 1.2;
23969
23969
  color: var(--color-main-text);
23970
23970
  }
23971
- .cn-map-widget__toggles[data-v-683678f9] {
23971
+ .cn-map-widget__toggles[data-v-1fc9cf51] {
23972
23972
  display: flex;
23973
23973
  flex-wrap: wrap;
23974
23974
  gap: 6px 16px;
@@ -23977,31 +23977,31 @@ svg.leaflet-image-layer.leaflet-interactive path {
23977
23977
  border: 0;
23978
23978
  font-size: 14px;
23979
23979
  }
23980
- .cn-map-widget__toggles-title[data-v-683678f9] {
23980
+ .cn-map-widget__toggles-title[data-v-1fc9cf51] {
23981
23981
  width: 100%;
23982
23982
  margin-bottom: 2px;
23983
23983
  padding: 0;
23984
23984
  font-weight: 600;
23985
23985
  }
23986
- .cn-map-widget__toggle[data-v-683678f9] {
23986
+ .cn-map-widget__toggle[data-v-1fc9cf51] {
23987
23987
  display: inline-flex;
23988
23988
  align-items: center;
23989
23989
  gap: 6px;
23990
23990
  }
23991
- .cn-map-widget__note[data-v-683678f9] {
23991
+ .cn-map-widget__note[data-v-1fc9cf51] {
23992
23992
  margin: 4px 0 0;
23993
23993
  font-size: 13px;
23994
23994
  color: var(--color-text-maxcontrast);
23995
23995
  }
23996
23996
 
23997
23997
  /* Why the map shows no markers: the card's own text size, on its inset. */
23998
- .cn-map-widget__note--status[data-v-683678f9] {
23998
+ .cn-map-widget__note--status[data-v-1fc9cf51] {
23999
23999
  font-size: 14px;
24000
24000
  }
24001
- .cn-map-widget__note--error[data-v-683678f9] {
24001
+ .cn-map-widget__note--error[data-v-1fc9cf51] {
24002
24002
  color: var(--color-error-text, var(--color-error));
24003
24003
  }
24004
- .cn-map-widget__fallback[data-v-683678f9] {
24004
+ .cn-map-widget__fallback[data-v-1fc9cf51] {
24005
24005
  display: flex;
24006
24006
  align-items: center;
24007
24007
  justify-content: center;
@@ -24009,11 +24009,11 @@ svg.leaflet-image-layer.leaflet-interactive path {
24009
24009
  min-height: 150px;
24010
24010
  color: var(--color-text-maxcontrast);
24011
24011
  }
24012
- .cn-map-widget__error[data-v-683678f9] {
24012
+ .cn-map-widget__error[data-v-1fc9cf51] {
24013
24013
  font-size: 14px;
24014
24014
  margin: 0;
24015
24015
  }
24016
- .cn-map-widget__legend[data-v-683678f9] {
24016
+ .cn-map-widget__legend[data-v-1fc9cf51] {
24017
24017
  position: absolute;
24018
24018
  top: 12px;
24019
24019
  right: 12px;
@@ -24026,7 +24026,7 @@ svg.leaflet-image-layer.leaflet-interactive path {
24026
24026
 
24027
24027
  /* Fullscreen overlay. A CSS-fixed box rather than the Fullscreen API, so it needs
24028
24028
  no permission prompt; the z-index clears the Nextcloud header. */
24029
- .cn-map-widget--fullscreen[data-v-683678f9] {
24029
+ .cn-map-widget--fullscreen[data-v-1fc9cf51] {
24030
24030
  position: fixed;
24031
24031
  top: 0;
24032
24032
  left: 0;
@@ -24039,7 +24039,7 @@ svg.leaflet-image-layer.leaflet-interactive path {
24039
24039
  Leaflet's default white-on-grey buttons.
24040
24040
  ::v-deep is required — Leaflet builds the control DOM via L.DomUtil.create, so
24041
24041
  those nodes never receive this SFC's scoped data-v attribute. */
24042
- .cn-map-widget[data-v-683678f9] .cn-map-widget__control {
24042
+ .cn-map-widget[data-v-1fc9cf51] .cn-map-widget__control {
24043
24043
  display: flex;
24044
24044
  align-items: center;
24045
24045
  justify-content: center;
@@ -24048,8 +24048,8 @@ svg.leaflet-image-layer.leaflet-interactive path {
24048
24048
  color: var(--color-main-text);
24049
24049
  background: var(--color-main-background);
24050
24050
  }
24051
- .cn-map-widget[data-v-683678f9] .cn-map-widget__control:hover,
24052
- .cn-map-widget[data-v-683678f9] .cn-map-widget__control:focus-visible {
24051
+ .cn-map-widget[data-v-1fc9cf51] .cn-map-widget__control:hover,
24052
+ .cn-map-widget[data-v-1fc9cf51] .cn-map-widget__control:focus-visible {
24053
24053
  background: var(--color-background-hover);
24054
24054
  }
24055
24055
 
@@ -24082,30 +24082,30 @@ svg.leaflet-image-layer.leaflet-interactive path {
24082
24082
  }
24083
24083
 
24084
24084
 
24085
- .cn-map-widget-form[data-v-ab71a77e] {
24085
+ .cn-map-widget-form[data-v-5ee2234a] {
24086
24086
  display: flex;
24087
24087
  flex-direction: column;
24088
24088
  gap: 12px;
24089
24089
  }
24090
- .cn-map-widget-form__row[data-v-ab71a77e] {
24090
+ .cn-map-widget-form__row[data-v-5ee2234a] {
24091
24091
  display: flex;
24092
24092
  gap: 8px;
24093
24093
  }
24094
- .cn-map-widget-form__row[data-v-ab71a77e] > * {
24094
+ .cn-map-widget-form__row[data-v-5ee2234a] > * {
24095
24095
  flex: 1;
24096
24096
  min-width: 0;
24097
24097
  }
24098
- .cn-map-widget-form__hint[data-v-ab71a77e] {
24098
+ .cn-map-widget-form__hint[data-v-5ee2234a] {
24099
24099
  color: var(--color-text-maxcontrast);
24100
24100
  font-size: 90%;
24101
24101
  margin: 0;
24102
24102
  }
24103
- .cn-map-widget-form__field[data-v-ab71a77e] {
24103
+ .cn-map-widget-form__field[data-v-5ee2234a] {
24104
24104
  display: flex;
24105
24105
  flex-direction: column;
24106
24106
  gap: 4px;
24107
24107
  }
24108
- .cn-map-widget-form__range[data-v-ab71a77e] {
24108
+ .cn-map-widget-form__range[data-v-5ee2234a] {
24109
24109
  width: 100%;
24110
24110
  /* Native range inputs ship a default 2px margin on ALL sides. The left/right
24111
24111
  2px pushes the width:100% track past the form and shows a phantom
package/l10n/nl.json CHANGED
@@ -3072,7 +3072,11 @@
3072
3072
  "An EAN-13 code takes twelve or thirteen digits with a valid check digit.": "Een EAN-13-code neemt twaalf of dertien cijfers met een geldig controlecijfer.",
3073
3073
  "A Code 128 code takes letters, digits and plain punctuation only.": "Een Code 128-code neemt alleen letters, cijfers en gewone leestekens.",
3074
3074
  "Started. It finishes in the background.": "Gestart. Het wordt op de achtergrond afgerond.",
3075
- "At most {max} rows.": "Hoogstens {max} rijen."
3075
+ "At most {max} rows.": "Hoogstens {max} rijen.",
3076
+ "Location field": "Locatieveld",
3077
+ "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.": "Objecten worden getekend vanuit het locatieveld: een punt, lijn of vlak. Zonder locatieveld vanuit hun locatie (@self.geo). Objecten zonder locatie worden overgeslagen.",
3078
+ "Custom base map": "Eigen achtergrondkaart",
3079
+ "Base map": "Achtergrondkaart"
3076
3080
  },
3077
3081
  "plurals": {
3078
3082
  "{count} member": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conduction/nextcloud-vue",
3
- "version": "2.181.1",
3
+ "version": "2.183.0",
4
4
  "description": "Shared Vue component library for Conduction Nextcloud apps — complements @nextcloud/vue with higher-level components, OpenRegister integration, and NL Design System support",
5
5
  "homepage": "https://github.com/ConductionNL/nextcloud-vue#readme",
6
6
  "bugs": {
@@ -18,6 +18,11 @@
18
18
  OpenRegister register/schema, reading each one's `@self.geo`
19
19
  (falling back to `latField` / `lngField` on the object itself).
20
20
  Objects with no usable location are skipped, not plotted at (0, 0).
21
+ `dataSource.spatialFilter` narrows them to a bbox, a radius around a
22
+ point, or a polygon, through OpenRegister's geo filters.
23
+ - `markers.detailLink` — a clicked object opens this address (with
24
+ `{id}`, `{register}`, `{schema}`, `{<property>}` tokens) in a new
25
+ tab; without it, a `url` the object carries is opened.
21
26
 
22
27
  `leaflet.markercluster`'s JS lazy-loads only when `clustering: true`
23
28
  (or `markers.clustering: true`), so a consumer without clustering does
@@ -110,6 +115,7 @@ import { resolveFilterTokens } from '../../utils/resolveFilterTokens.js'
110
115
  import { safeHref } from '../../utils/safeHref.js'
111
116
  import { SAFE_MARKDOWN_DOMPURIFY_CONFIG } from '../../utils/safeMarkdownDompurifyConfig.js'
112
117
  import { fromImagePoint, hasImagePosition, imageBounds, paddedImageBounds, toImagePoint } from './imageCoordinates.js'
118
+ import { featureDetailUrl, spatialFilterRequest } from './spatialFilter.js'
113
119
 
114
120
  // Leaflet's own stylesheet positions the map panes, tiles the tile
115
121
  // images, and places the zoom/attribution controls. The JS is lazy-loaded
@@ -313,14 +319,17 @@ export default {
313
319
  },
314
320
 
315
321
  /**
316
- * Marker config. `{ features?, dataSource?, latField?, lngField?, xField?, yField?,
317
- * popupField?, clustering?, iconColor?, iconUrl?, centerMarker? }`. On an image map
322
+ * Marker config. `{ features?, dataSource?, geoProperty?, latField?, lngField?, xField?, yField?,
323
+ * popupField?, clustering?, iconColor?, iconUrl?, centerMarker?, detailLink? }`. On an image map
318
324
  * (a layer of type `image`) markers read `xField` / `yField` (default `x` / `y`,
319
325
  * pixels from the picture's top left) instead of `latField` / `lngField`. `features[]` is inline;
320
326
  * `dataSource.url` is HTTP-fetched on mount; `dataSource.{register, schema}`
321
- * plots the objects of an OpenRegister register/schema via their `@self.geo`.
327
+ * plots the objects of an OpenRegister register/schema via `geoProperty` (a property
328
+ * holding a GeoJSON geometry of any type, or a point) when set, else `@self.geo`.
322
329
  * `centerMarker: true` adds an extra pin at the map's `center`, alongside any
323
- * source markers.
330
+ * source markers. `dataSource.spatialFilter` (`{ bbox }`, `{ near, radius }` or
331
+ * `{ within }`) narrows a register source to an area; `detailLink` is the address
332
+ * a clicked object opens in a new tab (see spatialFilter.js).
324
333
  *
325
334
  * @type {object|null}
326
335
  */
@@ -728,14 +737,18 @@ export default {
728
737
  },
729
738
 
730
739
  /**
731
- * The data-source filter with its tokens resolved, serialised so a new
732
- * record re-reads the markers.
740
+ * The data-source filter with its tokens resolved, and the spatial
741
+ * filter, serialised so a new record or a new area re-reads the markers.
733
742
  *
734
743
  * @return {string}
744
+ * @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
735
745
  */
736
746
  filterKey() {
737
747
  const ds = this.cfg.markers && this.cfg.markers.dataSource
738
- return ds && ds.filter ? JSON.stringify(this.sourceFilter(ds)) : ''
748
+ if (!ds || (!ds.filter && !ds.spatialFilter)) {
749
+ return ''
750
+ }
751
+ return JSON.stringify([ds.filter ? this.sourceFilter(ds) : null, ds.spatialFilter || null])
739
752
  },
740
753
 
741
754
  unplottedLabel() {
@@ -1278,6 +1291,7 @@ export default {
1278
1291
  * @type {{feature: object, latlng: object}}
1279
1292
  */
1280
1293
  this.$emit('marker-click', { feature, latlng: e.latlng })
1294
+ this.openFeatureDetail(feature)
1281
1295
  })
1282
1296
  },
1283
1297
  })
@@ -1775,8 +1789,11 @@ export default {
1775
1789
  * skipped rather than dropped at (0, 0) — an invisible wrong marker is worse
1776
1790
  * than an absent one.
1777
1791
  *
1778
- * @param {{register: string, schema: string, limit?: number}} ds The data source.
1792
+ * A `spatialFilter` narrows the objects to an area (see spatialFilter.js).
1793
+ *
1794
+ * @param {{register: string, schema: string, limit?: number, spatialFilter?: object}} ds The data source.
1779
1795
  * @return {Promise<Array<object>>} GeoJSON Feature array.
1796
+ * @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
1780
1797
  */
1781
1798
  async fetchRegisterFeatures(ds) {
1782
1799
  try {
@@ -1788,16 +1805,22 @@ export default {
1788
1805
  '/apps/openregister/api/objects/{register}/{schema}',
1789
1806
  { register: ds.register, schema: ds.schema },
1790
1807
  )
1791
- const res = await axios.get(url, { params: { ...this.sourceFilter(ds), _limit: ds.limit || 500 } })
1808
+ const params = { ...this.sourceFilter(ds), _limit: ds.limit || 500 }
1809
+ const spatial = spatialFilterRequest(ds.spatialFilter, this.cfg.markers && this.cfg.markers.geoProperty)
1810
+ const res = spatial && spatial.body
1811
+ ? await axios.post(url + '/geo-search', spatial.body, { params })
1812
+ : await axios.get(url, { params: { ...params, ...(spatial ? spatial.params : {}) } })
1792
1813
  const rows = (res && res.data && res.data.results) || []
1793
1814
 
1794
1815
  const latField = this.cfg.markers && this.cfg.markers.latField
1795
1816
  const lngField = this.cfg.markers && this.cfg.markers.lngField
1817
+ const geoProperty = this.cfg.markers && this.cfg.markers.geoProperty
1796
1818
 
1797
1819
  // (0, 0) is where an unset pair of numbers lands, not a place.
1798
1820
  return rows
1799
- .map((row) => objectToGeoFeature(row, { latField, lngField }))
1800
- .filter((feature) => feature && !(feature.geometry.coordinates[0] === 0 && feature.geometry.coordinates[1] === 0))
1821
+ .map((row) => objectToGeoFeature(row, { geoProperty, latField, lngField }))
1822
+ .filter((feature) => feature && !(feature.geometry.type === 'Point'
1823
+ && feature.geometry.coordinates[0] === 0 && feature.geometry.coordinates[1] === 0))
1801
1824
  } catch (err) {
1802
1825
  this.markersFailed = true
1803
1826
  // eslint-disable-next-line no-console
@@ -1806,6 +1829,20 @@ export default {
1806
1829
  }
1807
1830
  },
1808
1831
 
1832
+ /**
1833
+ * Open a clicked object's detail address in a new tab, when it has one.
1834
+ *
1835
+ * @param {object} feature The clicked GeoJSON feature.
1836
+ * @return {void}
1837
+ * @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
1838
+ */
1839
+ openFeatureDetail(feature) {
1840
+ const href = featureDetailUrl(feature, this.cfg.markers && this.cfg.markers.detailLink)
1841
+ if (href !== null) {
1842
+ window.open(href, '_blank', 'noopener,noreferrer')
1843
+ }
1844
+ },
1845
+
1809
1846
  /**
1810
1847
  * Normalise a fetched payload into a GeoJSON Feature array.
1811
1848
  * Accepts FeatureCollection, raw Feature[], or flat rows that
@@ -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
+ }
@@ -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
+ }
@@ -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 one are skipped.') }}
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: the form does not expose a basemap picker, and dropping
180
- // it on save would turn the user's map into a grey box.
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