@geogirafe/lib-geoportal 1.1.0-dev.2610902439 → 1.1.0-dev.2625220907
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/api/apicontext.d.ts +2 -0
- package/api/apicontext.js +4 -0
- package/assets/i18n/de.json +8 -0
- package/assets/i18n/en.json +8 -0
- package/assets/i18n/fr.json +8 -0
- package/assets/i18n/it.json +8 -0
- package/components/search/component.d.ts +6 -15
- package/components/search/component.js +71 -112
- package/components/search/style.css +21 -13
- package/components/search-mobile/component.js +2 -2
- package/components/search-mobile/style.css +25 -13
- package/package.json +1 -1
- package/templates/public/about.json +1 -1
- package/tools/auth/openidconnectmanager.js +10 -1
- package/tools/configuration/girafeconfig.d.ts +17 -2
- package/tools/configuration/girafeconfig.js +32 -12
- package/tools/context/context.d.ts +2 -0
- package/tools/context/context.js +4 -0
- package/tools/context/icontext.d.ts +2 -0
- package/tools/main.d.ts +7 -0
- package/tools/main.js +4 -0
- package/tools/search/abstractsearchclient.d.ts +42 -0
- package/tools/search/abstractsearchclient.js +85 -0
- package/tools/search/geoadminchsearchclient.d.ts +63 -0
- package/tools/search/geoadminchsearchclient.js +147 -0
- package/tools/search/gmfsearchclient.d.ts +23 -0
- package/tools/search/gmfsearchclient.js +37 -0
- package/tools/search/searchmanager.d.ts +33 -0
- package/tools/search/searchmanager.js +130 -0
- package/tools/tests/mockconfig.d.ts +4 -1
- package/tools/tests/mockconfig.js +1 -1
- package/tools/tests/mockcontext.d.ts +2 -0
- package/tools/tests/mockcontext.js +4 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import AbstractSearchClient from './abstractsearchclient.js';
|
|
2
|
+
/**
|
|
3
|
+
* A search provider for the GeoMapFish backend.
|
|
4
|
+
* Extends the AbstractSearchClient and provides methods tailored to processing GMF-specific search results.
|
|
5
|
+
*
|
|
6
|
+
* Configuration:
|
|
7
|
+
* - providerName: The name of the search provider, or geomapfish.
|
|
8
|
+
* - url: The URL of the GMF search service.
|
|
9
|
+
* - resultSrid: The spatial reference system (SRID) of the search results. Default same as map SRID.
|
|
10
|
+
*/
|
|
11
|
+
class GmfSearchClient extends AbstractSearchClient {
|
|
12
|
+
constructor(context, config) {
|
|
13
|
+
super(context, 'geomapfish', config.providerName, config.url, config.resultSrid);
|
|
14
|
+
}
|
|
15
|
+
groupedResults(results) {
|
|
16
|
+
const groupedResults = {};
|
|
17
|
+
for (const result of results) {
|
|
18
|
+
let group = 'Unknown layer type';
|
|
19
|
+
if (result.get('layer_name')) {
|
|
20
|
+
group = result.get('layer_name');
|
|
21
|
+
}
|
|
22
|
+
else if (result.get('actions')[0].action.startsWith('add_theme')) {
|
|
23
|
+
group = 'add_theme';
|
|
24
|
+
}
|
|
25
|
+
else if (result.get('actions')[0].action.startsWith('add_group')) {
|
|
26
|
+
group = 'add_group';
|
|
27
|
+
}
|
|
28
|
+
else if (result.get('actions')[0].action.startsWith('add_layer')) {
|
|
29
|
+
group = 'add_layer';
|
|
30
|
+
}
|
|
31
|
+
groupedResults[group] ??= [];
|
|
32
|
+
groupedResults[group].push(result);
|
|
33
|
+
}
|
|
34
|
+
return groupedResults;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export default GmfSearchClient;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import IGirafeContext from '../context/icontext.js';
|
|
2
|
+
import GirafeSingleton from '../../base/GirafeSingleton.js';
|
|
3
|
+
import Feature from 'ol/Feature.js';
|
|
4
|
+
import { Extent } from 'ol/extent.js';
|
|
5
|
+
export type SearchProviderConfig = {
|
|
6
|
+
type: 'geomapfish' | 'geoadminch';
|
|
7
|
+
providerName: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
declare class SearchManager extends GirafeSingleton {
|
|
11
|
+
private readonly clients;
|
|
12
|
+
private abortController;
|
|
13
|
+
readonly minSearchTermLength = 3;
|
|
14
|
+
constructor(context: IGirafeContext);
|
|
15
|
+
initializeSingleton(): void;
|
|
16
|
+
private createClient;
|
|
17
|
+
abortSearch(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Performs a search operation with all available clients based on the provided term and returns results
|
|
20
|
+
* grouped by provider name and result category.
|
|
21
|
+
*/
|
|
22
|
+
doSearch(term: string): Promise<Record<string, Record<string, Feature[]>> | null>;
|
|
23
|
+
private createCoordinateSearchResult;
|
|
24
|
+
/**
|
|
25
|
+
* Detects and parses a coordinate search term into an array of two numerical values.
|
|
26
|
+
* The method attempts to identify valid coordinate pairs from the given term,
|
|
27
|
+
* using different separators such as `;`, `/`, `,`, or whitespace.
|
|
28
|
+
*/
|
|
29
|
+
detectCoordinatesInTerm(term: string): [number, number] | null;
|
|
30
|
+
private parseCoordinate;
|
|
31
|
+
getZoomToBbox(feature: Feature): Extent | undefined;
|
|
32
|
+
}
|
|
33
|
+
export default SearchManager;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { SEARCH_GROUP_RECENTER_MAP, SEARCH_PROVIDER_DEFAULT } from './abstractsearchclient.js';
|
|
3
|
+
import GeoAdminChSearchClient from './geoadminchsearchclient.js';
|
|
4
|
+
import GmfSearchClient from './gmfsearchclient.js';
|
|
5
|
+
import GirafeSingleton from '../../base/GirafeSingleton.js';
|
|
6
|
+
import Feature from 'ol/Feature.js';
|
|
7
|
+
import { parseCoordinates } from '../geometrytools.js';
|
|
8
|
+
import { Point } from 'ol/geom.js';
|
|
9
|
+
class SearchManager extends GirafeSingleton {
|
|
10
|
+
clients = new Map();
|
|
11
|
+
abortController = new AbortController();
|
|
12
|
+
minSearchTermLength = 3;
|
|
13
|
+
constructor(context) {
|
|
14
|
+
super(context);
|
|
15
|
+
}
|
|
16
|
+
initializeSingleton() {
|
|
17
|
+
super.initializeSingleton();
|
|
18
|
+
for (const providerConfig of this.context.configManager.Config.search.providers ?? []) {
|
|
19
|
+
this.createClient(providerConfig);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
createClient(providerConfig) {
|
|
23
|
+
switch (providerConfig.type) {
|
|
24
|
+
case 'geomapfish':
|
|
25
|
+
this.clients.set(providerConfig.type, new GmfSearchClient(this.context, providerConfig));
|
|
26
|
+
break;
|
|
27
|
+
case 'geoadminch':
|
|
28
|
+
this.clients.set(providerConfig.type, new GeoAdminChSearchClient(this.context, providerConfig));
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
console.error(`Unknown search type: ${providerConfig.type}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
abortSearch() {
|
|
35
|
+
this.abortController.abort();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Performs a search operation with all available clients based on the provided term and returns results
|
|
39
|
+
* grouped by provider name and result category.
|
|
40
|
+
*/
|
|
41
|
+
async doSearch(term) {
|
|
42
|
+
// Cancel any previous search
|
|
43
|
+
this.abortSearch();
|
|
44
|
+
// Create a new controller for the new request
|
|
45
|
+
this.abortController = new AbortController();
|
|
46
|
+
let searchResults = null;
|
|
47
|
+
const coordinates = this.detectCoordinatesInTerm(term);
|
|
48
|
+
if (coordinates) {
|
|
49
|
+
searchResults = this.createCoordinateSearchResult(coordinates);
|
|
50
|
+
}
|
|
51
|
+
if (!searchResults && term.length >= this.minSearchTermLength) {
|
|
52
|
+
const responsesArray = await Promise.all(Array.from(this.clients.values()).map(async (client) => {
|
|
53
|
+
const response = await client.requestSearch(term, this.abortController);
|
|
54
|
+
return { [client.providerName]: client.groupedResults(response) };
|
|
55
|
+
}));
|
|
56
|
+
// Merge the responses of multiple clients into a single object that has the client name as key
|
|
57
|
+
// and the grouped results as values
|
|
58
|
+
searchResults = responsesArray.reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
59
|
+
}
|
|
60
|
+
return searchResults;
|
|
61
|
+
}
|
|
62
|
+
createCoordinateSearchResult(coordinates) {
|
|
63
|
+
const [coord1, coord2] = coordinates;
|
|
64
|
+
const currentSrid = this.context.mapManager.getMap().getView().getProjection().getCode();
|
|
65
|
+
const maxExtent = this.context.configManager.Config.map.maxExtent?.split(',').map(Number);
|
|
66
|
+
const [eastCoord, northCoord] = parseCoordinates([coord1, coord2], maxExtent, currentSrid);
|
|
67
|
+
if (!eastCoord || !northCoord) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const resultFeature = new Feature({
|
|
71
|
+
geometry: new Point([eastCoord, northCoord]),
|
|
72
|
+
label: `${coord1} ${coord2}`
|
|
73
|
+
});
|
|
74
|
+
// Return this result grouped by the default provider and as part of the `recenter_map` group
|
|
75
|
+
return { [SEARCH_PROVIDER_DEFAULT]: { [SEARCH_GROUP_RECENTER_MAP]: [resultFeature] } };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Detects and parses a coordinate search term into an array of two numerical values.
|
|
79
|
+
* The method attempts to identify valid coordinate pairs from the given term,
|
|
80
|
+
* using different separators such as `;`, `/`, `,`, or whitespace.
|
|
81
|
+
*/
|
|
82
|
+
detectCoordinatesInTerm(term) {
|
|
83
|
+
term = term.trim();
|
|
84
|
+
let parts = [];
|
|
85
|
+
// Supported separators:
|
|
86
|
+
const separators = [
|
|
87
|
+
{ char: ';' },
|
|
88
|
+
{ char: '/' },
|
|
89
|
+
// Only search for one comma, because a comma could also be used as a decimal separator
|
|
90
|
+
{ char: ',', condition: () => [...term].filter((c) => c === ',').length === 1 },
|
|
91
|
+
// Whitespace separator
|
|
92
|
+
{ char: null, regex: /\s+/ }
|
|
93
|
+
];
|
|
94
|
+
// Search for the coordinate separator step-wise
|
|
95
|
+
for (const { char, regex, condition } of separators) {
|
|
96
|
+
if (char && (condition ? condition() : term.includes(char))) {
|
|
97
|
+
parts = term.split(char);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
else if (regex?.test(term)) {
|
|
101
|
+
parts = term.split(regex);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (parts.length !== 2) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const first = this.parseCoordinate(parts[0]);
|
|
109
|
+
const second = this.parseCoordinate(parts[1]);
|
|
110
|
+
return first === null || second === null ? null : [first, second];
|
|
111
|
+
}
|
|
112
|
+
parseCoordinate(value) {
|
|
113
|
+
const normalized = value
|
|
114
|
+
// Remove coordinate prefix and thousand separator
|
|
115
|
+
.replace(/[NESW']/g, '')
|
|
116
|
+
// Relace decimal separator
|
|
117
|
+
.replace(',', '.')
|
|
118
|
+
.trim();
|
|
119
|
+
const number = Number(normalized);
|
|
120
|
+
return Number.isFinite(number) ? number : null;
|
|
121
|
+
}
|
|
122
|
+
getZoomToBbox(feature) {
|
|
123
|
+
const provider = feature.get('provider');
|
|
124
|
+
if (this.clients.has(provider)) {
|
|
125
|
+
return this.clients.get(provider)?.getZoomToBbox(feature);
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export default SearchManager;
|
|
@@ -31,7 +31,7 @@ export const MockConfig = {
|
|
|
31
31
|
maxExtent: '2200000,1040000,3000000,1310000'
|
|
32
32
|
},
|
|
33
33
|
search: {
|
|
34
|
-
url: 'https://search.url?query=###SEARCHTERM###'
|
|
34
|
+
providers: [{ type: 'geomapfish', url: 'https://search.url?query=###SEARCHTERM###' }]
|
|
35
35
|
},
|
|
36
36
|
share: {
|
|
37
37
|
createUrl: 'https://share.url'
|
|
@@ -31,6 +31,7 @@ import WfsManager from '../wfs/wfsmanager';
|
|
|
31
31
|
import WmsManager from '../wms/wmsmanager';
|
|
32
32
|
import OnBoardingManager from '../onboarding/onboardingmanager';
|
|
33
33
|
import ThemeFavoritesManager from '../themes/themefavoritesmanager';
|
|
34
|
+
import SearchManager from '../search/searchmanager';
|
|
34
35
|
import FeedbackManager from '../feedback/feedbackmanager';
|
|
35
36
|
export default class MockGirafeContext implements IGirafeContext {
|
|
36
37
|
readonly userDataManager: UserDataManager;
|
|
@@ -65,6 +66,7 @@ export default class MockGirafeContext implements IGirafeContext {
|
|
|
65
66
|
readonly localFileManager: LocalFileManager;
|
|
66
67
|
readonly onBoardingManager: OnBoardingManager;
|
|
67
68
|
readonly themeFavoritesManager: ThemeFavoritesManager;
|
|
69
|
+
readonly searchManager: SearchManager;
|
|
68
70
|
readonly feedbackManager: FeedbackManager;
|
|
69
71
|
constructor();
|
|
70
72
|
initialize(): Promise<void>;
|
|
@@ -33,6 +33,7 @@ import WmsManager from '../wms/wmsmanager';
|
|
|
33
33
|
import { MockConfig } from './mockconfig';
|
|
34
34
|
import OnBoardingManager from '../onboarding/onboardingmanager';
|
|
35
35
|
import ThemeFavoritesManager from '../themes/themefavoritesmanager';
|
|
36
|
+
import SearchManager from '../search/searchmanager';
|
|
36
37
|
import FeedbackManager from '../feedback/feedbackmanager';
|
|
37
38
|
export default class MockGirafeContext {
|
|
38
39
|
userDataManager;
|
|
@@ -67,6 +68,7 @@ export default class MockGirafeContext {
|
|
|
67
68
|
localFileManager;
|
|
68
69
|
onBoardingManager;
|
|
69
70
|
themeFavoritesManager;
|
|
71
|
+
searchManager;
|
|
70
72
|
feedbackManager;
|
|
71
73
|
constructor() {
|
|
72
74
|
this.componentManager = new ComponentManager(this);
|
|
@@ -101,6 +103,7 @@ export default class MockGirafeContext {
|
|
|
101
103
|
this.ogcApiFeaturesManager = new OgcApiFeaturesManager(this);
|
|
102
104
|
this.onBoardingManager = new OnBoardingManager(this);
|
|
103
105
|
this.themeFavoritesManager = new ThemeFavoritesManager(this);
|
|
106
|
+
this.searchManager = new SearchManager(this);
|
|
104
107
|
this.feedbackManager = new FeedbackManager(this);
|
|
105
108
|
this.initialize();
|
|
106
109
|
}
|
|
@@ -145,6 +148,7 @@ export default class MockGirafeContext {
|
|
|
145
148
|
this.ogcApiFeaturesManager.initializeSingleton();
|
|
146
149
|
this.onBoardingManager.initializeSingleton();
|
|
147
150
|
this.themeFavoritesManager.initializeSingleton();
|
|
151
|
+
this.searchManager.initializeSingleton();
|
|
148
152
|
this.feedbackManager.initializeSingleton();
|
|
149
153
|
}
|
|
150
154
|
}
|