ol-wfst 4.2.0 → 4.4.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 (87) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +72 -22
  3. package/dist/@enums.d.ts +17 -0
  4. package/dist/@enums.d.ts.map +1 -0
  5. package/dist/@types.d.ts +206 -0
  6. package/dist/@types.d.ts.map +1 -0
  7. package/dist/Geoserver.d.ts +275 -0
  8. package/dist/Geoserver.d.ts.map +1 -0
  9. package/dist/WfsLayer.d.ts +51 -0
  10. package/dist/WfsLayer.d.ts.map +1 -0
  11. package/dist/WmsLayer.d.ts +69 -0
  12. package/dist/WmsLayer.d.ts.map +1 -0
  13. package/dist/css/ol-wfst.bootstrap5.css +18 -18
  14. package/dist/css/ol-wfst.bootstrap5.min.css +1 -1
  15. package/dist/css/ol-wfst.css +26 -39
  16. package/dist/css/ol-wfst.min.css +1 -1
  17. package/dist/defaults.d.ts +4 -0
  18. package/dist/defaults.d.ts.map +1 -0
  19. package/dist/index-umd.d.ts +3 -0
  20. package/dist/index-umd.d.ts.map +1 -0
  21. package/dist/modules/EditControlChanges.d.ts +18 -0
  22. package/dist/modules/EditControlChanges.d.ts.map +1 -0
  23. package/dist/modules/EditFieldsModal.d.ts +19 -0
  24. package/dist/modules/EditFieldsModal.d.ts.map +1 -0
  25. package/dist/modules/EditOverlay.d.ts +8 -0
  26. package/dist/modules/EditOverlay.d.ts.map +1 -0
  27. package/dist/modules/LayersControl.d.ts +38 -0
  28. package/dist/modules/LayersControl.d.ts.map +1 -0
  29. package/dist/modules/Uploads.d.ts +50 -0
  30. package/dist/modules/Uploads.d.ts.map +1 -0
  31. package/dist/modules/base/BaseLayer.d.ts +62 -0
  32. package/dist/modules/base/BaseLayer.d.ts.map +1 -0
  33. package/dist/modules/base/WfsSource.d.ts +49 -0
  34. package/dist/modules/base/WfsSource.d.ts.map +1 -0
  35. package/dist/modules/base/WmsSource.d.ts +47 -0
  36. package/dist/modules/base/WmsSource.d.ts.map +1 -0
  37. package/dist/modules/editLayer.d.ts +4 -0
  38. package/dist/modules/editLayer.d.ts.map +1 -0
  39. package/dist/modules/errors.d.ts +12 -0
  40. package/dist/modules/errors.d.ts.map +1 -0
  41. package/dist/modules/helpers.d.ts +7 -0
  42. package/dist/modules/helpers.d.ts.map +1 -0
  43. package/dist/modules/i18n/en.d.ts +3 -0
  44. package/dist/modules/i18n/en.d.ts.map +1 -0
  45. package/dist/modules/i18n/es.d.ts +3 -0
  46. package/dist/modules/i18n/es.d.ts.map +1 -0
  47. package/dist/modules/i18n/index.d.ts +15 -0
  48. package/dist/modules/i18n/index.d.ts.map +1 -0
  49. package/dist/modules/i18n/zh.d.ts +3 -0
  50. package/dist/modules/i18n/zh.d.ts.map +1 -0
  51. package/dist/modules/loading.d.ts +3 -0
  52. package/dist/modules/loading.d.ts.map +1 -0
  53. package/dist/modules/state.d.ts +22 -0
  54. package/dist/modules/state.d.ts.map +1 -0
  55. package/dist/modules/styleFunction.d.ts +13 -0
  56. package/dist/modules/styleFunction.d.ts.map +1 -0
  57. package/dist/myPragma.d.ts +2 -0
  58. package/dist/myPragma.d.ts.map +1 -0
  59. package/dist/ol-wfst.d.ts +340 -0
  60. package/dist/ol-wfst.d.ts.map +1 -0
  61. package/dist/ol-wfst.js +99 -56
  62. package/dist/ol-wfst.js.map +1 -1
  63. package/dist/ol-wfst.min.js +3 -3
  64. package/dist/ol-wfst.min.js.map +1 -1
  65. package/lib/@types.d.ts +14 -9
  66. package/lib/@types.d.ts.map +1 -1
  67. package/lib/Geoserver.d.ts.map +1 -1
  68. package/lib/WfsLayer.d.ts +2 -4
  69. package/lib/WfsLayer.d.ts.map +1 -1
  70. package/lib/WmsLayer.d.ts +2 -2
  71. package/lib/WmsLayer.d.ts.map +1 -1
  72. package/lib/modules/EditFieldsModal.d.ts +2 -2
  73. package/lib/modules/EditFieldsModal.d.ts.map +1 -1
  74. package/lib/modules/LayersControl.d.ts +8 -4
  75. package/lib/modules/LayersControl.d.ts.map +1 -1
  76. package/lib/modules/base/WfsSource.d.ts +2 -1
  77. package/lib/modules/base/WfsSource.d.ts.map +1 -1
  78. package/lib/ol-wfst.d.ts +25 -22
  79. package/lib/ol-wfst.d.ts.map +1 -1
  80. package/lib/ol-wfst.js +99 -56
  81. package/lib/ol-wfst.js.map +1 -1
  82. package/lib/style/css/ol-gisify.css +26 -39
  83. package/lib/style/css/ol-wfst.bootstrap5.css +18 -18
  84. package/lib/style/scss/ol-wfst.scss +82 -58
  85. package/package.json +5 -5
  86. package/dist/tsconfig.tsbuildinfo +0 -1
  87. package/lib/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,340 @@
