geonetwork-ui 2.2.0-dev.95201f8f → 2.2.0-dev.ae0a63ae

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 (118) hide show
  1. package/esm2022/libs/api/metadata-converter/src/lib/gn4/atomic-operations.mjs +2 -1
  2. package/esm2022/libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.mjs +36 -2
  3. package/esm2022/libs/api/repository/src/lib/gn4/index.mjs +3 -1
  4. package/esm2022/libs/common/domain/src/lib/model/record/metadata.model.mjs +1 -1
  5. package/esm2022/libs/feature/dataviz/src/lib/service/data.service.mjs +5 -4
  6. package/esm2022/libs/feature/editor/src/lib/record-form/record-form.component.mjs +5 -3
  7. package/esm2022/libs/feature/map/src/index.mjs +2 -1
  8. package/esm2022/libs/feature/map/src/lib/constant/index.mjs +2 -1
  9. package/esm2022/libs/feature/map/src/lib/constant/projections.mjs +2 -0
  10. package/esm2022/libs/feature/map/src/lib/feature-map.module.mjs +17 -3
  11. package/esm2022/libs/feature/map/src/lib/geocoding/geocoding.component.mjs +93 -0
  12. package/esm2022/libs/feature/map/src/lib/geocoding.service.mjs +40 -0
  13. package/esm2022/libs/feature/map/src/lib/utils/index.mjs +1 -3
  14. package/esm2022/libs/feature/map/src/lib/utils/map-utils.service.mjs +60 -29
  15. package/esm2022/libs/feature/record/src/lib/map-view/map-view.component.mjs +29 -20
  16. package/esm2022/libs/feature/search/src/lib/state/effects.mjs +5 -3
  17. package/esm2022/libs/ui/elements/src/index.mjs +2 -1
  18. package/esm2022/libs/ui/elements/src/lib/downloads-list/downloads-list.component.mjs +3 -3
  19. package/esm2022/libs/ui/elements/src/lib/image-overlay-preview/image-overlay-preview.component.mjs +3 -3
  20. package/esm2022/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.mjs +3 -3
  21. package/esm2022/libs/ui/elements/src/lib/ui-elements.module.mjs +3 -1
  22. package/esm2022/libs/ui/inputs/src/lib/editable-label/editable-label.directive.mjs +46 -0
  23. package/esm2022/libs/ui/inputs/src/lib/ui-inputs.module.mjs +8 -3
  24. package/esm2022/libs/ui/search/src/lib/record-table/record-table.component.mjs +3 -3
  25. package/esm2022/libs/util/shared/src/lib/links/link-utils.mjs +29 -13
  26. package/esm2022/translations/de.json +1 -0
  27. package/esm2022/translations/en.json +1 -0
  28. package/esm2022/translations/es.json +1 -0
  29. package/esm2022/translations/fr.json +1 -0
  30. package/esm2022/translations/it.json +1 -0
  31. package/esm2022/translations/nl.json +1 -0
  32. package/esm2022/translations/pt.json +1 -0
  33. package/fesm2022/geonetwork-ui.mjs +341 -108
  34. package/fesm2022/geonetwork-ui.mjs.map +1 -1
  35. package/libs/api/metadata-converter/src/lib/gn4/atomic-operations.d.ts +1 -0
  36. package/libs/api/metadata-converter/src/lib/gn4/atomic-operations.d.ts.map +1 -1
  37. package/libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.d.ts.map +1 -1
  38. package/libs/api/repository/src/lib/gn4/index.d.ts +2 -0
  39. package/libs/api/repository/src/lib/gn4/index.d.ts.map +1 -1
  40. package/libs/common/domain/src/lib/model/record/metadata.model.d.ts +10 -5
  41. package/libs/common/domain/src/lib/model/record/metadata.model.d.ts.map +1 -1
  42. package/libs/feature/dataviz/src/lib/service/data.service.d.ts +15 -2
  43. package/libs/feature/dataviz/src/lib/service/data.service.d.ts.map +1 -1
  44. package/libs/feature/editor/src/lib/record-form/record-form.component.d.ts.map +1 -1
  45. package/libs/feature/map/src/index.d.ts +1 -0
  46. package/libs/feature/map/src/index.d.ts.map +1 -1
  47. package/libs/feature/map/src/lib/constant/index.d.ts +1 -0
  48. package/libs/feature/map/src/lib/constant/index.d.ts.map +1 -1
  49. package/libs/feature/map/src/lib/constant/projections.d.ts.map +1 -0
  50. package/libs/feature/map/src/lib/feature-map.module.d.ts +13 -12
  51. package/libs/feature/map/src/lib/feature-map.module.d.ts.map +1 -1
  52. package/libs/feature/map/src/lib/geocoding/geocoding.component.d.ts +25 -0
  53. package/libs/feature/map/src/lib/geocoding/geocoding.component.d.ts.map +1 -0
  54. package/libs/feature/map/src/lib/geocoding.service.d.ts +18 -0
  55. package/libs/feature/map/src/lib/geocoding.service.d.ts.map +1 -0
  56. package/libs/feature/map/src/lib/utils/index.d.ts +0 -2
  57. package/libs/feature/map/src/lib/utils/index.d.ts.map +1 -1
  58. package/libs/feature/map/src/lib/utils/map-utils.service.d.ts +13 -11
  59. package/libs/feature/map/src/lib/utils/map-utils.service.d.ts.map +1 -1
  60. package/libs/feature/record/src/lib/map-view/map-view.component.d.ts +1 -3
  61. package/libs/feature/record/src/lib/map-view/map-view.component.d.ts.map +1 -1
  62. package/libs/feature/search/src/lib/state/effects.d.ts.map +1 -1
  63. package/libs/ui/dataviz/src/lib/chart/chart.component.d.ts +1 -1
  64. package/libs/ui/elements/src/index.d.ts +1 -0
  65. package/libs/ui/elements/src/index.d.ts.map +1 -1
  66. package/libs/ui/elements/src/lib/downloads-list/downloads-list.component.d.ts +1 -1
  67. package/libs/ui/elements/src/lib/ui-elements.module.d.ts +1 -1
  68. package/libs/ui/elements/src/lib/ui-elements.module.d.ts.map +1 -1
  69. package/libs/ui/inputs/src/lib/editable-label/editable-label.directive.d.ts +13 -0
  70. package/libs/ui/inputs/src/lib/editable-label/editable-label.directive.d.ts.map +1 -0
  71. package/libs/ui/inputs/src/lib/ui-inputs.module.d.ts +2 -1
  72. package/libs/ui/inputs/src/lib/ui-inputs.module.d.ts.map +1 -1
  73. package/libs/util/shared/src/lib/links/link-utils.d.ts +19 -7
  74. package/libs/util/shared/src/lib/links/link-utils.d.ts.map +1 -1
  75. package/package.json +4 -1
  76. package/src/libs/api/metadata-converter/src/lib/gn4/atomic-operations.ts +3 -0
  77. package/src/libs/api/metadata-converter/src/lib/gn4/gn4.field.mapper.ts +43 -0
  78. package/src/libs/api/repository/src/lib/gn4/index.ts +2 -0
  79. package/src/libs/common/domain/src/lib/index.ts +2 -0
  80. package/src/libs/common/domain/src/lib/model/record/metadata.model.ts +12 -7
  81. package/src/libs/feature/dataviz/src/lib/service/data.service.ts +8 -5
  82. package/src/libs/feature/editor/src/lib/record-form/record-form.component.ts +2 -1
  83. package/src/libs/feature/map/src/index.ts +1 -0
  84. package/src/libs/feature/map/src/lib/constant/index.ts +1 -0
  85. package/src/libs/feature/map/src/lib/feature-map.module.ts +8 -0
  86. package/src/libs/feature/map/src/lib/geocoding/geocoding.component.css +0 -0
  87. package/src/libs/feature/map/src/lib/geocoding/geocoding.component.html +39 -0
  88. package/src/libs/feature/map/src/lib/geocoding/geocoding.component.ts +99 -0
  89. package/src/libs/feature/map/src/lib/geocoding.service.ts +59 -0
  90. package/src/libs/feature/map/src/lib/utils/index.ts +0 -2
  91. package/src/libs/feature/map/src/lib/utils/map-utils.service.ts +85 -50
  92. package/src/libs/feature/record/src/lib/map-view/map-view.component.ts +18 -3
  93. package/src/libs/feature/search/src/lib/state/effects.ts +4 -3
  94. package/src/libs/ui/elements/src/index.ts +1 -0
  95. package/src/libs/ui/elements/src/lib/downloads-list/downloads-list.component.html +4 -1
  96. package/src/libs/ui/elements/src/lib/image-overlay-preview/image-overlay-preview.component.html +3 -2
  97. package/src/libs/ui/elements/src/lib/metadata-contact/metadata-contact.component.html +1 -1
  98. package/src/libs/ui/elements/src/lib/ui-elements.module.ts +1 -0
  99. package/src/libs/ui/inputs/src/lib/editable-label/editable-label.directive.ts +48 -0
  100. package/src/libs/ui/inputs/src/lib/ui-inputs.module.ts +3 -0
  101. package/src/libs/ui/search/src/lib/record-table/record-table.component.html +2 -2
  102. package/src/libs/util/shared/src/lib/links/link-utils.ts +34 -11
  103. package/translations/de.json +1 -0
  104. package/translations/en.json +1 -0
  105. package/translations/es.json +1 -0
  106. package/translations/fr.json +1 -0
  107. package/translations/it.json +1 -0
  108. package/translations/nl.json +1 -0
  109. package/translations/pt.json +1 -0
  110. package/translations/sk.json +1 -0
  111. package/esm2022/libs/feature/map/src/lib/utils/map-utils-wms.service.mjs +0 -55
  112. package/esm2022/libs/feature/map/src/lib/utils/projections.mjs +0 -2
  113. package/libs/feature/map/src/lib/utils/map-utils-wms.service.d.ts +0 -17
  114. package/libs/feature/map/src/lib/utils/map-utils-wms.service.d.ts.map +0 -1
  115. package/libs/feature/map/src/lib/utils/projections.d.ts.map +0 -1
  116. package/src/libs/feature/map/src/lib/utils/map-utils-wms.service.ts +0 -58
  117. /package/libs/feature/map/src/lib/{utils → constant}/projections.d.ts +0 -0
  118. /package/src/libs/feature/map/src/lib/{utils → constant}/projections.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geonetwork-ui",
