@geogirafe/lib-geoportal 1.3.0-dev.3053452205 → 1.3.0-dev.3079206142
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/LICENSE +1 -0
- package/assets/i18n/de.json +33 -3
- package/assets/i18n/en.json +32 -2
- package/assets/i18n/fr.json +34 -4
- package/assets/i18n/it.json +36 -6
- package/assets/icons/edit.svg +1 -1
- package/assets/icons/lock.svg +1 -0
- package/components/cross-section/cross-section-settings/component.js +1 -1
- package/components/edit/component.d.ts +52 -36
- package/components/edit/component.js +340 -292
- package/components/edit/editcomponentstate.d.ts +1 -0
- package/components/edit/editcomponentstate.js +1 -0
- package/components/edit/editform/component.d.ts +33 -4
- package/components/edit/editform/component.js +218 -37
- package/components/edit/editform/style.css +51 -16
- package/components/edit/geometryedithelper.d.ts +47 -0
- package/components/edit/geometryedithelper.js +324 -0
- package/components/edit/style.css +71 -28
- package/components/main.d.ts +1 -1
- package/components/main.js +1 -1
- package/components/print/component.d.ts +1 -1
- package/components/treeview/tools/treeviewelement.d.ts +1 -0
- package/components/treeview/tools/treeviewelement.js +22 -0
- package/components/treeview/treeviewitem/component.js +7 -1
- package/models/gmf.d.ts +18 -2
- package/models/gmf.js +3 -1
- package/models/layers/editablelayer.d.ts +7 -0
- package/models/layers/editablelayer.js +7 -0
- package/models/layers/layerwms.d.ts +1 -2
- package/models/layers/layerwms.js +4 -8
- package/models/main.d.ts +9 -4
- package/models/main.js +6 -2
- package/models/oapiflayer.d.ts +29 -0
- package/models/oapiflayer.js +40 -0
- package/models/oapiftypes.d.ts +71 -0
- package/models/oapiftypes.js +29 -0
- package/models/serverogc.d.ts +5 -3
- package/models/serverogc.js +19 -6
- package/models/serverogcapi.d.ts +2 -0
- package/models/serverogcapi.js +2 -0
- package/models/serverogcapifeatures.d.ts +5 -62
- package/models/serverogcapifeatures.js +8 -4
- package/package.json +1 -1
- package/templates/index.html +1 -0
- package/templates/public/about.json +1 -1
- package/tools/app/geogirafeapp.js +2 -2
- package/tools/drawing/olDrawing.js +2 -22
- package/tools/drawing/shapeConstraints.d.ts +2 -1
- package/tools/drawing/shapeConstraints.js +18 -2
- package/tools/main.d.ts +7 -5
- package/tools/main.js +7 -5
- package/tools/ogcapi/ogcapiclient.d.ts +7 -3
- package/tools/ogcapi/ogcapiclient.js +49 -4
- package/tools/ogcapi/ogcapiconformance.d.ts +2 -2
- package/tools/ogcapi/ogcapiconformance.js +7 -13
- package/tools/ogcapi/ogcapifeaturesclient.d.ts +65 -30
- package/tools/ogcapi/ogcapifeaturesclient.js +265 -139
- package/tools/ogcapi/ogcapifeaturesclientgeorama.d.ts +0 -5
- package/tools/ogcapi/ogcapifeaturesclientgeorama.js +0 -11
- package/tools/ogcapi/ogcapifeaturesclientqgis.d.ts +8 -0
- package/tools/ogcapi/ogcapifeaturesclientqgis.js +13 -0
- package/tools/ogcapi/ogcapifeaturesmanager.d.ts +61 -8
- package/tools/ogcapi/ogcapifeaturesmanager.js +179 -30
- package/tools/ogcapi/ogcapifeaturesschema.d.ts +31 -13
- package/tools/ogcapi/ogcapifeaturesschema.js +69 -39
- package/tools/ogcapi/ogcapifeaturesschemaproperty.d.ts +44 -0
- package/tools/ogcapi/ogcapifeaturesschemaproperty.js +137 -0
- package/tools/ogcapi/ogcapifeaturesschemavalidator.d.ts +22 -0
- package/tools/ogcapi/ogcapifeaturesschemavalidator.js +121 -0
- package/tools/state/state.d.ts +6 -0
- package/tools/state/state.js +4 -0
- package/tools/themes/themesmanager.d.ts +10 -3
- package/tools/themes/themesmanager.js +29 -9
- package/tools/time/layertimeformatter.d.ts +0 -5
- package/tools/time/layertimeformatter.js +10 -19
- package/tools/utils/dateutils.d.ts +40 -0
- package/tools/utils/dateutils.js +111 -0
- package/tools/utils/utils.d.ts +4 -0
- package/tools/utils/utils.js +12 -0
- package/tools/wfs/wfsmanager.js +3 -0
- package/tools/wms/wmsclient.d.ts +1 -0
- package/tools/wms/wmsclient.js +4 -0
- package/tools/ogcapi/demolayers.d.ts +0 -1
- package/tools/ogcapi/demolayers.js +0 -99
- package/tools/ogcapi/ogcapifeaturesclientgmf.d.ts +0 -13
- package/tools/ogcapi/ogcapifeaturesclientgmf.js +0 -30
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { oapifTemporalFormats } from '../../models/oapiftypes.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a schema property in the context of an OGC API Features implementation.
|
|
5
|
+
* This class defines characteristics and metadata for a property, including type, role, and other attributes.
|
|
6
|
+
*/
|
|
7
|
+
export class OgcApiFeaturesSchemaProperty {
|
|
8
|
+
name;
|
|
9
|
+
isRequired;
|
|
10
|
+
options;
|
|
11
|
+
referenceList;
|
|
12
|
+
constructor(name, options, required = false) {
|
|
13
|
+
this.name = name;
|
|
14
|
+
// Set defaults
|
|
15
|
+
this.options = { ...options };
|
|
16
|
+
this.isRequired = required || this.isPrimaryKey;
|
|
17
|
+
}
|
|
18
|
+
get title() {
|
|
19
|
+
return this.options.title ?? this.name;
|
|
20
|
+
}
|
|
21
|
+
get description() {
|
|
22
|
+
return this.options.description;
|
|
23
|
+
}
|
|
24
|
+
get propertyType() {
|
|
25
|
+
return this.options.type?.toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
get format() {
|
|
28
|
+
return this.options.format?.toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
get minLength() {
|
|
31
|
+
return this.parseNumber(this.options.minLength);
|
|
32
|
+
}
|
|
33
|
+
get maxLength() {
|
|
34
|
+
return this.parseNumber(this.options.maxLength);
|
|
35
|
+
}
|
|
36
|
+
get pattern() {
|
|
37
|
+
return this.options.pattern;
|
|
38
|
+
}
|
|
39
|
+
get minimum() {
|
|
40
|
+
return this.parseNumber(this.options.minimum);
|
|
41
|
+
}
|
|
42
|
+
get maximum() {
|
|
43
|
+
return this.parseNumber(this.options.maximum);
|
|
44
|
+
}
|
|
45
|
+
get exclusiveMinimum() {
|
|
46
|
+
return this.parseNumber(this.options.exclusiveMinimum);
|
|
47
|
+
}
|
|
48
|
+
get exclusiveMaximum() {
|
|
49
|
+
return this.parseNumber(this.options.exclusiveMaximum);
|
|
50
|
+
}
|
|
51
|
+
get isTextProperty() {
|
|
52
|
+
return this.propertyType === 'string' && !this.options.format && !this.isValueListProperty;
|
|
53
|
+
}
|
|
54
|
+
get isNumericProperty() {
|
|
55
|
+
return ['number', 'integer'].includes(this.propertyType ?? '') && !this.isValueListProperty;
|
|
56
|
+
}
|
|
57
|
+
isIntegerProperty() {
|
|
58
|
+
return (this.propertyType === 'integer' && (!this.format || this.format.includes('int')) && !this.isValueListProperty);
|
|
59
|
+
}
|
|
60
|
+
get isBooleanProperty() {
|
|
61
|
+
return this.propertyType === 'boolean';
|
|
62
|
+
}
|
|
63
|
+
get isTemporalProperty() {
|
|
64
|
+
return this.propertyType === 'string' && oapifTemporalFormats.includes((this.options.format ?? '').toLowerCase());
|
|
65
|
+
}
|
|
66
|
+
get isValueListProperty() {
|
|
67
|
+
return !!this.options.enum || !!this.options.oneOf || this.hasReference;
|
|
68
|
+
}
|
|
69
|
+
get isFormProperty() {
|
|
70
|
+
return !this.isGeometry;
|
|
71
|
+
}
|
|
72
|
+
get sortOrder() {
|
|
73
|
+
return this.options['x-ogc-propertySeq'] ?? null;
|
|
74
|
+
}
|
|
75
|
+
get isGeometry() {
|
|
76
|
+
return this.options.format?.startsWith('geometry') ?? false;
|
|
77
|
+
}
|
|
78
|
+
get isPrimaryGeometry() {
|
|
79
|
+
return this.options['x-ogc-role'] === 'primary-geometry';
|
|
80
|
+
}
|
|
81
|
+
get isPrimaryKey() {
|
|
82
|
+
return this.options['x-ogc-role'] === 'id';
|
|
83
|
+
}
|
|
84
|
+
get isReadOnly() {
|
|
85
|
+
return this.options.readOnly ?? false;
|
|
86
|
+
}
|
|
87
|
+
get valueListEntries() {
|
|
88
|
+
if (!this.isValueListProperty) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
if (this.hasReference) {
|
|
92
|
+
return this.referenceList ?? [];
|
|
93
|
+
}
|
|
94
|
+
if (this.options.enum) {
|
|
95
|
+
return this.options.enum?.map((value) => {
|
|
96
|
+
return { value: value, title: `${value}` };
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (this.options.oneOf) {
|
|
100
|
+
return this.options.oneOf?.map((option) => {
|
|
101
|
+
return { value: option.const, title: option.title ?? `${option.const}` };
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
get hasReference() {
|
|
107
|
+
return this.options['x-ogc-role'] === 'reference' && !!this.options['x-ogc-collectionId'];
|
|
108
|
+
}
|
|
109
|
+
get internalReference() {
|
|
110
|
+
return this.options['x-ogc-collectionId'];
|
|
111
|
+
}
|
|
112
|
+
isNullValue(value) {
|
|
113
|
+
if (value === undefined || value === null) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (value === true || value === false) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (this.options['x-ogc-nullValues']) {
|
|
120
|
+
return this.options['x-ogc-nullValues'].includes(value);
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
setReferenceList(referenceList) {
|
|
125
|
+
if (referenceList && referenceList[0] instanceof Object) {
|
|
126
|
+
this.referenceList = referenceList;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.referenceList = referenceList.map((value) => {
|
|
130
|
+
return { value: value, title: `${value}` };
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
parseNumber(value) {
|
|
135
|
+
return Number.isNaN(Number(value)) ? undefined : value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { OgcApiFeaturesSchemaProperty } from './ogcapifeaturesschemaproperty.js';
|
|
2
|
+
import IGirafeContext from '../context/icontext.js';
|
|
3
|
+
type FormValue = string | number | boolean | null;
|
|
4
|
+
export default class OgcApiFeaturesSchemaValidator {
|
|
5
|
+
private readonly context;
|
|
6
|
+
private readonly validationRules;
|
|
7
|
+
constructor(context: IGirafeContext);
|
|
8
|
+
validate(property: OgcApiFeaturesSchemaProperty, formValue: FormValue): string[];
|
|
9
|
+
private validateRequired;
|
|
10
|
+
private validateMinLength;
|
|
11
|
+
private validateMaxLength;
|
|
12
|
+
private validatePattern;
|
|
13
|
+
private validateNumeric;
|
|
14
|
+
private validateMinimum;
|
|
15
|
+
private validateMaximum;
|
|
16
|
+
private validateExclusiveMinimum;
|
|
17
|
+
private validateExclusiveMaximum;
|
|
18
|
+
private i18n;
|
|
19
|
+
private isNumericValue;
|
|
20
|
+
private isNullOrUndefinedOrBlank;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export default class OgcApiFeaturesSchemaValidator {
|
|
2
|
+
context;
|
|
3
|
+
validationRules;
|
|
4
|
+
constructor(context) {
|
|
5
|
+
this.context = context;
|
|
6
|
+
this.validationRules = [
|
|
7
|
+
(prop, val) => this.validateRequired(prop, val),
|
|
8
|
+
(prop, val) => this.validateMinLength(prop, val),
|
|
9
|
+
(prop, val) => this.validateMaxLength(prop, val),
|
|
10
|
+
(prop, val) => this.validatePattern(prop, val),
|
|
11
|
+
(prop, val) => this.validateNumeric(prop, val),
|
|
12
|
+
(prop, val) => this.validateMinimum(prop, val),
|
|
13
|
+
(prop, val) => this.validateMaximum(prop, val),
|
|
14
|
+
(prop, val) => this.validateExclusiveMinimum(prop, val),
|
|
15
|
+
(prop, val) => this.validateExclusiveMaximum(prop, val)
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
validate(property, formValue) {
|
|
19
|
+
return this.validationRules
|
|
20
|
+
.map((rule) => rule(property, formValue))
|
|
21
|
+
.filter((error) => Boolean(error));
|
|
22
|
+
}
|
|
23
|
+
validateRequired(property, value) {
|
|
24
|
+
if (!property.isRequired || !this.isNullOrUndefinedOrBlank(value)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return this.i18n('A value is required');
|
|
28
|
+
}
|
|
29
|
+
validateMinLength(property, value) {
|
|
30
|
+
if (!property.minLength || value === '' || typeof value !== 'string' || value.length >= property.minLength) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return this.i18n('The value must be at least _minLen_ characters long', {
|
|
34
|
+
_minLen_: property.minLength.toString()
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
validateMaxLength(property, value) {
|
|
38
|
+
if (!property.maxLength || value === '' || typeof value !== 'string' || value.length <= property.maxLength) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return this.i18n('The value must be no longer than _maxLen_ characters', {
|
|
42
|
+
_maxLen_: property.maxLength.toString()
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
validatePattern(property, value) {
|
|
46
|
+
if (!property.pattern || value === '' || typeof value !== 'string' || new RegExp(property.pattern).test(value)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return this.i18n('The value must satisfy the regular expression pattern _pattern_', {
|
|
50
|
+
_pattern_: property.pattern
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
validateNumeric(property, value) {
|
|
54
|
+
if (!property.isNumericProperty || this.isNullOrUndefinedOrBlank(value)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return !this.isNumericValue(value) ? this.i18n('The value must be a number') : null;
|
|
58
|
+
}
|
|
59
|
+
validateMinimum(property, value) {
|
|
60
|
+
if (property.minimum === undefined || !this.isNumericValue(value)) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (Number(value) < property.minimum) {
|
|
64
|
+
return this.i18n('The value must be greater than or equal to _min_', {
|
|
65
|
+
_min_: property.minimum.toString()
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
validateMaximum(property, value) {
|
|
71
|
+
if (property.maximum === undefined || !this.isNumericValue(value)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (Number(value) > property.maximum) {
|
|
75
|
+
return this.i18n('The value must be less than or equal to _max_', {
|
|
76
|
+
_max_: property.maximum.toString()
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
validateExclusiveMinimum(property, value) {
|
|
82
|
+
if (property.exclusiveMinimum === undefined || !this.isNumericValue(value)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
if (Number(value) <= property.exclusiveMinimum) {
|
|
86
|
+
return this.i18n('The value must be greater than _min_', {
|
|
87
|
+
_min_: property.exclusiveMinimum.toString()
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
validateExclusiveMaximum(property, value) {
|
|
93
|
+
if (property.exclusiveMaximum === undefined || !this.isNumericValue(value)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
if (Number(value) >= property.exclusiveMaximum) {
|
|
97
|
+
return this.i18n('The value must be less than _max_', {
|
|
98
|
+
_max_: property.exclusiveMaximum.toString()
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
i18n(key, replacements) {
|
|
104
|
+
let message = this.context.i18nManager.getTranslation(key);
|
|
105
|
+
if (replacements) {
|
|
106
|
+
for (const [placeholder, val] of Object.entries(replacements)) {
|
|
107
|
+
message = message.replace(placeholder, val);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return message;
|
|
111
|
+
}
|
|
112
|
+
isNumericValue(value) {
|
|
113
|
+
if (this.isNullOrUndefinedOrBlank(value) || typeof value === 'boolean') {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return !Number.isNaN(Number(value));
|
|
117
|
+
}
|
|
118
|
+
isNullOrUndefinedOrBlank(val) {
|
|
119
|
+
return val === undefined || val === null || val === '' || (typeof val === 'string' && val.trim() === '');
|
|
120
|
+
}
|
|
121
|
+
}
|
package/tools/state/state.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type Theme from '../../models/theme.js';
|
|
|
16
16
|
import GraphicalInterface from './graphicalInterface.js';
|
|
17
17
|
import { GMFThemeFunctionalities, GMFThemeFunctionality } from '../../models/gmf.js';
|
|
18
18
|
import { LayerId } from '../../models/layerdefinitions.js';
|
|
19
|
+
import { EditableLayer } from '../../models/layers/editablelayer.js';
|
|
19
20
|
export type ThemesConfig = {
|
|
20
21
|
_allThemes: Record<LayerId, ThemeLayer>;
|
|
21
22
|
_allFunctionalities: Record<LayerId, GMFThemeFunctionalities>;
|
|
@@ -79,6 +80,10 @@ export type SearchState = {
|
|
|
79
80
|
filterShortcutPrefix: string | null;
|
|
80
81
|
filterShortcut: string | null;
|
|
81
82
|
};
|
|
83
|
+
type EditingState = {
|
|
84
|
+
available: boolean | null;
|
|
85
|
+
layer: EditableLayer | null;
|
|
86
|
+
};
|
|
82
87
|
export type ExtendedState = Record<string, object>;
|
|
83
88
|
export default class State {
|
|
84
89
|
/**
|
|
@@ -125,6 +130,7 @@ export default class State {
|
|
|
125
130
|
isOffline: boolean;
|
|
126
131
|
oauth: LoginState;
|
|
127
132
|
search: SearchState;
|
|
133
|
+
editing: EditingState;
|
|
128
134
|
extendedState: ExtendedState;
|
|
129
135
|
}
|
|
130
136
|
export {};
|
package/tools/state/state.js
CHANGED
|
@@ -126,6 +126,10 @@ export default class State {
|
|
|
126
126
|
filterShortcutPrefix: null,
|
|
127
127
|
filterShortcut: null
|
|
128
128
|
};
|
|
129
|
+
editing = {
|
|
130
|
+
available: null,
|
|
131
|
+
layer: null
|
|
132
|
+
};
|
|
129
133
|
// The State object is defined as <not extensible> by the StateManager.
|
|
130
134
|
// This property can be used by third-parts components or extensions
|
|
131
135
|
// to add custom attributes to the state.
|
|
@@ -13,11 +13,18 @@ declare class ThemesManager extends GirafeSingleton {
|
|
|
13
13
|
private setDefaultBasemap;
|
|
14
14
|
private prepareOgcServers;
|
|
15
15
|
/**
|
|
16
|
-
* Preload all WFS DescribeFeatureType
|
|
17
|
-
* In order to limit the network
|
|
18
|
-
* and each call will wait the previous one to be done
|
|
16
|
+
* Preload all WFS DescribeFeatureType.
|
|
17
|
+
* In order to limit the network load, the server calls are done sequentially
|
|
18
|
+
* and each call will wait the previous one to be done.
|
|
19
19
|
*/
|
|
20
20
|
private preloadWfsServer;
|
|
21
|
+
/**
|
|
22
|
+
* Preload all OAPIF servers.
|
|
23
|
+
* In order to limit the network load, the server calls are done sequentially
|
|
24
|
+
* and each call will wait the previous one to be done.
|
|
25
|
+
*/
|
|
26
|
+
private preloadOapifServer;
|
|
27
|
+
private preloadOapifServerForEditing;
|
|
21
28
|
private prepareBasemaps;
|
|
22
29
|
private addBasemapsFromConfig;
|
|
23
30
|
private applyOpacityToBasemaps;
|
|
@@ -142,18 +142,19 @@ class ThemesManager extends GirafeSingleton {
|
|
|
142
142
|
const servers = {};
|
|
143
143
|
if (ogcServerJson) {
|
|
144
144
|
for (const serverName of Object.keys(ogcServerJson)) {
|
|
145
|
-
|
|
146
|
-
servers[serverName] = server;
|
|
145
|
+
servers[serverName] = new ServerOgc(serverName, ogcServerJson[serverName]);
|
|
147
146
|
}
|
|
148
147
|
// Preload WFS FeatureInfos
|
|
149
|
-
this.preloadWfsServer(servers);
|
|
148
|
+
void this.preloadWfsServer(servers);
|
|
149
|
+
// Preload OAPIF servers for editing
|
|
150
|
+
void this.preloadOapifServer(servers);
|
|
150
151
|
}
|
|
151
152
|
return servers;
|
|
152
153
|
}
|
|
153
154
|
/**
|
|
154
|
-
* Preload all WFS DescribeFeatureType
|
|
155
|
-
* In order to limit the network
|
|
156
|
-
* and each call will wait the previous one to be done
|
|
155
|
+
* Preload all WFS DescribeFeatureType.
|
|
156
|
+
* In order to limit the network load, the server calls are done sequentially
|
|
157
|
+
* and each call will wait the previous one to be done.
|
|
157
158
|
*/
|
|
158
159
|
async preloadWfsServer(ogcServers) {
|
|
159
160
|
for (const server of Object.values(ogcServers)) {
|
|
@@ -162,6 +163,21 @@ class ThemesManager extends GirafeSingleton {
|
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Preload all OAPIF servers.
|
|
168
|
+
* In order to limit the network load, the server calls are done sequentially
|
|
169
|
+
* and each call will wait the previous one to be done.
|
|
170
|
+
*/
|
|
171
|
+
async preloadOapifServer(ogcServers) {
|
|
172
|
+
const editServers = Object.values(ogcServers).filter((server) => server.hasEditService);
|
|
173
|
+
await editServers.reduce((previous, server) => previous.then(() => this.preloadOapifServerForEditing(server)), Promise.resolve());
|
|
174
|
+
}
|
|
175
|
+
async preloadOapifServerForEditing(server) {
|
|
176
|
+
const oapifServer = await this.context.ogcApiFeaturesManager.tryGetServer(server);
|
|
177
|
+
if (!this.state.editing.available && oapifServer?.hasEditableLayers) {
|
|
178
|
+
this.state.editing.available = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
165
181
|
async prepareBasemaps(basemapJson) {
|
|
166
182
|
const basemaps = {};
|
|
167
183
|
if (this.context.configManager.Config.basemaps.emptyBasemap) {
|
|
@@ -276,7 +292,7 @@ class ThemesManager extends GirafeSingleton {
|
|
|
276
292
|
break;
|
|
277
293
|
}
|
|
278
294
|
case 'WMS': {
|
|
279
|
-
layer = this.createWmsLayer(ogcServerName, elem, order);
|
|
295
|
+
layer = await this.createWmsLayer(ogcServerName, elem, order);
|
|
280
296
|
break;
|
|
281
297
|
}
|
|
282
298
|
case 'COG': {
|
|
@@ -363,7 +379,7 @@ class ThemesManager extends GirafeSingleton {
|
|
|
363
379
|
return null;
|
|
364
380
|
}
|
|
365
381
|
}
|
|
366
|
-
createWmsLayer(ogcServerName, elem, order) {
|
|
382
|
+
async createWmsLayer(ogcServerName, elem, order) {
|
|
367
383
|
if (ogcServerName) {
|
|
368
384
|
const ogcServer = this.state.ogcServers[ogcServerName];
|
|
369
385
|
const options = elem;
|
|
@@ -371,11 +387,15 @@ class ThemesManager extends GirafeSingleton {
|
|
|
371
387
|
options.metadata.metadataUrl = applyDefaultPrefixToUrl(this.context, options.metadata.metadataUrl);
|
|
372
388
|
}
|
|
373
389
|
const wmsLayer = new LayerWms(elem.id, elem.name, order.value, ogcServer, elem);
|
|
374
|
-
// For WMFS queries, the layers attribute will be used. It can be different from the name.
|
|
390
|
+
// For WMFS queries, the `layers` attribute will be used. It can be different from the name.
|
|
375
391
|
// But in order to be able to define the translations only once, we use an translation alias here.
|
|
376
392
|
if (wmsLayer.layers) {
|
|
377
393
|
this.context.i18nManager.addTranslationAlias(wmsLayer.name, wmsLayer.layers);
|
|
378
394
|
}
|
|
395
|
+
// If this layer can be edited, the associated layer names are provided by the editing (OAPIF) service.
|
|
396
|
+
if (ogcServer.hasEditService) {
|
|
397
|
+
wmsLayer.editLayers = await this.context.ogcApiFeaturesManager.getEditableLayerNames(wmsLayer);
|
|
398
|
+
}
|
|
379
399
|
return wmsLayer;
|
|
380
400
|
}
|
|
381
401
|
else {
|
|
@@ -56,12 +56,7 @@ declare class LayerTimeFormatter {
|
|
|
56
56
|
* @return {Filter | undefined} Returns a new OpenLayers WFS filter object, or undefined if no valid filter could be created.
|
|
57
57
|
*/
|
|
58
58
|
toOpenLayersWfsFilter(timeRestriction: string, timeAttribute: string): Filter | undefined;
|
|
59
|
-
private isValidDateString;
|
|
60
59
|
private isWithinRange;
|
|
61
|
-
/**
|
|
62
|
-
* Formats a given date into a date string of type 'YYYY-MM-DD'.
|
|
63
|
-
*/
|
|
64
|
-
private static formatAsDate;
|
|
65
60
|
private static getMondayOfWeek;
|
|
66
61
|
private static getSundayOfWeek;
|
|
67
62
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { during } from 'ol/format/filter.js';
|
|
2
|
+
import DateUtils from '../utils/dateutils.js';
|
|
2
3
|
export const TIME_RANGE_SEPARATOR = '/';
|
|
3
4
|
// In ISO 8601 format
|
|
4
5
|
const MIN_DATE = '1900-01-01T00:00:00.000Z';
|
|
@@ -83,9 +84,8 @@ class LayerTimeFormatter {
|
|
|
83
84
|
* @return {Date | undefined} The resulting Date object if the input is valid, otherwise undefined.
|
|
84
85
|
*/
|
|
85
86
|
parseDateString(dateStr) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return new Date(dateStr);
|
|
87
|
+
const normalizedDateString = DateUtils.normalizeDateTimeString(dateStr);
|
|
88
|
+
return normalizedDateString ? new Date(normalizedDateString) : undefined;
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* Helper method to quickly generate a formated query string from the default time restriction
|
|
@@ -110,8 +110,8 @@ class LayerTimeFormatter {
|
|
|
110
110
|
* @return {Filter | undefined} Returns a new OpenLayers WFS filter object, or undefined if no valid filter could be created.
|
|
111
111
|
*/
|
|
112
112
|
toOpenLayersWfsFilter(timeRestriction, timeAttribute) {
|
|
113
|
-
let lower = timeRestriction.split(
|
|
114
|
-
let upper = timeRestriction.split(
|
|
113
|
+
let lower = timeRestriction.split(TIME_RANGE_SEPARATOR)[0];
|
|
114
|
+
let upper = timeRestriction.split(TIME_RANGE_SEPARATOR)[1] ?? undefined;
|
|
115
115
|
let temporalFilter = undefined;
|
|
116
116
|
if (this.mode === 'range') {
|
|
117
117
|
temporalFilter = during(timeAttribute, lower, upper);
|
|
@@ -151,18 +151,9 @@ class LayerTimeFormatter {
|
|
|
151
151
|
}
|
|
152
152
|
return temporalFilter;
|
|
153
153
|
}
|
|
154
|
-
isValidDateString(dateString) {
|
|
155
|
-
return !Number.isNaN(Date.parse(dateString));
|
|
156
|
-
}
|
|
157
154
|
isWithinRange(date) {
|
|
158
155
|
return date >= this.minValue && date <= this.maxValue;
|
|
159
156
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Formats a given date into a date string of type 'YYYY-MM-DD'.
|
|
162
|
-
*/
|
|
163
|
-
static formatAsDate(date) {
|
|
164
|
-
return date.toISOString().split('T')[0];
|
|
165
|
-
}
|
|
166
157
|
static getMondayOfWeek(date) {
|
|
167
158
|
const monday = date.getUTCDate() - date.getUTCDay() + (date.getUTCDay() === 0 ? -6 : 1);
|
|
168
159
|
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), monday));
|
|
@@ -178,13 +169,13 @@ class LayerTimeFormatter {
|
|
|
178
169
|
static formatAsWeekRange(date) {
|
|
179
170
|
const startOfWeek = LayerTimeFormatter.getMondayOfWeek(date);
|
|
180
171
|
const endOfWeek = LayerTimeFormatter.getSundayOfWeek(date);
|
|
181
|
-
return `${
|
|
172
|
+
return `${DateUtils.formatAsDate(startOfWeek)}${TIME_RANGE_SEPARATOR}${DateUtils.formatAsDate(endOfWeek)}`;
|
|
182
173
|
}
|
|
183
174
|
/**
|
|
184
175
|
* Formats a given date into a date string of type 'YYYY-MM'.
|
|
185
176
|
*/
|
|
186
177
|
static formatAsMonth(date) {
|
|
187
|
-
return
|
|
178
|
+
return DateUtils.formatAsDate(date).slice(0, 7);
|
|
188
179
|
}
|
|
189
180
|
/**
|
|
190
181
|
* Formats a given date into a year string of type 'YYYY'.
|
|
@@ -202,7 +193,7 @@ class LayerTimeFormatter {
|
|
|
202
193
|
static queryStringFromSingleValueAndResolution(date, resolution) {
|
|
203
194
|
switch (resolution) {
|
|
204
195
|
case 'day':
|
|
205
|
-
return
|
|
196
|
+
return DateUtils.formatAsDate(date);
|
|
206
197
|
case 'week':
|
|
207
198
|
// This will return a range, even when in 'value' mode!
|
|
208
199
|
return LayerTimeFormatter.formatAsWeekRange(date);
|
|
@@ -226,9 +217,9 @@ class LayerTimeFormatter {
|
|
|
226
217
|
static queryStringFromDateRangeAnResolution(lowerLimit, upperLimit, resolution) {
|
|
227
218
|
switch (resolution) {
|
|
228
219
|
case 'day':
|
|
229
|
-
return `${
|
|
220
|
+
return `${DateUtils.formatAsDate(lowerLimit)}${TIME_RANGE_SEPARATOR}${DateUtils.formatAsDate(upperLimit)}`;
|
|
230
221
|
case 'week':
|
|
231
|
-
return `${
|
|
222
|
+
return `${DateUtils.formatAsDate(LayerTimeFormatter.getMondayOfWeek(lowerLimit))}${TIME_RANGE_SEPARATOR}${DateUtils.formatAsDate(LayerTimeFormatter.getSundayOfWeek(upperLimit))}`;
|
|
232
223
|
case 'month':
|
|
233
224
|
return `${LayerTimeFormatter.formatAsMonth(lowerLimit)}${TIME_RANGE_SEPARATOR}${LayerTimeFormatter.formatAsMonth(upperLimit)}`;
|
|
234
225
|
case 'year':
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type TimestampPrecision = 'minutes' | 'seconds' | 'milliseconds';
|
|
2
|
+
export default class DateUtils {
|
|
3
|
+
/**
|
|
4
|
+
* Validates if a string represents a valid date or datetime.
|
|
5
|
+
* The string can be formatted as an ISO / SQL timestamp or as a date string 'YYYY-MM-DD'.
|
|
6
|
+
*/
|
|
7
|
+
static normalizeDateTimeString(dateString: string | null | undefined): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Formats a given Date instance into a 'YYYY-MM-DD' date string.
|
|
10
|
+
*/
|
|
11
|
+
static formatAsDate(date: Date): string;
|
|
12
|
+
/**
|
|
13
|
+
* Converts an ISO / SQL timestamp, or a date string into a 'YYYY-MM-DD' date string.
|
|
14
|
+
*/
|
|
15
|
+
static dateTimeStringToDate(dateString: string | null | undefined): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a string is a timestamp with timezone information, e.g. `2026-10-29T15:30:00+02:00` or `2026-10-29T15:30:00Z`.
|
|
18
|
+
*/
|
|
19
|
+
static isTimeZoneAware(dateString: string | null | undefined): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Extract the timezone information from a timestamp.
|
|
22
|
+
*/
|
|
23
|
+
private static extractTimezone;
|
|
24
|
+
/**
|
|
25
|
+
* Converts an ISO or SQL timestamp string into a local date time value compatible with HTML datetime-local inputs.
|
|
26
|
+
* Strips trailing timezone indicators (e.g. 'Z', '+02:00').
|
|
27
|
+
*/
|
|
28
|
+
static fromApiToLocalDateTime(dateString: string | null | undefined, precision?: TimestampPrecision): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Converts a datetime-local input value into an API-ready ISO timestamp string.
|
|
31
|
+
* Checks the timezone format of the previous value to decide if a conversion to UTC time is necessary.
|
|
32
|
+
* For new values (no previous value), defaults to UTC time with timezone indicator 'Z'.
|
|
33
|
+
*/
|
|
34
|
+
static fromLocalToApiDateTime(localDateString: string | null | undefined, previousValue?: string): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* Removes the timezone information from the ISO timestamp string and optionally forces a precision.
|
|
37
|
+
*/
|
|
38
|
+
static formatLocalTimestampString(isoTimestamp: string, precision?: TimestampPrecision): string;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
const TIMEZONE_REGEX = /(Z|[+-]\d{2}(?::?\d{2})?)$/i;
|
|
3
|
+
export default class DateUtils {
|
|
4
|
+
/**
|
|
5
|
+
* Validates if a string represents a valid date or datetime.
|
|
6
|
+
* The string can be formatted as an ISO / SQL timestamp or as a date string 'YYYY-MM-DD'.
|
|
7
|
+
*/
|
|
8
|
+
static normalizeDateTimeString(dateString) {
|
|
9
|
+
if (!dateString || typeof dateString !== 'string' || dateString.trim() === '') {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const cleanedValue = dateString.trim().replace(' ', 'T');
|
|
13
|
+
return Number.isNaN(Date.parse(cleanedValue)) ? null : cleanedValue;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Formats a given Date instance into a 'YYYY-MM-DD' date string.
|
|
17
|
+
*/
|
|
18
|
+
static formatAsDate(date) {
|
|
19
|
+
return date.toISOString().split('T')[0];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Converts an ISO / SQL timestamp, or a date string into a 'YYYY-MM-DD' date string.
|
|
23
|
+
*/
|
|
24
|
+
static dateTimeStringToDate(dateString) {
|
|
25
|
+
const cleanValue = this.normalizeDateTimeString(dateString);
|
|
26
|
+
return cleanValue ? cleanValue.split('T')[0] : null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if a string is a timestamp with timezone information, e.g. `2026-10-29T15:30:00+02:00` or `2026-10-29T15:30:00Z`.
|
|
30
|
+
*/
|
|
31
|
+
static isTimeZoneAware(dateString) {
|
|
32
|
+
const cleanedValue = this.normalizeDateTimeString(dateString);
|
|
33
|
+
return cleanedValue ? !!this.extractTimezone(cleanedValue) : false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extract the timezone information from a timestamp.
|
|
37
|
+
*/
|
|
38
|
+
static extractTimezone(normalizedDateString) {
|
|
39
|
+
const timePart = normalizedDateString.split('T')[1] ?? null;
|
|
40
|
+
if (timePart) {
|
|
41
|
+
// Only analyse the second part of the timestamp
|
|
42
|
+
const match = timePart.match(TIMEZONE_REGEX);
|
|
43
|
+
return match?.length ? match[0] : null;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts an ISO or SQL timestamp string into a local date time value compatible with HTML datetime-local inputs.
|
|
49
|
+
* Strips trailing timezone indicators (e.g. 'Z', '+02:00').
|
|
50
|
+
*/
|
|
51
|
+
static fromApiToLocalDateTime(dateString, precision) {
|
|
52
|
+
const cleanValue = this.normalizeDateTimeString(dateString);
|
|
53
|
+
if (!cleanValue) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (this.isTimeZoneAware(cleanValue)) {
|
|
57
|
+
const date = new Date(cleanValue);
|
|
58
|
+
// Adjust time by local timezone offset (offset is in minutes; negative for timezones ahead of UTC)
|
|
59
|
+
const localTime = new Date(date.getTime() - date.getTimezoneOffset() * 60_000);
|
|
60
|
+
// Build a timestamp based on requested precision
|
|
61
|
+
return this.formatLocalTimestampString(localTime.toISOString(), precision);
|
|
62
|
+
}
|
|
63
|
+
// DateTime without time zone information - use as-is but format to fit precision demand
|
|
64
|
+
return this.formatLocalTimestampString(cleanValue, precision);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Converts a datetime-local input value into an API-ready ISO timestamp string.
|
|
68
|
+
* Checks the timezone format of the previous value to decide if a conversion to UTC time is necessary.
|
|
69
|
+
* For new values (no previous value), defaults to UTC time with timezone indicator 'Z'.
|
|
70
|
+
*/
|
|
71
|
+
static fromLocalToApiDateTime(localDateString, previousValue) {
|
|
72
|
+
const cleanValue = this.normalizeDateTimeString(localDateString);
|
|
73
|
+
if (!cleanValue) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const cleanPreviousValue = this.normalizeDateTimeString(previousValue);
|
|
77
|
+
if (!previousValue || this.isTimeZoneAware(cleanPreviousValue)) {
|
|
78
|
+
// Return a UTC timestamp
|
|
79
|
+
return new Date(cleanValue).toISOString();
|
|
80
|
+
}
|
|
81
|
+
// Return a naive datetime without timezone
|
|
82
|
+
return cleanValue;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Removes the timezone information from the ISO timestamp string and optionally forces a precision.
|
|
86
|
+
*/
|
|
87
|
+
static formatLocalTimestampString(isoTimestamp, precision) {
|
|
88
|
+
const timezone = this.extractTimezone(isoTimestamp) ?? '';
|
|
89
|
+
const timestampWithoutTimezone = isoTimestamp.replace(timezone, '');
|
|
90
|
+
const [datePart, timePart] = timestampWithoutTimezone.split('T');
|
|
91
|
+
if (!precision || !timePart) {
|
|
92
|
+
return timestampWithoutTimezone;
|
|
93
|
+
}
|
|
94
|
+
const timeParts = timePart.split(/[:.]/);
|
|
95
|
+
const hours = (timeParts[0] ?? '00').padStart(2, '0');
|
|
96
|
+
const minutes = (timeParts[1] ?? '00').padStart(2, '0');
|
|
97
|
+
const seconds = (timeParts[2] ?? '00').padStart(2, '0');
|
|
98
|
+
const rawMillis = timeParts[3] ?? '000';
|
|
99
|
+
const milliseconds = rawMillis.padEnd(3, '0').slice(0, 3);
|
|
100
|
+
switch (precision) {
|
|
101
|
+
case 'minutes':
|
|
102
|
+
return `${datePart}T${hours}:${minutes}`;
|
|
103
|
+
case 'seconds':
|
|
104
|
+
return `${datePart}T${hours}:${minutes}:${seconds}`;
|
|
105
|
+
case 'milliseconds':
|
|
106
|
+
return `${datePart}T${hours}:${minutes}:${seconds}.${milliseconds}`;
|
|
107
|
+
default:
|
|
108
|
+
return timestampWithoutTimezone;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|