1
+ import Geometry from 'ol/geom/Geometry.js';
2
+ import Control from 'ol/control/Control.js';
3
+ import Draw from 'ol/interaction/Draw.js';
4
+ import Modify from 'ol/interaction/Modify.js';
5
+ import Select from 'ol/interaction/Select.js';
6
+ import Snap from 'ol/interaction/Snap.js';
7
+ import { EventsKey } from 'ol/events.js';
8
+ import Collection from 'ol/Collection.js';
9
+ import Feature from 'ol/Feature.js';
10
+ import Overlay from 'ol/Overlay.js';
11
+ import View from 'ol/View.js';
12
+ import Map from 'ol/Map.js';
13
+ import BaseEvent from 'ol/events/Event.js';
14
+ import { LoadingStrategy } from 'ol/source/Vector.js';
15
+ import { Options as VectorLayerOptions } from 'ol/layer/BaseVector.js';
16
+ import { CombinedOnSignature, EventTypes, OnSignature } from 'ol/Observable.js';
17
+ import { ObjectEvent } from 'ol/Object.js';
18
+ import { Types as ObjectEventTypes } from 'ol/ObjectEventType.js';
19
+ import WfsLayer from './WfsLayer';
20
+ import WmsLayer from './WmsLayer';
21
+ import LayersControl from './modules/LayersControl';
22
+ import Uploads from './modules/Uploads';
23
+ import { TransactionType } from './@enums';
24
+ import { I18n, IGeoserverDescribeFeatureType, IProperty, WfsGeoserverVendor, WmsGeoserverVendor } from './@types';
25
+ import EditControlChangesEl from './modules/EditControlChanges';
26
+ import { EditFieldsModal } from './modules/EditFieldsModal';
27
+ import Geoserver from './Geoserver';
28
+ import './assets/scss/-ol-wfst.bootstrap5.scss';
29
+ import './assets/scss/ol-wfst.scss';
30
+ /**
31
+ * Tiny WFS-T client to insert (drawing/uploading), modify and delete
32
+ * features on GeoServers using OpenLayers. Layers with these types
33
+ * of geometries are supported: "GeometryCollection" (in this case, you can
34
+ * choose the geometry type of each element to draw), "Point", "MultiPoint",
35
+ * "LineString", "MultiLineString", "Polygon" and "MultiPolygon".
36
+ *
37
+ * @constructor
38
+ * @fires modifystart
39
+ * @fires modifyend
40
+ * @fires drawstart
41
+ * @fires drawend
42
+ * @fires load
43
+ * @fires describeFeatureType
44
+ * @extends {ol/control/Control~Control}
45
+ * @param options Wfst options, see [Wfst Options](#options) for more details.
46
+ */
47
+ export default class Wfst extends Control {
48
+ protected _options: Options;
49
+ protected _i18n: I18n;
50
+ protected _map: Map;
51
+ protected _view: View;
52
+ protected _viewport: HTMLElement;
53
+ protected _initialized: boolean;
54
+ protected _layersControl: LayersControl;
55
+ protected _overlay: Overlay;
56
+ protected _interactionWfsSelect: Select;
57
+ protected _interactionSelectModify: Select;
58
+ protected _collectionModify: Collection<any>;
59
+ protected _interactionModify: Modify;
60
+ protected _interactionSnap: Snap;
61
+ protected _interactionDraw: Draw;
62
+ protected _keyClickWms: EventsKey | EventsKey[];
63
+ protected _keyRemove: EventsKey;
64
+ protected _keySelect: EventsKey;
65
+ protected _controlApplyDiscardChanges: EditControlChangesEl;
66
+ protected _controlWidgetToolsDiv: HTMLElement;
67
+ protected _selectDraw: HTMLSelectElement;
68
+ protected _currentZoom: number;
69
+ protected _lastZoom: number;
70
+ protected _editFeature: Feature<Geometry>;
71
+ protected _editFeatureOriginal: Feature<Geometry>;
72
+ protected _uploads: Uploads;
73
+ protected _editFields: EditFieldsModal;
74
+ on: OnSignature<EventTypes, BaseEvent, EventsKey> & OnSignature<WfstEventTypes, WfstEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, EventsKey> & CombinedOnSignature<WfstEventTypes | ObjectEventTypes | EventTypes, EventsKey>;
75
+ once: OnSignature<EventTypes, BaseEvent, EventsKey> & OnSignature<WfstEventTypes, WfstEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, EventsKey> & CombinedOnSignature<WfstEventTypes | ObjectEventTypes | EventTypes, EventsKey>;
76
+ un: OnSignature<EventTypes, BaseEvent, void> & OnSignature<WfstEventTypes, WfstEvent, EventsKey> & OnSignature<ObjectEventTypes, ObjectEvent, void> & CombinedOnSignature<WfstEventTypes | ObjectEventTypes | EventTypes, void>;
77
+ constructor(options?: Options);
78
+ /**
79
+ * Get all the layers in the ol-wfst instance
80
+ * @public
81
+ */
82
+ getLayers(): Array<WfsLayer | WmsLayer>;
83
+ /**
84
+ * Get a layer
85
+ * @public
86
+ */
87
+ getLayerByName(layerName?: string): WfsLayer | WmsLayer;
88
+ /**
89
+ * Connect to the GeoServer and retrieve metadata about the service (GetCapabilities).
90
+ * Get each layer specs (DescribeFeatureType) and create the layers and map controls.
91
+ * @fires describeFeatureType
92
+ * @private
93
+ */
94
+ private _initMapAndLayers;
95
+ /**
96
+ * @private
97
+ */
98
+ private _init;
99
+ /**
100
+ * Create the edit layer to allow modify elements, add interactions,
101
+ * map controls and keyboard handlers.
102
+ *
103
+ * @param showControl
104
+ * @param active
105
+ * @private
106
+ */
107
+ private _createMapElements;
108
+ /**
109
+ * @private
110
+ */
111
+ private _addInteractions;
112
+ /**
113
+ * Layer to store temporary the elements to be edited
114
+ * @private
115
+ */
116
+ private _prepareEditLayer;
117
+ /**
118
+ * @private
119
+ */
120
+ private _addMapEvents;
121
+ /**
122
+ * Add map handlers
123
+ * @private
124
+ */
125
+ private _addInteractionHandlers;
126
+ /**
127
+ * Add the widget on the map to allow change the tools and select active layers
128
+ * @private
129
+ */
130
+ private _addMapControl;
131
+ /**
132
+ *
133
+ * @param feature
134
+ * @private
135
+ */
136
+ private _deselectEditFeature;
137
+ /**
138
+ *
139
+ * @param feature
140
+ * @param layerName
141
+ * @private
142
+ */
143
+ private _restoreFeatureToLayer;
144
+ /**
145
+ * @param feature
146
+ * @private
147
+ */
148
+ private _removeFeatureFromTmpLayer;
149
+ /**
150
+ * Trigger on deselecting a feature from in the Edit layer
151
+ *
152
+ * @private
153
+ */
154
+ private _onDeselectFeatureEvent;
155
+ /**
156
+ * Trigger on removing a feature from the Edit layer
157
+ *
158
+ * @private
159
+ */
160
+ private _onRemoveFeatureEvent;
161
+ /**
162
+ *
163
+ * @param feature
164
+ * @private
165
+ */
166
+ private _editModeOn;
167
+ /**
168
+ * @private
169
+ */
170
+ private _editModeOff;
171
+ /**
172
+ * Remove a feature from the edit Layer and from the Geoserver
173
+ *
174
+ * @param feature
175
+ * @private
176
+ */
177
+ private _deleteFeature;
178
+ /**
179
+ * Add a feature to the Edit Layer to allow editing, and creates an Overlay Helper to show options
180
+ *
181
+ * @param feature
182
+ * @param coordinate
183
+ * @param layerName
184
+ * @private
185
+ */
186
+ private _addFeatureToEditMode;
187
+ /**
188
+ * Activate/deactivate the draw mode
189
+ *
190
+ * @param layer
191
+ * @public
192
+ */
193
+ activateDrawMode(layer: WfsLayer | WmsLayer | false): void;
194
+ /**
195
+ * Activate/desactivate the edit mode
196
+ *
197
+ * @param bool
198
+ * @public
199
+ */
200
+ activateEditMode(bool?: boolean): void;
201
+ /**
202
+ * Remove the overlay helper atttached to a specify feature
203
+ * @param feature
204
+ * @private
205
+ */
206
+ private _removeOverlayHelper;
207
+ }
208
+ /**
209
+ * **_[interface]_** - Wfst Options specified when creating a Wfst instance
210
+ *
211
+ * Default values:
212
+ * ```javascript
213
+ * {
214
+ * layers: null,
215
+ * evtType: 'singleclick',
216
+ * active: true,
217
+ * showControl: true,
218
+ * language: 'en',
219
+ * i18n: {...}, // according to language selection
220
+ * uploadFormats: '.geojson,.json,.kml',
221
+ * processUpload: null,
222
+ * }
223
+ * ```
224
+ */
225
+ interface Options {
226
+ /**
227
+ * Layers to be loaded from the geoserver
228
+ */
229
+ layers?: Array<WfsLayer | WmsLayer>;
230
+ /**
231
+ * Init active
232
+ */
233
+ active?: boolean;
234
+ /**
235
+ * The click event to allow selection of Features to be edited
236
+ */
237
+ evtType?: 'singleclick' | 'dblclick';
238
+ /**
239
+ * Show/hide the control map
240
+ */
241
+ showControl?: boolean;
242
+ /**
243
+ * Modal configuration
244
+ */
245
+ modal?: {
246
+ animateClass?: string;
247
+ animateInClass?: string;
248
+ transition?: number;
249
+ backdropTransition?: number;
250
+ templates?: {
251
+ dialog?: string | HTMLElement;
252
+ headerClose?: string | HTMLElement;
253
+ };
254
+ };
255
+ /**
256
+ * Language to be used
257
+ */
258
+ language?: 'es' | 'en' | 'zh';
259
+ /**
260
+ * Custom translations
261
+ */
262
+ i18n?: I18n;
263
+ /**
264
+ * Show/hide the upload button
265
+ */
266
+ showUpload?: boolean;
267
+ /**
268
+ * Accepted extension formats on upload
269
+ * Example: ".json,.geojson"
270
+ */
271
+ uploadFormats?: string;
272
+ /**
273
+ * Triggered to allow implement custom functions or to parse other formats than default
274
+ * by filtering the extension. If this doesn't return features, the default function
275
+ * will be used to extract them.
276
+ */
277
+ processUpload?(file: File): Array<Feature<Geometry>>;
278
+ }
279
+ /**
280
+ * **_[interface]_** - Parameters to create the layers and connect to the GeoServer
281
+ *
282
+ * You can use all the parameters supported by OpenLayers
283
+ *
284
+ * Default values:
285
+ * ```javascript
286
+ * {
287
+ * name: null,
288
+ * geoserver: null,
289
+ * label: null, // `name` if not provided
290
+ * strategy: all,
291
+ * geoserverVendor: null
292
+ * }
293
+ * ```
294
+ */
295
+ interface LayerOptions extends Omit<VectorLayerOptions<any>, 'source'> {
296
+ /**
297
+ * Layer name in the GeoServer
298
+ */
299
+ name: string;
300
+ /**
301
+ * Geoserver Object
302
+ */
303
+ geoserver: Geoserver;
304
+ /**
305
+ * Label to be displayed in the widget control
306
+ */
307
+ label?: string;
308
+ /**
309
+ * Available geoserver options
310
+ */
311
+ geoserverVendor?: WfsGeoserverVendor | WmsGeoserverVendor;
312
+ /**
313
+ * Strategy function for loading features.
314
+ * Only for WFS
315
+ * By default `all` strategy is used
316
+ */
317
+ strategy?: LoadingStrategy;
318
+ /**
319
+ * Triggered before inserting new features to the Geoserver.
320
+ * Use this to insert custom properties, modify the feature, etc.
321
+ */
322
+ beforeTransactFeature?(feature: Feature<Geometry>, transaction: TransactionType): Feature<Geometry>;
323
+ /**
324
+ * Hook to customize the html elements showed in the fields modal
325
+ * Return `null` to hide the field from the modal
326
+ */
327
+ beforeShowFieldsModal?: (field: IProperty, value: string, formElement: HTMLElement) => HTMLElement | string | null;
328
+ }
329
+ declare class WfstEvent extends BaseEvent {
330
+ data: IGeoserverDescribeFeatureType;
331
+ layer: WfsLayer | WmsLayer;
332
+ constructor(options: {
333
+ type: WfstEventTypes;
334
+ layer: WfsLayer | WmsLayer;
335
+ data: IGeoserverDescribeFeatureType;
336
+ });
337
+ }
338
+ type WfstEventTypes = 'describeFeatureType';
339
+ export { Options, WfstEventTypes, WfstEvent, I18n, LayerOptions, Geoserver, WmsLayer, WfsLayer };
340
+ //# sourceMappingURL=ol-wfst.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ol-wfst.d.ts","sourceRoot":"","sources":["../src/ol-wfst.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAK3C,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAC9C,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAC9C,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,OAAO,MAAM,eAAe,CAAC;AACpC,OAAO,OAAO,MAAM,eAAe,CAAC;AACpC,OAAO,IAAI,MAAM,YAAY,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: Sat Sep 30 2023 12:32:13 GMT-0300 (Argentina Standard Time)
4
+ * Built: Sun May 05 2024 21:48:51 GMT-0300 (Argentina Standard Time)
5
5
  */