3
- "version": "2.2.0-dev.95201f8f",
3
+ "version": "2.2.0-dev.ae0a63ae",
4
4
  "engines": {
5
5
  "node": ">=14.17.0"
6
6
  },
@@ -48,12 +48,14 @@
48
48
  "dependencies": {
49
49
  "@biesbjerg/ngx-translate-extract-marker": "^1.0.0",
50
50
  "@camptocamp/ogc-client": "^0.4.0",
51
+ "@geospatial-sdk/geocoding": "^0.0.5-alpha.1",
51
52
  "@ltd/j-toml": "~1.35.2",
52
53
  "@messageformat/core": "^3.0.1",
53
54
  "@nx/angular": "16.6.0",
54
55
  "@rgrove/parse-xml": "~4.0.1",
55
56
  "alasql": "^3.1.0",
56
57
  "axios": "^1.6.0",
58
+ "basiclightbox": "^5.0.4",
57
59
  "chart.js": "^4.2.0",
58
60
  "chroma-js": "^2.1.2",
59
61
  "date-fns": "^2.29.3",
@@ -62,6 +64,7 @@
62
64
  "embla-carousel": "^8.0.0-rc14",
63
65
  "express": "^4.17.1",
64
66
  "geojson-validation": "^1.0.2",
67
+ "marked": "^11.1.1",
65
68
  "moment": "^2.29.4",
66
69
  "ng-table-virtual-scroll": "^1.4.1",
67
70
  "ngx-chips": "3.0.0",
@@ -41,6 +41,9 @@ export const toDate = (field) => new Date(field)
41
41
  export const getFirstValue = (field) =>
42
42
  Array.isArray(field) ? field[0] : field
43
43
 
44
+ export const getArrayItem = (field, index) =>
45
+ Array.isArray(field) && field[index] !== undefined ? field[index] : null
46
+
44
47
  export const getAsArray = (field) =>
45
48
  Array.isArray(field) ? field : field !== null ? [field] : []
46
49
 
@@ -1,4 +1,5 @@
1
1
  import {
2
+ getArrayItem,
2
3
  getAsArray,
3
4
  getAsUrl,
4
5
  getFirstValue,
@@ -22,6 +23,7 @@ import {
22
23
  DatasetDistributionType,
23
24
  DatasetDownloadDistribution,
24
25
  DatasetServiceDistribution,
26
+ DatasetSpatialExtent,
25
27
  OnlineLinkResource,
26
28
  } from '../../../../../../libs/common/domain/src/lib/model/record'
27
29
  import { matchProtocol } from '../common/distribution.mapper'
@@ -258,6 +260,47 @@ export class Gn4FieldMapper {
258
260
  kind,
259
261
  }
260
262
  },
263
+ geom: (output, source) => {
264
+ const geoms = getAsArray(selectField(source, 'geom'))
265
+ const shapes = getAsArray(selectField(source, 'shape'))
266
+ const extentDescriptions = getAsArray(
267
+ selectField(source, 'extentDescriptionObject')
268
+ )
269
+ const spatialExtents = getAsArray(selectField(source, 'spatialExtents'))
270
+ return {
271
+ ...output,
272
+ spatialExtents: [
273
+ ...spatialExtents,
274
+ ...geoms.map((geom, index) => {
275
+ const description = selectTranslatedValue(
276
+ getArrayItem(extentDescriptions, index),
277
+ this.lang3
278
+ )
279
+ const geometry = shapes[index] ?? geom
280
+ return {
281
+ ...(description !== null ? { description } : null),
282
+ geometry,
283
+ } as DatasetSpatialExtent
284
+ }),
285
+ ],
286
+ }
287
+ },
288
+ resourceTemporalDateRange: (output, source) => {
289
+ const ranges = getAsArray(
290
+ selectField(source, 'resourceTemporalDateRange')
291
+ )
292
+ return {
293
+ ...output,
294
+ temporalExtents: ranges.map((range) => {
295
+ const start = selectField(range, 'gte')
296
+ const end = selectField(range, 'lte')
297
+ return {
298
+ ...(start !== null ? { start: toDate(start) } : null),
299
+ ...(end !== null ? { end: toDate(end) } : null),
300
+ }
301
+ }),
302
+ }
303
+ },
261
304
  }
262
305
 
263
306
  private genericField = (output) => output
@@ -6,3 +6,5 @@ export * from './auth'
6
6
  export * from './favorites/favorites.service'
7
7
  export * from './selection/selection.service'
8
8
  export * from './gn4.provider'
9
+ export * from './platform/gn4-platform.service'
10
+ export * from './platform/gn4-platform.mapper'
@@ -0,0 +1,2 @@
1
+ export * from './organizations.service.interface'
2
+ export * from './platform.service.interface'
@@ -1,6 +1,7 @@
1
1
  import { marker } from '@biesbjerg/ngx-translate-extract-marker'
2
- import { Individual } from './contact.model'
3
- import { Organization } from './organization.model'
2
+ import type { Individual } from './contact.model'
3
+ import type { Organization } from './organization.model'
4
+ import type { Geometry } from 'geojson'
4
5
 
5
6
  type Uuid = string
6
7
 
@@ -122,6 +123,7 @@ export interface DatasetDownloadDistribution {
122
123
  // textEncoding?: string
123
124
  name?: string
124
125
  description?: string
126
+ accessServiceProtocol?: ServiceProtocol
125
127
  }
126
128
 
127
129
  export interface OnlineLinkResource {
@@ -145,13 +147,16 @@ export interface GraphicOverview {
145
147
  }
146
148
 
147
149
  export interface DatasetSpatialExtent {
148
- geometry: unknown // GeoJSON
150
+ geometry: Geometry
149
151
  description?: string
150
152
  }
151
153
 
154
+ /**
155
+ * At least a start or an end date should be provided
156
+ */
152
157
  export interface DatasetTemporalExtent {
153
- start: Date
154
- end: Date
158
+ start?: Date
159
+ end?: Date
155
160
  description?: string
156
161
  }
157
162
 
@@ -163,8 +168,8 @@ export interface DatasetRecord extends BaseRecord {
163
168
  datasetUpdated?: Date
164
169
  lineage: string // Explanation of the origin of this record (e.g: how, why)"
165
170
  distributions: Array<DatasetDistribution>
166
- spatialExtents: Array<DatasetSpatialExtent> // not handled yet
167
- temporalExtents: Array<DatasetTemporalExtent> // not handled yet
171
+ spatialExtents: Array<DatasetSpatialExtent>
172
+ temporalExtents: Array<DatasetTemporalExtent>
168
173
  spatialRepresentation?: SpatialRepresentationType
169
174
  }
170
175
 
@@ -9,8 +9,8 @@ import {
9
9
  SupportedTypes,
10
10
  } from '../../../../../../libs/util/data-fetcher/src'
11
11
  import {
12
- extensionToFormat,
13
12
  getFileFormat,
13
+ getFileFormatFromServiceOutput,
14
14
  getMimeTypeForFormat,
15
15
  ProxyService,
16
16
  } from '../../../../../../libs/util/shared/src'
@@ -45,7 +45,7 @@ interface WfsDownloadUrls {
45
45
  export class DataService {
46
46
  constructor(private proxy: ProxyService) {}
47
47
 
48
- private getDownloadUrlsFromWfs(
48
+ getDownloadUrlsFromWfs(
49
49
  wfsUrl: string,
50
50
  featureTypeName: string
51
51
  ): Observable<WfsDownloadUrls> {
@@ -120,7 +120,7 @@ export class DataService {
120
120
  )
121
121
  }
122
122
 
123
- private getDownloadUrlFromEsriRest(apiUrl: string, format: string): string {
123
+ getDownloadUrlFromEsriRest(apiUrl: string, format: string): string {
124
124
  return this.proxy.getProxiedUrl(
125
125
  `${apiUrl}/query?f=${format}&where=1=1&outFields=*`
126
126
  )
@@ -138,8 +138,11 @@ export class DataService {
138
138
  map((urls) =>
139
139
  Object.keys(urls).map((format) => ({
140
140
  ...wfsLink,
141
+ type: 'download',
141
142
  url: new URL(urls[format]),
142
- mimeType: getMimeTypeForFormat(extensionToFormat(format)) || format,
143
+ mimeType: getMimeTypeForFormat(
144
+ getFileFormatFromServiceOutput(format)
145
+ ),
143
146
  }))
144
147
  )
145
148
  )
@@ -153,7 +156,7 @@ export class DataService {
153
156
  url: new URL(
154
157
  this.getDownloadUrlFromEsriRest(esriRestLink.url.toString(), format)
155
158
  ),
156
- mimeType: getMimeTypeForFormat(extensionToFormat(format)) || format,
159
+ mimeType: getMimeTypeForFormat(getFileFormatFromServiceOutput(format)),
157
160
  }))
158
161
  }
159
162
 
@@ -1,6 +1,7 @@
1
1
  import { CommonModule } from '@angular/common'
2
2
  import { ChangeDetectionStrategy, Component } from '@angular/core'
3
3
  import { EditorService, FormField } from '../services/editor.service'
4
+ import { UiInputsModule } from '../../../../../../libs/ui/inputs/src'
4
5
 
5
6
  @Component({
6
7
  selector: 'gn-ui-record-form',
@@ -8,7 +9,7 @@ import { EditorService, FormField } from '../services/editor.service'
8
9
  styleUrls: ['./record-form.component.css'],
9
10
  changeDetection: ChangeDetectionStrategy.OnPush,
10
11
  standalone: true,
11
- imports: [CommonModule],
12
+ imports: [CommonModule, UiInputsModule],
12
13
  })
13
14
  export class RecordFormComponent {
14
15
  constructor(public editorService: EditorService) {}
@@ -17,3 +17,4 @@ export * from './lib/layers-panel/layers-panel.component'
17
17
  export * from './lib/add-layer-from-catalog/add-layer-from-catalog.component'
18
18
  export * from './lib/add-layer-from-catalog/add-layer-record-preview/add-layer-record-preview.component'
19
19
  export * from './lib/map-container/map-container.component'
20
+ export * from './lib/geocoding/geocoding.component'
@@ -1 +1,2 @@
1
1
  export * from './map-options'
2
+ export * from './projections'
@@ -23,6 +23,8 @@ import { UiInputsModule } from '../../../../../libs/ui/inputs/src'
23
23
  import { AddLayerFromWmsComponent } from './add-layer-from-wms/add-layer-from-wms.component'
24
24
  import { AddLayerFromFileComponent } from './add-layer-from-file/add-layer-from-file.component'
25
25
  import { AddLayerFromWfsComponent } from './add-layer-from-wfs/add-layer-from-wfs.component'
26
+ import { GeocodingComponent } from './geocoding/geocoding.component'
27
+ import { GEOCODING_PROVIDER, GeocodingProvider } from './geocoding.service'
26
28
 
27
29
  @NgModule({
28
30
  declarations: [
@@ -35,6 +37,7 @@ import { AddLayerFromWfsComponent } from './add-layer-from-wfs/add-layer-from-wf
35
37
  AddLayerFromWmsComponent,
36
38
  AddLayerFromFileComponent,
37
39
  AddLayerFromWfsComponent,
40
+ GeocodingComponent,
38
41
  ],
39
42
  exports: [
40
43
  MapContextComponent,
@@ -42,6 +45,7 @@ import { AddLayerFromWfsComponent } from './add-layer-from-wfs/add-layer-from-wf
42
45
  LayersPanelComponent,
43
46
  AddLayerFromCatalogComponent,
44
47
  MapContainerComponent,
48
+ GeocodingComponent,
45
49
  ],
46
50
  imports: [
47
51
  CommonModule,
@@ -62,6 +66,10 @@ import { AddLayerFromWfsComponent } from './add-layer-from-wfs/add-layer-from-wf
62
66
  useValue: defaultMapOptions,
63
67
  },
64
68
  MapFacade,
69
+ {
70
+ provide: GEOCODING_PROVIDER,
71
+ useValue: ['geonames', { maxRows: 5 }] as GeocodingProvider,
72
+ },
65
73
  ],
66
74
  })
67
75
  export class FeatureMapModule {}
@@ -0,0 +1,39 @@
1
+ <gn-ui-search-input
2
+ [(value)]="searchText"
3
+ (valueChange)="onSearchChange($event)"
4
+ (keyup.enter)="onEnterPress()"
5
+ [placeholder]="'map.geocoding.placeholder' | translate"
6
+ >
7
+ </gn-ui-search-input>
8
+ <ul
9
+ class="bg-gray-50 border border-gray-200 w-full mt-2 shadow-sm rounded-lg"
10
+ *ngIf="results && results.length"
11
+ >
12
+ <li
13
+ *ngFor="let result of results"
14
+ (click)="zoomToLocation(result)"
15
+ class="flex items-center pl-8 pr-4 py-2 border-b border-gray-200 relative cursor-pointer hover:bg-blue-100 hover:text-gray-800 transition duration-300 ease-in-out"
16
+ >
17
+ <svg
18
+ class="stroke-current text-blue-500 absolute w-5 h-5 left-3 top-3"
19
+ xmlns="http://www.w3.org/2000/svg"
20
+ fill="none"
21
+ viewBox="0 0 24 24"
22
+ stroke="currentColor"
23
+ >
24
+ <path
25
+ stroke-linecap="round"
26
+ stroke-linejoin="round"
27
+ stroke-width="2"
28
+ d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"
29
+ />
30
+ <path
31
+ stroke-linecap="round"
32
+ stroke-linejoin="round"
33
+ stroke-width="2"
34
+ d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"
35
+ />
36
+ </svg>
37
+ <span class="font-sans font-semibold ml-4">{{ result.label }}</span>
38
+ </li>
39
+ </ul>
@@ -0,0 +1,99 @@
1
+ import { Component, OnDestroy } from '@angular/core'
2
+ import { catchError, from, Subject, takeUntil } from 'rxjs'
3
+ import { debounceTime, switchMap } from 'rxjs/operators'
4
+ import { MapManagerService } from '../manager/map-manager.service'
5
+ import { fromLonLat } from 'ol/proj'
6
+ import { Polygon } from 'ol/geom'
7
+ import { GeocodingService } from '../geocoding.service'
8
+
9
+ @Component({
10
+ selector: 'gn-ui-geocoding',
11
+ templateUrl: './geocoding.component.html',
12
+ styleUrls: ['./geocoding.component.css'],
13
+ })
14
+ export class GeocodingComponent implements OnDestroy {
15
+ searchText = ''
16
+ results: any[] = []
17
+ searchTextChanged = new Subject<string>()
18
+ destroy$ = new Subject<void>()
19
+ errorMessage: string | null = null
20
+
21
+ constructor(
22
+ private mapManager: MapManagerService,
23
+ private geocodingService: GeocodingService
24
+ ) {
25
+ this.searchTextChanged
26
+ .pipe(
27
+ debounceTime(300),
28
+ switchMap((searchText) => {
29
+ return from(this.geocodingService.query(searchText)).pipe(
30
+ catchError((error) => {
31
+ this.errorMessage =
32
+ 'An error occurred while searching. Please try again.'
33
+ console.error(error)
34
+ return []
35
+ })
36
+ )
37
+ }),
38
+ takeUntil(this.destroy$)
39
+ )
40
+ .subscribe((results) => {
41
+ this.results = results
42
+ })
43
+ }
44
+
45
+ ngOnDestroy() {
46
+ this.destroy$.next()
47
+ this.destroy$.complete()
48
+ }
49
+
50
+ onSearchChange(searchText: string) {
51
+ if (!searchText) {
52
+ this.clearSearch()
53
+ return
54
+ } else {
55
+ this.searchTextChanged.next(searchText)
56
+ }
57
+ }
58
+
59
+ clearSearch() {
60
+ this.searchText = ''
61
+ this.results = []
62
+ this.errorMessage = null
63
+ }
64
+
65
+ zoomToLocation(result: any) {
66
+ const map = this.mapManager.map
67
+ const view = map.getView()
68
+ const geometry = result.geom
69
+
70
+ if (geometry.type === 'Point') {
71
+ this.zoomToPoint(geometry.coordinates, view)
72
+ } else if (geometry.type === 'Polygon') {
73
+ this.zoomToPolygon(geometry.coordinates, view)
74
+ } else {
75
+ console.error(`Unsupported geometry type: ${geometry.type}`)
76
+ }
77
+ }
78
+
79
+ zoomToPoint(pointCoords: [number, number], view: any) {
80
+ const transformedCoords = fromLonLat(pointCoords)
81
+ view.setCenter(transformedCoords)
82
+ view.setZoom(12)
83
+ }
84
+
85
+ zoomToPolygon(polygonCoords: [[number, number][]], view: any) {
86
+ const transformedCoords = polygonCoords[0].map((coord) => fromLonLat(coord))
87
+ const polygon = new Polygon([transformedCoords])
88
+ view.fit(polygon, {
89
+ duration: 100,
90
+ maxZoom: 12,
91
+ })
92
+ }
93
+
94
+ onEnterPress() {
95
+ if (this.results && this.results.length > 0) {
96
+ this.zoomToLocation(this.results[0])
97
+ }
98
+ }
99
+ }
@@ -0,0 +1,59 @@
1
+ import { Injectable, Inject, InjectionToken } from '@angular/core'
2
+ import {
3
+ queryGeoadmin,
4
+ GeoadminOptions,
5
+ GeocodingResult,
6
+ queryGeonames,
7
+ GeonamesOptions,
8
+ DataGouvFrOptions,
9
+ queryDataGouvFr,
10
+ } from '@geospatial-sdk/geocoding'
11
+ import { from, Observable, throwError } from 'rxjs'
12
+ import { catchError } from 'rxjs/operators'
13
+
14
+ type GeoadminGeocodingProvider = ['geoadmin', GeoadminOptions]
15
+ type GeonamesGeocodingProvider = ['geonames', GeonamesOptions]
16
+ type DataGouvFrGeocodingProvider = ['data-gouv-fr', DataGouvFrOptions]
17
+ export type GeocodingProvider =
18
+ | GeoadminGeocodingProvider
19
+ | GeonamesGeocodingProvider
20
+ | DataGouvFrGeocodingProvider
21
+
22
+ export const GEOCODING_PROVIDER = new InjectionToken<GeocodingProvider>(
23
+ 'geocoding-provider'
24
+ )
25
+
26
+ @Injectable({
27
+ providedIn: 'root',
28
+ })
29
+ export class GeocodingService {
30
+ constructor(
31
+ @Inject(GEOCODING_PROVIDER) private provider: GeocodingProvider
32
+ ) {}
33
+
34
+ query(text: string): Observable<GeocodingResult[]> {
35
+ let queryObservable: Observable<GeocodingResult[]>
36
+ switch (this.provider[0]) {
37
+ case 'geoadmin':
38
+ queryObservable = from(
39
+ queryGeoadmin(text, this.provider[1] as GeoadminOptions)
40
+ )
41
+ break
42
+ case 'geonames':
43
+ queryObservable = from(
44
+ queryGeonames(text, this.provider[1] as GeonamesOptions)
45
+ )
46
+ break
47
+ case 'data-gouv-fr':
48
+ queryObservable = from(
49
+ queryDataGouvFr(text, this.provider[1] as DataGouvFrOptions)
50
+ )
51
+ break
52
+ default:
53
+ return throwError(
54
+ () => new Error(`Unsupported geocoding provider: ${this.provider[0]}`)
55
+ )
56
+ }
57
+ return queryObservable.pipe(catchError((error) => throwError(error)))
58
+ }
59
+ }
@@ -1,3 +1 @@
1
1
  export * from './map-utils.service'
2
- export * from './map-utils-wms.service'
3
- export * from './projections'