6
6
  (function (global, factory) {
7
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('ol/style/Circle.js'), require('ol/style/Fill.js'), require('ol/style/Stroke.js'), require('ol/style/Style.js'), require('ol/control/Control.js'), require('ol/interaction/Draw.js'), require('ol/interaction/Modify.js'), require('ol/interaction/Select.js'), require('ol/interaction/Snap.js'), require('ol/Collection.js'), require('ol/events/Event.js'), require('ol/events/condition.js'), require('ol/Observable.js'), require('ol/layer/Vector.js'), require('ol/layer/Base.js'), require('ol/format/GeoJSON.js'), require('ol/source/Vector.js'), require('ol/proj.js'), require('ol/loadingstrategy.js'), require('ol/layer/Tile.js'), require('ol/source/TileWMS.js'), require('ol/geom.js'), require('ol/format/KML.js'), require('ol/format/WFS.js'), require('ol/style.js'), require('ol/Object.js'), require('ol/geom/Circle.js'), require('ol/geom/GeometryCollection.js'), require('ol/Feature.js'), require('ol/geom/Polygon.js'), require('ol/format/XML.js'), require('ol/xml.js'), require('ol/format/xlink.js'), require('ol/format/xsd.js'), require('ol/extent.js'), require('ol/Overlay.js')) :
@@ -1904,6 +1904,9 @@
1904
1904
  if (options.beforeTransactFeature) {
1905
1905
  this.beforeTransactFeature = options.beforeTransactFeature;
1906
1906
  }
1907
+ if (options.beforeShowFieldsModal) {
1908
+ this.beforeShowFieldsModal = options.beforeShowFieldsModal;
1909
+ }
1907
1910
  this._formatGeoJSON = new GeoJSON();
1908
1911
  const geoserver = options.geoserver;
1909
1912
  const source = new WmsSource({
@@ -1971,6 +1974,9 @@
1971
1974
  const data = await response.json();
1972
1975
  let features = this._parseFeaturesFromResponse(data);
1973
1976
  const featuresId = features.map((f) => f.getId());
1977
+ if (!featuresId.length) {
1978
+ return;
1979
+ }
1974
1980
  const fullResList = await this._getFullResGeometryById(featuresId);
1975
1981
  if (fullResList) {
1976
1982
  features = fullResList;
@@ -2194,17 +2200,21 @@
2194
2200
  layer.setVisible(false);
2195
2201
  }
2196
2202
  }
2203
+ /**
2204
+ * Called when a layer is selected in the widget
2205
+ * @param evt
2206
+ * @param layer
2207
+ */
2197
2208
  _layerChangeHandler(evt, layer) {
2198
- const radioInput = evt.currentTarget;
2199
- const parentDiv = radioInput.closest('.wfst--layer-control');
2200
- // Deselect DOM previous layer
2201
2209
  const selected = document.querySelector('.ol-wfst--selected-on');
2202
- if (selected)
2203
- selected.classList.remove('ol-wfst--selected-on');
2210
+ const parentDiv = evt.currentTarget.closest('.wfst--layer-control');
2211
+ // Deselect DOM previous layer
2212
+ selected.classList.remove('ol-wfst--selected-on');
2204
2213
  // Select this layer
2205
2214
  parentDiv.classList.add('ol-wfst--selected-on');
2206
2215
  setActiveLayerToInsertEls(layer);
2207
2216
  this._changeStateSelect(layer);
2217
+ this.dispatchEvent('changeLayer');
2208
2218
  }
2209
2219
  render() {
2210
2220
  return (createElement(null, null,
@@ -2663,23 +2673,37 @@
2663
2673
  constructor(options) {
2664
2674
  super();
2665
2675
  this._options = options;
2666
- const footer = `
2667
- <button type="button" class="btn btn-sm btn-link btn-third" data-action="delete" data-dismiss="modal">
2668
- ${I18N.labels.delete}
2669
- </button>
2670
- <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">
2671
- ${I18N.labels.cancel}
2672
- </button>
2673
- <button type="button" class="btn btn-sm btn-primary" data-action="save" data-dismiss="modal">
2674
- ${I18N.labels.save}
2675
- </button>
2676
- `;
2677
- this._modal = new Modal(Object.assign(Object.assign({}, this._options), { header: true, headerClose: true, title: '', content: '<div></div>', footer: footer }));
2676
+ this._modal = new Modal(Object.assign(Object.assign({}, this._options.modal), { header: true, headerClose: true, title: '', content: createElement("div", null), footer: `
2677
+ <button
2678
+ type="button"
2679
+ class="btn btn-sm btn-link btn-third"
2680
+ data-action="delete"
2681
+ data-dismiss="modal"
2682
+ >
2683
+ ${I18N.labels.delete}
2684
+ </button>
2685
+ <button
2686
+ type="button"
2687
+ class="btn btn-sm btn-secondary"
2688
+ data-dismiss="modal"
2689
+ >
2690
+ ${I18N.labels.cancel}
2691
+ </button>
2692
+ <button
2693
+ type="button"
2694
+ class="btn btn-sm btn-primary"
2695
+ data-action="save"
2696
+ data-dismiss="modal"
2697
+ >
2698
+ ${I18N.labels.save}
2699
+ </button>
2700
+ ` }));
2678
2701
  this._modal.on('dismiss', (modal, event) => {
2679
2702
  // On saving changes
2680
2703
  if (event.target.dataset.action === 'save') {
2681
- const inputs = modal.el.querySelectorAll('input');
2682
- inputs.forEach((el) => {
2704
+ const formElements = modal.el.querySelector('form')
2705
+ .elements;
2706
+ Array.from(formElements).forEach((el) => {
2683
2707
  const value = el.value;
2684
2708
  const field = el.name;
2685
2709
  this._feature.set(field, value, /*isSilent = */ true);
@@ -2695,45 +2719,55 @@
2695
2719
  }
2696
2720
  show(feature) {
2697
2721
  this._feature = feature;
2698
- const title = `${I18N.labels.editElement} ${feature.getId()} `;
2699
- const properties = feature.getProperties();
2722
+ const modalTitle = `${I18N.labels.editElement} ${feature.getId()} `;
2723
+ const featProperties = feature.getProperties();
2700
2724
  const layerName = feature.get('_layerName_');
2701
2725
  // Data schema from the geoserver
2702
2726
  const layer = getStoredLayer(layerName);
2703
2727
  const dataSchema = layer.getDescribeFeatureType()._parsed.properties;
2704
- let content = '<form autocomplete="false">';
2705
- Object.keys(properties).forEach((key) => {
2728
+ this._modal._html.body.innerHTML = '';
2729
+ this._modal._html.body.append(createElement("form", { autocomplete: "false" }, Object.keys(featProperties).flatMap((key) => {
2706
2730
  // If the feature field exists in the geoserver and is not added by openlayers
2707
2731
  const field = dataSchema.find((data) => data.name === key);
2708
- if (field) {
2709
- const typeXsd = field.type;
2710
- let type;
2711
- switch (typeXsd) {
2712
- case 'xsd:string':
2713
- type = 'text';
2714
- break;
2715
- case 'xsd:number':
2716
- case 'xsd:int':
2717
- type = 'number';
2718
- break;
2719
- case 'xsd:date-time':
2720
- type = 'datetime';
2721
- break;
2722
- default:
2723
- type = 'text';
2732
+ if (!field)
2733
+ return [];
2734
+ const typeXsd = field.type;
2735
+ const value = featProperties[key];
2736
+ let type;
2737
+ switch (typeXsd) {
2738
+ case 'xsd:double':
2739
+ case 'xsd:number':
2740
+ case 'xsd:int':
2741
+ type = 'number';
2742
+ break;
2743
+ case 'xsd:date':
2744
+ type = 'date';
2745
+ break;
2746
+ case 'xsd:date-time':
2747
+ type = 'datetime';
2748
+ break;
2749
+ case 'xsd:string':
2750
+ default:
2751
+ type = 'text';
2752
+ }
2753
+ let input = (createElement("input", { placeholder: "NULL", className: "ol-wfst--input-field-input", type: type, name: key, value: value || null }));
2754
+ if (layer.beforeShowFieldsModal) {
2755
+ const hookInput = layer.beforeShowFieldsModal(field, value, input);
2756
+ if (!hookInput) {
2757
+ return [];
2758
+ }
2759
+ if (typeof hookInput === 'string') {
2760
+ input = new DOMParser().parseFromString(hookInput, 'text/html').body.childNodes[0];
2724
2761
  }
2725
- if (type) {
2726
- content += `
2727
- <div class="ol-wfst--input-field-container">
2728
- <label class="ol-wfst--input-field-label" for="${key}">${key}</label>
2729
- <input placeholder="NULL" class="ol-wfst--input-field-input" type="${type}" name="${key}" value="${properties[key] || ''}">
2730
- </div>`;
2762
+ else {
2763
+ input = hookInput;
2731
2764
  }
2732
2765
  }
2733
- });
2734
- content += '</form>';
2735
- this._modal._html.body.innerHTML = content;
2736
- this._modal._html.header.innerHTML = title;
2766
+ return (createElement("div", { className: "ol-wfst--input-field-container" },
2767
+ createElement("label", { className: "ol-wfst--input-field-label", htmlFor: key }, key),
2768
+ input));
2769
+ })));
2770
+ this._modal._html.header.innerHTML = modalTitle;
2737
2771
  this._modal.show();
2738
2772
  }
2739
2773
  }
@@ -3871,9 +3905,12 @@
3871
3905
  throw new Error(`${I18N.errors.layerNotFound}: "${layerName}"`);
3872
3906
  }
3873
3907
  const describeFeatureType = geoLayer.getDescribeFeatureType()._parsed;
3908
+ const layerNameClean = layerName.split(':').length > 1
3909
+ ? layerName.split(':').pop()
3910
+ : layerName;
3874
3911
  const options = {
3875
3912
  featureNS: describeFeatureType.namespace,
3876
- featureType: layerName,
3913
+ featureType: layerNameClean,
3877
3914
  srsName: srs,
3878
3915
  featurePrefix: null,
3879
3916
  nativeElements: null,
@@ -3901,7 +3938,7 @@
3901
3938
  if (transactionType === TransactionType.Insert) {
3902
3939
  payload = payload.replace(/<(\/?)\bgeometry\b>/g, `<$1${geomField}>`);
3903
3940
  }
3904
- else {
3941
+ else if (transactionType === TransactionType.Update) {
3905
3942
  payload = payload.replace(/<Name>geometry<\/Name>/g, `<Name>${geomField}</Name>`);
3906
3943
  }
3907
3944
  // This has to be te same used before
@@ -4118,7 +4155,7 @@
4118
4155
 
4119
4156
  const controlElement = document.createElement('div');
4120
4157
  /**
4121
- * Tiny WFST-T client to insert (drawing/uploading), modify and delete
4158
+ * Tiny WFS-T client to insert (drawing/uploading), modify and delete
4122
4159
  * features on GeoServers using OpenLayers. Layers with these types
4123
4160
  * of geometries are supported: "GeometryCollection" (in this case, you can
4124
4161
  * choose the geometry type of each element to draw), "Point", "MultiPoint",
@@ -4153,7 +4190,7 @@
4153
4190
  this._controlWidgetToolsDiv = controlElement;
4154
4191
  this._controlWidgetToolsDiv.className = 'ol-wfst--tools-control';
4155
4192
  this._uploads = new Uploads(this._options);
4156
- this._editFields = new EditFieldsModal(this._options.modal);
4193
+ this._editFields = new EditFieldsModal(this._options);
4157
4194
  }
4158
4195
  /**
4159
4196
  * Get all the layers in the ol-wfst instance
@@ -4260,7 +4297,7 @@
4260
4297
  this._collectionModify.remove(feature);
4261
4298
  });
4262
4299
  // @ts-expect-error
4263
- this._editFields.dispose('delete', ({ feature }) => {
4300
+ this._editFields.on('delete', ({ feature }) => {
4264
4301
  this._deleteFeature(feature, true);
4265
4302
  });
4266
4303
  this._addMapEvents();
@@ -4508,6 +4545,12 @@
4508
4545
  this.activateDrawMode(getActiveLayerToInsertEls());
4509
4546
  }
4510
4547
  });
4548
+ // @ts-expect-error
4549
+ this._layersControl.on('changeLayer', () => {
4550
+ if (getMode() === Modes.Draw) {
4551
+ this.activateDrawMode(getActiveLayerToInsertEls());
4552
+ }
4553
+ });
4511
4554
  const controlEl = this._layersControl.render();
4512
4555
  this._selectDraw = controlEl.querySelector('.wfst--tools-control--select-draw');
4513
4556
  this._controlWidgetToolsDiv.append(controlEl);