ol-wfst 3.0.4 → 4.0.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 (140) hide show
  1. package/CHANGELOG.md +88 -67
  2. package/LICENSE.md +21 -0
  3. package/README.md +548 -173
  4. package/dist/@enums.d.ts +5 -0
  5. package/dist/@enums.d.ts.map +1 -1
  6. package/dist/@types.d.ts +163 -0
  7. package/dist/@types.d.ts.map +1 -0
  8. package/dist/Geoserver.d.ts +260 -0
  9. package/dist/Geoserver.d.ts.map +1 -0
  10. package/dist/WfsLayer.d.ts +40 -0
  11. package/dist/WfsLayer.d.ts.map +1 -0
  12. package/dist/WmsLayer.d.ts +48 -0
  13. package/dist/WmsLayer.d.ts.map +1 -0
  14. package/dist/css/ol-wfst.bootstrap5.css +364 -481
  15. package/dist/css/ol-wfst.bootstrap5.min.css +1 -1
  16. package/dist/css/ol-wfst.css +22 -18
  17. package/dist/css/ol-wfst.min.css +1 -1
  18. package/dist/defaults.d.ts +4 -0
  19. package/dist/defaults.d.ts.map +1 -0
  20. package/dist/modules/EditControlChanges.d.ts +18 -0
  21. package/dist/modules/EditControlChanges.d.ts.map +1 -0
  22. package/dist/modules/EditFieldsModal.d.ts +18 -0
  23. package/dist/modules/EditFieldsModal.d.ts.map +1 -0
  24. package/dist/modules/EditOverlay.d.ts +7 -0
  25. package/dist/modules/EditOverlay.d.ts.map +1 -0
  26. package/dist/modules/LayersControl.d.ts +35 -0
  27. package/dist/modules/LayersControl.d.ts.map +1 -0
  28. package/dist/modules/Modes/WfsSource.d.ts +60 -0
  29. package/dist/modules/Modes/WfsSource.d.ts.map +1 -0
  30. package/dist/modules/Modes/WmsSource.d.ts +82 -0
  31. package/dist/modules/Modes/WmsSource.d.ts.map +1 -0
  32. package/dist/modules/Modes/baseLayer.d.ts +62 -0
  33. package/dist/modules/Modes/baseLayer.d.ts.map +1 -0
  34. package/dist/modules/Modes/baseSource.d.ts +103 -0
  35. package/dist/modules/Modes/baseSource.d.ts.map +1 -0
  36. package/dist/modules/Uploads.d.ts +47 -0
  37. package/dist/modules/Uploads.d.ts.map +1 -0
  38. package/dist/modules/editLayer.d.ts +4 -0
  39. package/dist/modules/editLayer.d.ts.map +1 -0
  40. package/dist/modules/errors.d.ts +11 -0
  41. package/dist/modules/errors.d.ts.map +1 -0
  42. package/dist/modules/helpers.d.ts +7 -0
  43. package/dist/modules/helpers.d.ts.map +1 -0
  44. package/dist/{assets → modules}/i18n/en.d.ts +0 -0
  45. package/dist/modules/i18n/en.d.ts.map +1 -0
  46. package/dist/{assets → modules}/i18n/es.d.ts +0 -0
  47. package/dist/modules/i18n/es.d.ts.map +1 -0
  48. package/dist/modules/i18n/index.d.ts +15 -0
  49. package/dist/modules/i18n/index.d.ts.map +1 -0
  50. package/dist/{assets → modules}/i18n/zh.d.ts +0 -0
  51. package/dist/modules/i18n/zh.d.ts.map +1 -0
  52. package/dist/modules/loading.d.ts +3 -0
  53. package/dist/modules/loading.d.ts.map +1 -0
  54. package/dist/modules/state.d.ts +22 -0
  55. package/dist/modules/state.d.ts.map +1 -0
  56. package/dist/modules/styleFunction.d.ts +13 -0
  57. package/dist/modules/styleFunction.d.ts.map +1 -0
  58. package/dist/myPragma.d.ts +2 -0
  59. package/dist/myPragma.d.ts.map +1 -0
  60. package/dist/ol-wfst.d.ts +89 -315
  61. package/dist/ol-wfst.d.ts.map +1 -1
  62. package/dist/ol-wfst.js +6368 -5113
  63. package/dist/ol-wfst.js.map +1 -1
  64. package/dist/ol-wfst.min.js +1 -15
  65. package/dist/ol-wfst.min.js.map +1 -1
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/lib/@enums.d.ts +5 -0
  68. package/lib/@enums.d.ts.map +1 -1
  69. package/lib/@types.d.ts +163 -0
  70. package/lib/@types.d.ts.map +1 -0
  71. package/lib/Geoserver.d.ts +260 -0
  72. package/lib/Geoserver.d.ts.map +1 -0
  73. package/lib/WfsLayer.d.ts +40 -0
  74. package/lib/WfsLayer.d.ts.map +1 -0
  75. package/lib/WmsLayer.d.ts +48 -0
  76. package/lib/WmsLayer.d.ts.map +1 -0
  77. package/lib/defaults.d.ts +4 -0
  78. package/lib/defaults.d.ts.map +1 -0
  79. package/lib/index-es.js +3008 -0
  80. package/lib/index-es.js.map +1 -0
  81. package/lib/modules/EditControlChanges.d.ts +18 -0
  82. package/lib/modules/EditControlChanges.d.ts.map +1 -0
  83. package/lib/modules/EditFieldsModal.d.ts +18 -0
  84. package/lib/modules/EditFieldsModal.d.ts.map +1 -0
  85. package/lib/modules/EditOverlay.d.ts +7 -0
  86. package/lib/modules/EditOverlay.d.ts.map +1 -0
  87. package/lib/modules/LayersControl.d.ts +35 -0
  88. package/lib/modules/LayersControl.d.ts.map +1 -0
  89. package/lib/modules/Modes/WfsSource.d.ts +60 -0
  90. package/lib/modules/Modes/WfsSource.d.ts.map +1 -0
  91. package/lib/modules/Modes/WmsSource.d.ts +82 -0
  92. package/lib/modules/Modes/WmsSource.d.ts.map +1 -0
  93. package/lib/modules/Modes/baseLayer.d.ts +62 -0
  94. package/lib/modules/Modes/baseLayer.d.ts.map +1 -0
  95. package/lib/modules/Modes/baseSource.d.ts +103 -0
  96. package/lib/modules/Modes/baseSource.d.ts.map +1 -0
  97. package/lib/modules/Uploads.d.ts +47 -0
  98. package/lib/modules/Uploads.d.ts.map +1 -0
  99. package/lib/modules/editLayer.d.ts +4 -0
  100. package/lib/modules/editLayer.d.ts.map +1 -0
  101. package/lib/modules/errors.d.ts +11 -0
  102. package/lib/modules/errors.d.ts.map +1 -0
  103. package/lib/modules/helpers.d.ts +7 -0
  104. package/lib/modules/helpers.d.ts.map +1 -0
  105. package/lib/{assets → modules}/i18n/en.d.ts +0 -0
  106. package/lib/modules/i18n/en.d.ts.map +1 -0
  107. package/lib/{assets → modules}/i18n/es.d.ts +0 -0
  108. package/lib/modules/i18n/es.d.ts.map +1 -0
  109. package/lib/modules/i18n/index.d.ts +15 -0
  110. package/lib/modules/i18n/index.d.ts.map +1 -0
  111. package/lib/{assets → modules}/i18n/zh.d.ts +0 -0
  112. package/lib/modules/i18n/zh.d.ts.map +1 -0
  113. package/lib/modules/loading.d.ts +3 -0
  114. package/lib/modules/loading.d.ts.map +1 -0
  115. package/lib/modules/state.d.ts +22 -0
  116. package/lib/modules/state.d.ts.map +1 -0
  117. package/lib/modules/styleFunction.d.ts +13 -0
  118. package/lib/modules/styleFunction.d.ts.map +1 -0
  119. package/lib/myPragma.d.ts +2 -0
  120. package/lib/myPragma.d.ts.map +1 -0
  121. package/lib/ol-wfst.d.ts +89 -315
  122. package/lib/ol-wfst.d.ts.map +1 -1
  123. package/lib/style/css/ol-gisify.css +22 -18
  124. package/lib/style/css/ol-wfst.bootstrap5.css +364 -481
  125. package/lib/style/scss/_variables.scss +17 -0
  126. package/lib/style/scss/ol-wfst.scss +31 -28
  127. package/lib/tsconfig.tsbuildinfo +1 -1
  128. package/package.json +71 -70
  129. package/dist/assets/i18n/en.d.ts.map +0 -1
  130. package/dist/assets/i18n/es.d.ts.map +0 -1
  131. package/dist/assets/i18n/index.d.ts +0 -4
  132. package/dist/assets/i18n/index.d.ts.map +0 -1
  133. package/dist/assets/i18n/zh.d.ts.map +0 -1
  134. package/lib/assets/i18n/en.d.ts.map +0 -1
  135. package/lib/assets/i18n/es.d.ts.map +0 -1
  136. package/lib/assets/i18n/index.d.ts +0 -4
  137. package/lib/assets/i18n/index.d.ts.map +0 -1
  138. package/lib/assets/i18n/zh.d.ts.map +0 -1
  139. package/lib/ol-wfst.js +0 -2259
  140. package/lib/ol-wfst.js.map +0 -1
package/lib/ol-wfst.js DELETED
@@ -1,2259 +0,0 @@
1
- import TileState from 'ol/TileState';
2
- import { GeometryCollection, Circle as Circle$1, Polygon, MultiLineString, MultiPolygon, MultiPoint } from 'ol/geom';
3
- import { Style, Circle, Fill, Stroke } from 'ol/style';
4
- import { Control } from 'ol/control';
5
- import { Modify, Snap, Select, Draw } from 'ol/interaction';
6
- import { Collection, Feature, Overlay } from 'ol';
7
- import { WFS, GeoJSON, KML } from 'ol/format';
8
- import { Vector, Tile } from 'ol/layer';
9
- import { Vector as Vector$1, TileWMS } from 'ol/source';
10
- import { bbox, all } from 'ol/loadingstrategy';
11
- import { fromCircle } from 'ol/geom/Polygon';
12
- import { getCenter } from 'ol/extent';
13
- import { primaryAction, never } from 'ol/events/condition';
14
- import { transformExtent } from 'ol/proj';
15
- import { unByKey } from 'ol/Observable';
16
- import Modal from 'modal-vanilla';
17
-
18
- /*! *****************************************************************************
19
- Copyright (c) Microsoft Corporation.
20
-
21
- Permission to use, copy, modify, and/or distribute this software for any
22
- purpose with or without fee is hereby granted.
23
-
24
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
25
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
26
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
27
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
28
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
29
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
30
- PERFORMANCE OF THIS SOFTWARE.
31
- ***************************************************************************** */
32
-
33
- function __awaiter(thisArg, _arguments, P, generator) {
34
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
- return new (P || (P = Promise))(function (resolve, reject) {
36
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
37
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
38
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
39
- step((generator = generator.apply(thisArg, _arguments || [])).next());
40
- });
41
- }
42
-
43
- var img = "data:image/svg+xml,%3csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='768' height='768' viewBox='0 0 768 768'%3e %3cpath d='M663 225l-58.5 58.5-120-120 58.5-58.5q9-9 22.5-9t22.5 9l75 75q9 9 9 22.5t-9 22.5zM96 552l354-354 120 120-354 354h-120v-120z'%3e%3c/path%3e%3c/svg%3e";
44
-
45
- var img$1 = "data:image/svg+xml,%3csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='448' height='448' viewBox='0 0 448 448'%3e %3cpath d='M222 296l29-29-38-38-29 29v14h24v24h14zM332 116c-2.25-2.25-6-2-8.25 0.25l-87.5 87.5c-2.25 2.25-2.5 6-0.25 8.25s6 2 8.25-0.25l87.5-87.5c2.25-2.25 2.5-6 0.25-8.25zM352 264.5v47.5c0 39.75-32.25 72-72 72h-208c-39.75 0-72-32.25-72-72v-208c0-39.75 32.25-72 72-72h208c10 0 20 2 29.25 6.25 2.25 1 4 3.25 4.5 5.75 0.5 2.75-0.25 5.25-2.25 7.25l-12.25 12.25c-2.25 2.25-5.25 3-8 2-3.75-1-7.5-1.5-11.25-1.5h-208c-22 0-40 18-40 40v208c0 22 18 40 40 40h208c22 0 40-18 40-40v-31.5c0-2 0.75-4 2.25-5.5l16-16c2.5-2.5 5.75-3 8.75-1.75s5 4 5 7.25zM328 80l72 72-168 168h-72v-72zM439 113l-23 23-72-72 23-23c9.25-9.25 24.75-9.25 34 0l38 38c9.25 9.25 9.25 24.75 0 34z'%3e%3c/path%3e%3c/svg%3e";
46
-
47
- var img$2 = "data:image/svg+xml,%3csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='541' height='512' viewBox='0 0 541 512'%3e %3cpath fill='black' d='M103.306 228.483l129.493-125.249c-17.662-4.272-31.226-18.148-34.98-35.663l-0.055-0.307-129.852 125.248c17.812 4.15 31.53 18.061 35.339 35.662l0.056 0.308z'%3e%3c/path%3e %3cpath fill='black' d='M459.052 393.010c-13.486-8.329-22.346-23.018-22.373-39.779v-0.004c-0.053-0.817-0.082-1.772-0.082-2.733s0.030-1.916 0.089-2.863l-0.007 0.13-149.852 71.94c9.598 8.565 15.611 20.969 15.611 34.779 0 0.014 0 0.029 0 0.043v-0.002c-0.048 5.164-0.94 10.104-2.544 14.711l0.098-0.322z'%3e%3c/path%3e %3cpath fill='black' d='M290.207 57.553c-0.009 15.55-7.606 29.324-19.289 37.819l-0.135 0.093 118.054 46.69c-0.216-1.608-0.346-3.48-0.36-5.379v-0.017c0.033-16.948 9.077-31.778 22.596-39.953l0.209-0.118-122.298-48.056c0.659 2.633 1.098 5.693 1.221 8.834l0.002 0.087z'%3e%3c/path%3e %3cpath fill='black' d='M241.36 410.132l-138.629-160.067c-4.734 17.421-18.861 30.61-36.472 33.911l-0.29 0.045 143.881 166.255c1.668-18.735 14.197-34.162 31.183-40.044l0.327-0.099z'%3e%3c/path%3e %3cpath fill='black' d='M243.446 115.105c-31.785 0-57.553-25.767-57.553-57.553s25.767-57.553 57.553-57.553c31.785 0 57.552 25.767 57.552 57.553v0c0 31.786-25.767 57.553-57.553 57.553v0zM243.446 21.582c-19.866 0-35.97 16.105-35.97 35.97s16.105 35.97 35.97 35.97c19.866 0 35.97-16.105 35.97-35.97v0c0-19.866-16.104-35.97-35.97-35.97v0z'%3e%3c/path%3e %3cpath fill='black' d='M483.224 410.78c-31.786 0-57.553-25.767-57.553-57.553s25.767-57.553 57.553-57.553c31.786 0 57.552 25.767 57.552 57.553v0c0 31.786-25.767 57.553-57.553 57.553v0zM483.224 317.257c-19.866 0-35.97 16.104-35.97 35.97s16.105 35.97 35.97 35.97c19.866 0 35.97-16.105 35.97-35.97v0c0-19.866-16.105-35.97-35.97-35.97v0z'%3e%3c/path%3e %3cpath fill='black' d='M57.553 295.531c-31.785 0-57.553-25.767-57.553-57.553s25.767-57.553 57.553-57.553c31.785 0 57.553 25.767 57.553 57.553v0c0 31.786-25.767 57.553-57.553 57.553v0zM57.553 202.008c-19.866 0-35.97 16.105-35.97 35.97s16.105 35.97 35.97 35.97c19.866 0 35.97-16.105 35.97-35.97v0c-0.041-19.835-16.13-35.898-35.97-35.898 0 0 0 0 0 0v0z'%3e%3c/path%3e %3cpath fill='black' d='M256.036 512.072c-31.786 0-57.553-25.767-57.553-57.553s25.767-57.553 57.553-57.553c31.786 0 57.553 25.767 57.553 57.553v0c0 31.786-25.767 57.553-57.553 57.553v0zM256.036 418.55c-19.866 0-35.97 16.104-35.97 35.97s16.105 35.97 35.97 35.97c19.866 0 35.97-16.105 35.97-35.97v0c0-19.866-16.105-35.97-35.97-35.97v0z'%3e%3c/path%3e %3cpath fill='black' d='M435.24 194.239c-31.786 0-57.553-25.767-57.553-57.553s25.767-57.553 57.553-57.553c31.786 0 57.553 25.767 57.553 57.553v0c0 31.785-25.767 57.553-57.553 57.553v0zM435.24 100.716c-19.866 0-35.97 16.105-35.97 35.97s16.105 35.97 35.97 35.97c19.866 0 35.97-16.105 35.97-35.97v0c0-19.866-16.105-35.97-35.97-35.97v0z'%3e%3c/path%3e%3c/svg%3e";
48
-
49
- var img$3 = "data:image/svg+xml,%3csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='512' height='512' viewBox='0 0 512 512'%3e%3cpath d='M240 352h-240v128h480v-128h-240zM448 416h-64v-32h64v32zM112 160l128-128 128 128h-80v160h-96v-160z'%3e%3c/path%3e%3c/svg%3e";
50
-
51
- var img$4 = "data:image/svg+xml,%3csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='768' height='768' viewBox='0 0 768 768'%3e%3cpath d='M384 288q39 0 67.5 28.5t28.5 67.5-28.5 67.5-67.5 28.5-67.5-28.5-28.5-67.5 28.5-67.5 67.5-28.5zM384 544.5q66 0 113.25-47.25t47.25-113.25-47.25-113.25-113.25-47.25-113.25 47.25-47.25 113.25 47.25 113.25 113.25 47.25zM384 144q118.5 0 214.5 66t138 174q-42 108-138 174t-214.5 66-214.5-66-138-174q42-108 138-174t214.5-66z'%3e%3c/path%3e%3c/svg%3e";
52
-
53
- var img$5 = "data:image/svg+xml,%3csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='768' height='768' viewBox='0 0 768 768'%3e%3cpath d='M379.5 288h4.5q39 0 67.5 28.5t28.5 67.5v6zM241.5 313.5q-18 36-18 70.5 0 66 47.25 113.25t113.25 47.25q34.5 0 70.5-18l-49.5-49.5q-12 3-21 3-39 0-67.5-28.5t-28.5-67.5q0-9 3-21zM64.5 136.5l40.5-40.5 567 567-40.5 40.5q-7.5-7.5-47.25-46.5t-60.75-60q-64.5 27-139.5 27-118.5 0-214.5-66t-138-174q16.5-39 51.75-86.25t68.25-72.75q-18-18-50.25-51t-36.75-37.5zM384 223.5q-30 0-58.5 12l-69-69q58.5-22.5 127.5-22.5 118.5 0 213.75 66t137.25 174q-36 88.5-109.5 151.5l-93-93q12-28.5 12-58.5 0-66-47.25-113.25t-113.25-47.25z'%3e%3c/path%3e%3c/svg%3e";
54
-
55
- var GeometryType;
56
- (function (GeometryType) {
57
- GeometryType["Point"] = "Point";
58
- GeometryType["LineString"] = "LineString";
59
- GeometryType["LinearRing"] = "LinearRing";
60
- GeometryType["Polygon"] = "Polygon";
61
- GeometryType["MultiPoint"] = "MultiPoint";
62
- GeometryType["MultiLineString"] = "MultiLineString";
63
- GeometryType["MultiPolygon"] = "MultiPolygon";
64
- GeometryType["GeometryCollection"] = "GeometryCollection";
65
- GeometryType["Circle"] = "Circle";
66
- })(GeometryType || (GeometryType = {}));
67
-
68
- const es = {
69
- labels: {
70
- select: 'Seleccionar',
71
- addElement: 'Modo dibujo',
72
- editElement: 'Editar elemento',
73
- save: 'Guardar',
74
- delete: 'Eliminar',
75
- cancel: 'Cancelar',
76
- apply: 'Aplicar cambios',
77
- upload: 'Subir',
78
- editMode: 'Modo Edición',
79
- confirmDelete: '¿Estás seguro de borrar el elemento?',
80
- geomTypeNotSupported: 'Geometría no compatible con la capa',
81
- editFields: 'Editar campos',
82
- editGeom: 'Editar geometría',
83
- selectDrawType: 'Tipo de geometría para dibujar',
84
- uploadToLayer: 'Subir archivo a la capa seleccionada',
85
- uploadFeatures: 'Subida de elementos a la capa',
86
- validFeatures: 'Válidas',
87
- invalidFeatures: 'Invalidas',
88
- loading: 'Cargando...',
89
- toggleVisibility: 'Cambiar visibilidad de la capa',
90
- close: 'Cerrar'
91
- },
92
- errors: {
93
- capabilities: 'No se pudieron obtener las Capabilidades del GeoServer',
94
- wfst: 'El GeoServer no tiene soporte a Transacciones',
95
- layer: 'No se pudieron obtener datos de la capa',
96
- layerNotFound: 'CApa no encontrada',
97
- noValidGeometry: 'No se encontraron geometrías válidas para agregar a esta capa',
98
- geoserver: 'No se pudieron obtener datos desde el GeoServer',
99
- badFormat: 'Formato no soportado',
100
- badFile: 'Error al leer elementos del archivo',
101
- lockFeature: 'No se pudieron bloquear elementos en el GeoServer.',
102
- transaction: 'Error al hacer transacción con el GeoServer. HTTP status:',
103
- getFeatures: 'Error al obtener elemento desde el GeoServer. HTTP status:'
104
- }
105
- };
106
-
107
- const en = {
108
- labels: {
109
- select: 'Select',
110
- addElement: 'Toggle Draw mode',
111
- editElement: 'Edit feature',
112
- save: 'Save',
113
- delete: 'Delete',
114
- cancel: 'Cancel',
115
- apply: 'Apply changes',
116
- upload: 'Upload',
117
- editMode: 'Edit Mode',
118
- confirmDelete: 'Are you sure to delete the feature?',
119
- geomTypeNotSupported: 'Geometry not supported by layer',
120
- editFields: 'Edit fields',
121
- editGeom: 'Edit geometry',
122
- selectDrawType: 'Geometry type to draw',
123
- uploadToLayer: 'Upload file to selected layer',
124
- uploadFeatures: 'Uploaded features to layer',
125
- validFeatures: 'Valid geometries',
126
- invalidFeatures: 'Invalid',
127
- loading: 'Loading...',
128
- toggleVisibility: 'Toggle layer visibility',
129
- close: 'Close'
130
- },
131
- errors: {
132
- capabilities: 'GeoServer Capabilities could not be downloaded.',
133
- wfst: 'The GeoServer does not support Transactions',
134
- layer: 'Could not get data from layer',
135
- layerNotFound: 'Layer not found',
136
- noValidGeometry: 'No valid geometries found to add to this layer',
137
- geoserver: 'Could not get data from the GeoServer',
138
- badFormat: 'Unsupported format',
139
- badFile: 'Error reading items from file',
140
- lockFeature: 'Could not lock items on the GeoServer. HTTP status:',
141
- transaction: 'Error when doing Transaction with GeoServer. HTTP status:',
142
- getFeatures: 'Error getting elements from GeoServer. HTTP status:'
143
- }
144
- };
145
-
146
- const zh = {
147
- labels: {
148
- select: '选择',
149
- addElement: '切换绘图类型',
150
- editElement: '编辑元素',
151
- save: '保存',
152
- delete: '删除',
153
- cancel: '取消',
154
- apply: '确认并应用改变',
155
- upload: '上传',
156
- editMode: '编辑模式',
157
- confirmDelete: '确认删除元素?',
158
- geomTypeNotSupported: '图层不支持该几何',
159
- editFields: '编辑区域',
160
- editGeom: '编辑几何',
161
- selectDrawType: '几何类型',
162
- uploadToLayer: '通过文件上传图层',
163
- uploadFeatures: '上传元素到图层',
164
- validFeatures: '合法的几何类型',
165
- invalidFeatures: '不合法',
166
- loading: '加载中...',
167
- toggleVisibility: '切换图层透明度',
168
- close: '关闭'
169
- },
170
- errors: {
171
- capabilities: '无法加载GeoServer服务所支持的能力.',
172
- wfst: 'GeoServer不支持事务',
173
- layer: '无法从图层获得数据',
174
- layerNotFound: 'Layer not found',
175
- noValidGeometry: '不支持的几何类型无法加载到图层',
176
- geoserver: '无法从GeoServer获取数据',
177
- badFormat: '不支持的格式',
178
- badFile: '读取文件数据出错',
179
- lockFeature: '无法锁定GeoServer上的元素. HTTP状态码:',
180
- transaction: 'GeoServer处理事务出错. HTTP状态码:',
181
- getFeatures: '从GeoServer获取元素出错. HTTP状态码:'
182
- }
183
- };
184
-
185
- var i18n = /*#__PURE__*/Object.freeze({
186
- __proto__: null,
187
- es: es,
188
- en: en,
189
- zh: zh
190
- });
191
-
192
- // https://docs.geoserver.org/latest/en/user/services/wfs/axis_order.html
193
- // Axis ordering: latitude/longitude
194
- const DEFAULT_GEOSERVER_SRS = 'EPSG:3857';
195
- const DEFAULT_LANGUAGE = 'en';
196
- const controlElement = document.createElement('div');
197
- /**
198
- * Tiny WFST-T client to insert (drawing/uploading), modify and delete
199
- * features on GeoServers using OpenLayers. Layers with these types
200
- * of geometries are supported: "GeometryCollection" (in this case, you can
201
- * choose the geometry type of each element to draw), "Point", "MultiPoint",
202
- * "LineString", "MultiLineString", "Polygon" and "MultiPolygon".
203
- *
204
- * @constructor
205
- * @fires getCapabilities
206
- * @fires describeFeatureType
207
- * @fires allDescribeFeatureTypeLoaded
208
- * @fires getFeature
209
- * @fires modifystart
210
- * @fires modifyend
211
- * @fires drawstart
212
- * @fires drawend
213
- * @extends {ol/control/Control~Control}
214
- * @param opt_options Wfst options, see [Wfst Options](#options) for more details.
215
- */
216
- class Wfst extends Control {
217
- constructor(opt_options) {
218
- super({
219
- target: null,
220
- element: controlElement
221
- });
222
- // Check if the selected language exists
223
- this._i18n =
224
- opt_options.language && opt_options.language in i18n
225
- ? i18n[opt_options.language]
226
- : i18n[DEFAULT_LANGUAGE];
227
- if (opt_options.i18n) {
228
- // Merge custom translations
229
- this._i18n = Object.assign(Object.assign({}, this._i18n), opt_options.i18n);
230
- }
231
- // Default options
232
- const defaultOptions = {
233
- geoServerUrl: null,
234
- geoServerAdvanced: {
235
- getCapabilitiesVersion: '1.3.0',
236
- getFeatureVersion: '1.0.0',
237
- describeFeatureTypeVersion: '1.1.0',
238
- lockFeatureVersion: '1.1.0',
239
- wfsTransactionVersion: '1.1.0',
240
- projection: DEFAULT_GEOSERVER_SRS
241
- },
242
- headers: {},
243
- credentials: 'same-origin',
244
- layers: null,
245
- evtType: 'singleclick',
246
- active: true,
247
- showControl: true,
248
- useLockFeature: true,
249
- minZoom: 9,
250
- language: DEFAULT_LANGUAGE,
251
- uploadFormats: '.geojson,.json,.kml',
252
- processUpload: null,
253
- beforeInsertFeature: null,
254
- modal: {
255
- animateClass: 'fade',
256
- animateInClass: 'show',
257
- transition: 300,
258
- backdropTransition: 150,
259
- templates: {
260
- dialog: '<div class="modal-dialog modal-dialog-centered"></div>',
261
- headerClose: `<button type="button" class="btn-close" data-dismiss="modal" aria-label="${this._i18n.labels.close}"><span aria-hidden="true">×</span></button>`
262
- }
263
- }
264
- };
265
- this._options = deepObjectAssign(defaultOptions, opt_options);
266
- this._mapLayers = [];
267
- this._countRequests = 0;
268
- this._isEditModeOn = false;
269
- // GeoServer
270
- this._hasLockFeature = false;
271
- this._hasTransaction = false;
272
- this._geoServerCapabilities = null;
273
- this._geoServerData = {};
274
- // Editing
275
- this._editedFeatures = new Set();
276
- this._layerToInsertElements = this._options.layers[0].name; // By default, the first layer is ready to accept new draws
277
- this._insertFeatures = [];
278
- this._updateFeatures = [];
279
- this._deleteFeatures = [];
280
- // Formats
281
- this._formatWFS = new WFS();
282
- this._formatGeoJSON = new GeoJSON();
283
- this._formatKml = new KML({
284
- extractStyles: false,
285
- showPointNames: false
286
- });
287
- this._xs = new XMLSerializer();
288
- this._controlWidgetToolsDiv = controlElement;
289
- this._controlWidgetToolsDiv.className = 'ol-wfst--tools-control';
290
- this._initAsyncOperations();
291
- }
292
- /**
293
- * @private
294
- */
295
- _onLoad() {
296
- this._map = super.getMap();
297
- this._view = this._map.getView();
298
- this._viewport = this._map.getViewport();
299
- // State
300
- this._isVisible = this._view.getZoom() > this._options.minZoom;
301
- this._createLayers(this._options.layers);
302
- this._initMapElements(this._options.showControl, this._options.active);
303
- }
304
- /**
305
- * Connect to the GeoServer and retrieve metadata about the service (GetCapabilities).
306
- * Get each layer specs (DescribeFeatureType) and create the layers and map controls.
307
- *
308
- * @param layers
309
- * @param showControl
310
- * @param active
311
- * @private
312
- */
313
- _initAsyncOperations() {
314
- return __awaiter(this, void 0, void 0, function* () {
315
- try {
316
- // @ts-expect-error
317
- this.on('allDescribeFeatureTypeLoaded', this._onLoad);
318
- this._showLoading();
319
- yield this._connectToGeoServerAndGetCapabilities();
320
- if (this._options.layers) {
321
- yield this._getGeoserverLayersData(this._options.layers, this._options.geoServerUrl);
322
- }
323
- }
324
- catch (err) {
325
- this._hideLoading();
326
- this._showError(err.message, err);
327
- }
328
- });
329
- }
330
- /**
331
- * Get the capabilities from the GeoServer and check
332
- * all the available operations.
333
- *
334
- * @fires capabilitiesLoaded
335
- * @private
336
- */
337
- _connectToGeoServerAndGetCapabilities() {
338
- const _super = Object.create(null, {
339
- dispatchEvent: { get: () => super.dispatchEvent }
340
- });
341
- return __awaiter(this, void 0, void 0, function* () {
342
- /**
343
- * @private
344
- */
345
- const getCapabilities = () => __awaiter(this, void 0, void 0, function* () {
346
- const params = new URLSearchParams({
347
- service: 'wfs',
348
- version: this._options.geoServerAdvanced.getCapabilitiesVersion,
349
- request: 'GetCapabilities',
350
- exceptions: 'application/json'
351
- });
352
- const url_fetch = this._options.geoServerUrl + '?' + params.toString();
353
- try {
354
- const response = yield fetch(url_fetch, {
355
- headers: this._options.headers,
356
- credentials: this._options.credentials
357
- });
358
- if (!response.ok) {
359
- throw new Error('');
360
- }
361
- const data = yield response.text();
362
- const capabilities = new window.DOMParser().parseFromString(data, 'text/xml');
363
- return capabilities;
364
- }
365
- catch (err) {
366
- throw new Error(this._i18n.errors.capabilities);
367
- }
368
- });
369
- this._geoServerCapabilities = yield getCapabilities();
370
- // Available operations in the geoserver
371
- const operations = this._geoServerCapabilities.getElementsByTagName('ows:Operation');
372
- Array.from(operations).forEach((operation) => {
373
- if (operation.getAttribute('name') === 'Transaction') {
374
- this._hasTransaction = true;
375
- }
376
- else if (operation.getAttribute('name') === 'LockFeature') {
377
- this._hasLockFeature = true;
378
- }
379
- });
380
- if (!this._hasTransaction) {
381
- throw new Error(this._i18n.errors.wfst);
382
- }
383
- _super.dispatchEvent.call(this, {
384
- type: 'getCapabilities',
385
- // @ts-expect-error
386
- data: this._geoServerCapabilities
387
- });
388
- });
389
- }
390
- /**
391
- * Request and store data layers obtained by DescribeFeatureType
392
- *
393
- * @param layers
394
- * @param geoServerUrl
395
- * @private
396
- */
397
- _getGeoserverLayersData(layers, geoServerUrl) {
398
- const _super = Object.create(null, {
399
- dispatchEvent: { get: () => super.dispatchEvent }
400
- });
401
- return __awaiter(this, void 0, void 0, function* () {
402
- /**
403
- *
404
- * @param layerName
405
- * @fires describeFeatureType
406
- * @fires allDescribeFeatureTypeLoaded
407
- * @returns
408
- * @private
409
- */
410
- const getLayerData = (layerName) => __awaiter(this, void 0, void 0, function* () {
411
- const params = new URLSearchParams({
412
- service: 'wfs',
413
- version: this._options.geoServerAdvanced
414
- .describeFeatureTypeVersion,
415
- request: 'DescribeFeatureType',
416
- typeName: layerName,
417
- outputFormat: 'application/json',
418
- exceptions: 'application/json'
419
- });
420
- const url_fetch = geoServerUrl + '?' + params.toString();
421
- const response = yield fetch(url_fetch, {
422
- headers: this._options.headers,
423
- credentials: this._options.credentials
424
- });
425
- if (!response.ok) {
426
- throw new Error('');
427
- }
428
- return yield response.json();
429
- });
430
- for (const layer of layers) {
431
- const layerName = layer.name;
432
- const layerLabel = layer.label || layerName;
433
- try {
434
- const data = yield getLayerData(layerName);
435
- if (!data) {
436
- throw new Error('');
437
- }
438
- _super.dispatchEvent.call(this, {
439
- type: 'describeFeatureType',
440
- // @ts-expect-error
441
- layer: layerName,
442
- data: data
443
- });
444
- const targetNamespace = data.targetNamespace;
445
- const properties = data.featureTypes[0].properties;
446
- // Find the geometry field
447
- const geom = properties.find((el) => el.type.indexOf('gml:') >= 0);
448
- this._geoServerData[layerName] = {
449
- namespace: targetNamespace,
450
- properties: properties,
451
- geomType: geom.localType,
452
- geomField: geom.name
453
- };
454
- }
455
- catch (err) {
456
- throw new Error(`${this._i18n.errors.layer} "${layerLabel}"`);
457
- }
458
- }
459
- _super.dispatchEvent.call(this, {
460
- type: 'allDescribeFeatureTypeLoaded',
461
- // @ts-expect-error
462
- data: this._geoServerData
463
- });
464
- });
465
- }
466
- /**
467
- * Create map layers in wfs o wms modes.
468
- *
469
- * @param layers
470
- * @private
471
- */
472
- _createLayers(layers) {
473
- let layerLoaded = 0;
474
- let layersNumber = 0; // Only count visibles
475
- /**
476
- * When all the data is loaded, hide the loading
477
- * @private
478
- */
479
- const addLayerLoaded = () => {
480
- layerLoaded++;
481
- if (layerLoaded >= layersNumber) {
482
- this._hideLoading();
483
- }
484
- };
485
- /**
486
- *
487
- * @param layerParams
488
- * @private
489
- */
490
- const newWmsLayer = (layerParams) => {
491
- const layerName = layerParams.name;
492
- const cqlFilter = layerParams.cqlFilter;
493
- const buffer = layerParams.tilesBuffer;
494
- const params = {
495
- SERVICE: 'WMS',
496
- LAYERS: layerName,
497
- TILED: true
498
- };
499
- if (cqlFilter) {
500
- params['CQL_FILTER'] = cqlFilter;
501
- }
502
- if (buffer) {
503
- params['BUFFER'] = buffer;
504
- }
505
- const source = new TileWMS({
506
- url: this._options.geoServerUrl,
507
- params: params,
508
- serverType: 'geoserver',
509
- tileLoadFunction: (tile, src) => __awaiter(this, void 0, void 0, function* () {
510
- try {
511
- const response = yield fetch(src, {
512
- headers: this._options.headers,
513
- credentials: this._options.credentials
514
- });
515
- if (!response.ok) {
516
- throw new Error('');
517
- }
518
- const data = yield response.blob();
519
- if (data !== undefined) {
520
- tile.getImage().src = URL.createObjectURL(data);
521
- }
522
- else {
523
- throw new Error('');
524
- }
525
- tile.setState(TileState.LOADED);
526
- }
527
- catch (err) {
528
- tile.setState(TileState.ERROR);
529
- }
530
- })
531
- });
532
- let loading = 0;
533
- let loaded = 0;
534
- source.on('tileloadstart', () => {
535
- loading++;
536
- this._showLoading();
537
- });
538
- source.on(['tileloadend', 'tileloaderror'], () => {
539
- loaded++;
540
- setTimeout(() => {
541
- if (loading === loaded)
542
- addLayerLoaded();
543
- }, 300);
544
- });
545
- const layer_options = Object.assign({ name: layerName, type: '_wms_', minZoom: this._options.minZoom, source: source, visible: true, zIndex: 1 }, layerParams);
546
- const layer = new Tile(layer_options);
547
- return layer;
548
- };
549
- /**
550
- *
551
- * @param layerParams
552
- * @private
553
- */
554
- const newWfsLayer = (layerParams) => {
555
- const layerName = layerParams.name;
556
- const cqlFilter = layerParams.cqlFilter;
557
- const strategy = layerParams.wfsStrategy || 'bbox';
558
- const source = new Vector$1({
559
- format: new GeoJSON(),
560
- strategy: strategy === 'bbox' ? bbox : all,
561
- loader: (extent) => __awaiter(this, void 0, void 0, function* () {
562
- try {
563
- const params = new URLSearchParams({
564
- service: 'wfs',
565
- version: this._options.geoServerAdvanced
566
- .getFeatureVersion,
567
- request: 'GetFeature',
568
- typename: layerName,
569
- outputFormat: 'application/json',
570
- exceptions: 'application/json',
571
- srsName: this._options.geoServerAdvanced.projection.toString()
572
- });
573
- if (cqlFilter) {
574
- params.append('cql_filter', cqlFilter);
575
- }
576
- // If bbox, add extent to the request
577
- if (strategy === 'bbox') {
578
- const extentGeoServer = transformExtent(extent, this._view.getProjection().getCode(), this._options.geoServerAdvanced.projection);
579
- // https://docs.geoserver.org/stable/en/user/services/wfs/reference.html
580
- // request features using a bounding box with CRS maybe different from featureTypes native CRS
581
- params.append('bbox', extentGeoServer.toString() +
582
- `,${this._options.geoServerAdvanced.projection}`);
583
- }
584
- const url_fetch = this._options.geoServerUrl +
585
- '?' +
586
- params.toString();
587
- const response = yield fetch(url_fetch, {
588
- headers: this._options.headers,
589
- credentials: this._options.credentials
590
- });
591
- if (!response.ok) {
592
- throw new Error('');
593
- }
594
- const data = yield response.json();
595
- this.dispatchEvent({
596
- type: 'getFeature',
597
- // @ts-expect-error
598
- layer: layerName,
599
- data: data
600
- });
601
- const features = source.getFormat().readFeatures(data, {
602
- featureProjection: this._view
603
- .getProjection()
604
- .getCode(),
605
- dataProjection: this._options.geoServerAdvanced
606
- .projection
607
- });
608
- features.forEach((feature) => {
609
- feature.set('_layerName_', layerName,
610
- /* silent = */ true);
611
- });
612
- source.addFeatures(features);
613
- source.dispatchEvent('featuresloadend');
614
- }
615
- catch (err) {
616
- source.dispatchEvent('featuresloaderror');
617
- this._showError(this._i18n.errors.geoserver, err);
618
- source.removeLoadedExtent(extent);
619
- }
620
- })
621
- });
622
- let loading = 0;
623
- let loaded = 0;
624
- source.on('featuresloadstart', () => {
625
- loading++;
626
- this._showLoading();
627
- });
628
- source.on(['featuresloadend', 'featuresloaderror'], () => {
629
- loaded++;
630
- setTimeout(() => {
631
- if (loading === loaded)
632
- addLayerLoaded();
633
- }, 300);
634
- });
635
- const layer_options = Object.assign({ name: layerName, type: '_wfs_', minZoom: this._options.minZoom, source: source, visible: true, zIndex: 2 }, layerParams);
636
- const layer = new Vector(layer_options);
637
- return layer;
638
- };
639
- for (const layerParams of layers) {
640
- const layerName = layerParams.name;
641
- // Only create the layer if we can get the GeoserverData
642
- if (this._geoServerData[layerName]) {
643
- let layer;
644
- const layerParams = this._options.layers.find((e) => e.name === layerName);
645
- const mode = layerParams.mode;
646
- // If mode is undefined, by default use wfs
647
- if (!mode) {
648
- layerParams.mode = 'wfs';
649
- }
650
- if (layerParams.mode === 'wfs') {
651
- layer = newWfsLayer(layerParams);
652
- }
653
- else {
654
- layer = newWmsLayer(layerParams);
655
- }
656
- if (layer.getVisible())
657
- layersNumber++;
658
- this._map.addLayer(layer);
659
- this._mapLayers[layerName] = layer;
660
- }
661
- }
662
- }
663
- /**
664
- * Create the edit layer to allow modify elements, add interactions,
665
- * map controls and keyboard handlers.
666
- *
667
- * @param showControl
668
- * @param active
669
- * @private
670
- */
671
- _initMapElements(showControl, active) {
672
- return __awaiter(this, void 0, void 0, function* () {
673
- // VectorLayer to store features on editing and inserting
674
- this._createEditLayer();
675
- this._addInteractions();
676
- this._addHandlers();
677
- if (showControl) {
678
- this._addMapControl();
679
- }
680
- // By default, init in edit mode
681
- this.activateEditMode(active);
682
- });
683
- }
684
- /**
685
- * @private
686
- */
687
- _addInteractions() {
688
- /**
689
- * Select the wfs feature already downloaded
690
- * @private
691
- */
692
- const prepareWfsInteraction = () => {
693
- this._collectionModify = new Collection();
694
- // Interaction to select wfs layer elements
695
- this.interactionWfsSelect = new Select({
696
- hitTolerance: 10,
697
- style: (feature) => this._styleFunction(feature),
698
- toggleCondition: never,
699
- filter: (feature, layer) => {
700
- return (!this._isEditModeOn &&
701
- layer &&
702
- layer.get('type') === '_wfs_');
703
- }
704
- });
705
- this._map.addInteraction(this.interactionWfsSelect);
706
- this.interactionWfsSelect.on('select', ({ selected, deselected, mapBrowserEvent }) => {
707
- const coordinate = mapBrowserEvent.coordinate;
708
- if (selected.length) {
709
- selected.forEach((feature) => {
710
- if (!this._editedFeatures.has(String(feature.getId()))) {
711
- // Remove the feature from the original layer
712
- const layer = this.interactionWfsSelect.getLayer(feature);
713
- layer.getSource().removeFeature(feature);
714
- this._addFeatureToEdit(feature, coordinate);
715
- }
716
- });
717
- }
718
- if (deselected.length) {
719
- if (!this._isEditModeOn) {
720
- deselected.forEach((feature) => {
721
- // Trigger deselect
722
- // This is necessary for those times where two features overlap.
723
- this._collectionModify.remove(feature);
724
- });
725
- }
726
- }
727
- });
728
- };
729
- /**
730
- * Call the geoserver to get the clicked feature
731
- * @private
732
- */
733
- const prepareWmsInteraction = () => {
734
- // Interaction to allow select features in the edit layer
735
- this.interactionSelectModify = new Select({
736
- style: (feature) => this._styleFunction(feature),
737
- layers: [this._editLayer],
738
- toggleCondition: never,
739
- removeCondition: () => (this._isEditModeOn ? true : false) // Prevent deselect on clicking outside the feature
740
- });
741
- this._map.addInteraction(this.interactionSelectModify);
742
- this._collectionModify = this.interactionSelectModify.getFeatures();
743
- const getFeatures = (evt) => __awaiter(this, void 0, void 0, function* () {
744
- for (const layerName in this._mapLayers) {
745
- const layer = this._mapLayers[layerName];
746
- // If layer is hidden or is not a wms, skip
747
- if (!layer.getVisible() ||
748
- !(layer.get('type') === '_wms_')) {
749
- continue;
750
- }
751
- const coordinate = evt.coordinate;
752
- // Si la vista es lejana, disminumos el buffer
753
- // Si es cercana, lo aumentamos, por ejemplo, para podeer clickear los vectores
754
- // y mejorar la sensibilidad en IOS
755
- const buffer = this._view.getZoom() > 10 ? 10 : 5;
756
- const source = layer.getSource();
757
- // Fallback to support a bad name
758
- // https://openlayers.org/en/v5.3.0/apidoc/module-ol_source_ImageWMS-ImageWMS.html#getGetFeatureInfoUrl
759
- const fallbackOl5 = 'getFeatureInfoUrl' in source
760
- ? 'getFeatureInfoUrl'
761
- : 'getGetFeatureInfoUrl';
762
- const url = source[fallbackOl5](coordinate, this._view.getResolution(), this._view.getProjection().getCode(), {
763
- INFO_FORMAT: 'application/json',
764
- BUFFER: buffer,
765
- FEATURE_COUNT: 1,
766
- EXCEPTIONS: 'application/json'
767
- });
768
- try {
769
- const response = yield fetch(url, {
770
- headers: this._options.headers,
771
- credentials: this._options.credentials
772
- });
773
- if (!response.ok) {
774
- throw new Error(this._i18n.errors.getFeatures +
775
- ' ' +
776
- response.status);
777
- }
778
- const data = yield response.json();
779
- const features = this._formatGeoJSON.readFeatures(data);
780
- if (!features.length) {
781
- continue;
782
- }
783
- features.forEach((feature) => this._addFeatureToEdit(feature, coordinate, layerName));
784
- }
785
- catch (err) {
786
- this._showError(err.message, err);
787
- }
788
- }
789
- });
790
- this._keyClickWms = this._map.on(this._options.evtType, (evt) => __awaiter(this, void 0, void 0, function* () {
791
- if (this._map.hasFeatureAtPixel(evt.pixel)) {
792
- return;
793
- }
794
- if (!this._isVisible) {
795
- return;
796
- }
797
- // Only get other features if editmode is disabled
798
- if (!this._isEditModeOn) {
799
- yield getFeatures(evt);
800
- }
801
- }));
802
- };
803
- if (this._options.layers.find((layer) => layer.mode === 'wfs')) {
804
- prepareWfsInteraction();
805
- }
806
- if (this._options.layers.find((layer) => layer.mode === 'wms')) {
807
- prepareWmsInteraction();
808
- }
809
- this.interactionModify = new Modify({
810
- style: () => {
811
- if (this._isEditModeOn) {
812
- return new Style({
813
- image: new Circle({
814
- radius: 6,
815
- fill: new Fill({
816
- color: '#ff0000'
817
- }),
818
- stroke: new Stroke({
819
- width: 2,
820
- color: 'rgba(5, 5, 5, 0.9)'
821
- })
822
- })
823
- });
824
- }
825
- else {
826
- return;
827
- }
828
- },
829
- features: this._collectionModify,
830
- condition: (evt) => {
831
- return primaryAction(evt) && this._isEditModeOn;
832
- }
833
- });
834
- this._map.addInteraction(this.interactionModify);
835
- this.interactionSnap = new Snap({
836
- source: this._editLayer.getSource()
837
- });
838
- this._map.addInteraction(this.interactionSnap);
839
- }
840
- /**
841
- * Layer to store temporary the elements to be edited
842
- * @private
843
- */
844
- _createEditLayer() {
845
- this._editLayer = new Vector({
846
- source: new Vector$1(),
847
- zIndex: 100
848
- });
849
- this._map.addLayer(this._editLayer);
850
- }
851
- /**
852
- * Add map handlers
853
- * @private
854
- */
855
- _addHandlers() {
856
- /**
857
- * @private
858
- */
859
- const keyboardEvents = () => {
860
- document.addEventListener('keydown', ({ key }) => {
861
- const inputFocus = document.querySelector('input:focus');
862
- if (inputFocus) {
863
- return;
864
- }
865
- if (key === 'Delete') {
866
- const selectedFeatures = this._collectionModify;
867
- if (selectedFeatures) {
868
- selectedFeatures.forEach((feature) => {
869
- this._deleteFeature(feature, true);
870
- });
871
- }
872
- }
873
- });
874
- };
875
- // When a feature is modified, add this to a list.
876
- // This prevent events fired on select and deselect features that has no changes and should
877
- // not be updated in the geoserver
878
- this.interactionModify.on('modifyend', (evt) => {
879
- const feature = evt.features.item(0);
880
- this._addFeatureToEditedList(feature);
881
- super.dispatchEvent(evt);
882
- });
883
- this.interactionModify.on('modifystart', (evt) => {
884
- super.dispatchEvent(evt);
885
- });
886
- this._onDeselectFeatureEvent();
887
- this._onRemoveFeatureEvent();
888
- /**
889
- * @private
890
- */
891
- const handleZoomEnd = () => {
892
- if (this._currentZoom > this._options.minZoom) {
893
- // Show the layers
894
- if (!this._isVisible) {
895
- this._isVisible = true;
896
- }
897
- }
898
- else {
899
- // Hide the layer
900
- if (this._isVisible) {
901
- this._isVisible = false;
902
- }
903
- }
904
- };
905
- this._map.on('moveend', () => {
906
- this._currentZoom = this._view.getZoom();
907
- if (this._currentZoom !== this._lastZoom) {
908
- handleZoomEnd();
909
- }
910
- this._lastZoom = this._currentZoom;
911
- });
912
- keyboardEvents();
913
- }
914
- /**
915
- * Add the widget on the map to allow change the tools and select active layers
916
- * @private
917
- */
918
- _addMapControl() {
919
- /**
920
- * @private
921
- * @returns
922
- */
923
- const createLayersControl = () => {
924
- /**
925
- *
926
- * @param layerParams
927
- * @private
928
- * @returns
929
- */
930
- const createLayerElements = (layerParams) => {
931
- const layerName = layerParams.name;
932
- const layerLabel = `<span title="${this._geoServerData[layerName].geomType}">${layerParams.label || layerName}</span>`;
933
- const visible = 'visible' in layerParams ? layerParams.visible : true;
934
- return `
935
- <div class="wfst--layer-control
936
- ${visible ? 'ol-wfst--visible-on' : ''}
937
- ${layerName === this._layerToInsertElements
938
- ? 'ol-wfst--selected-on'
939
- : ''}
940
- " data-layer="${layerName}">
941
- <div class="ol-wfst--tools-control-visible">
942
- <span class="ol-wfst--tools-control-visible-btn ol-wfst--visible-btn-on" title="${this._i18n.labels.toggleVisibility}">
943
- <img src="${img$4}"/>
944
- </span>
945
- <span class="ol-wfst--tools-control-visible-btn ol-wfst--visible-btn-off" title="${this._i18n.labels.toggleVisibility}">
946
- <img src="${img$5}"/>
947
- </span>
948
- </div>
949
- <label for="wfst--${layerName}">
950
- <input value="${layerName}" id="wfst--${layerName}" type="radio" class="ol-wfst--tools-control-input" name="wfst--select-layer" ${layerName === this._layerToInsertElements
951
- ? 'checked="checked"'
952
- : ''}>
953
- ${layerLabel}
954
- </label>
955
- </div>`;
956
- };
957
- let htmlLayers = '';
958
- Object.keys(this._mapLayers).map((key) => (htmlLayers += createLayerElements(this._options.layers.find((el) => el.name === key))));
959
- const selectLayers = document.createElement('div');
960
- selectLayers.className = 'wfst--tools-control--select-layers';
961
- selectLayers.innerHTML = htmlLayers;
962
- // Layer Selector
963
- const radioInputs = selectLayers.querySelectorAll('input');
964
- radioInputs.forEach((radioInput) => {
965
- const parentDiv = radioInput.closest('.wfst--layer-control');
966
- radioInput.onchange = () => {
967
- // Deselect DOM previous layer
968
- const selected = selectLayers.querySelector('.ol-wfst--selected-on');
969
- if (selected)
970
- selected.classList.remove('ol-wfst--selected-on');
971
- // Select this layer
972
- parentDiv.classList.add('ol-wfst--selected-on');
973
- this._layerToInsertElements = radioInput.value;
974
- this._changeStateSelect(this._layerToInsertElements);
975
- };
976
- });
977
- // Visibility toggler
978
- const visibilityBtn = selectLayers.querySelectorAll('.ol-wfst--tools-control-visible-btn');
979
- visibilityBtn.forEach((btn) => {
980
- const parentDiv = btn.closest('.wfst--layer-control');
981
- const layerName = parentDiv.dataset['layer'];
982
- btn.onclick = () => {
983
- parentDiv.classList.toggle('ol-wfst--visible-on');
984
- const layer = this._mapLayers[layerName];
985
- if (parentDiv.classList.contains('ol-wfst--visible-on')) {
986
- layer.setVisible(true);
987
- }
988
- else {
989
- layer.setVisible(false);
990
- }
991
- };
992
- });
993
- return selectLayers;
994
- };
995
- /**
996
- * @private
997
- * @returns
998
- */
999
- const createHeadControl = () => {
1000
- /**
1001
- * @private
1002
- */
1003
- const createUploadElements = () => {
1004
- const container = document.createElement('div');
1005
- // Upload button Tool
1006
- const uploadButton = document.createElement('label');
1007
- uploadButton.className =
1008
- 'ol-wfst--tools-control-btn ol-wfst--tools-control-btn-upload';
1009
- uploadButton.htmlFor = 'ol-wfst--upload';
1010
- uploadButton.innerHTML = `<img src="${img$3}"/> `;
1011
- uploadButton.title = this._i18n.labels.uploadToLayer;
1012
- // Hidden Input form
1013
- const uploadInput = document.createElement('input');
1014
- uploadInput.id = 'ol-wfst--upload';
1015
- uploadInput.type = 'file';
1016
- uploadInput.accept = this._options.uploadFormats;
1017
- uploadInput.onchange = (evt) => this._processUploadFile(evt);
1018
- container.append(uploadInput);
1019
- container.append(uploadButton);
1020
- return container;
1021
- };
1022
- /**
1023
- * @private
1024
- * @returns
1025
- */
1026
- const createDrawContainer = () => {
1027
- const drawContainer = document.createElement('div');
1028
- drawContainer.className = 'ol-wfst--tools-control-draw-cnt';
1029
- // Draw Tool
1030
- const drawButton = document.createElement('button');
1031
- drawButton.className =
1032
- 'ol-wfst--tools-control-btn ol-wfst--tools-control-btn-draw';
1033
- drawButton.type = 'button';
1034
- drawButton.innerHTML = `<img src="${img}"/>`;
1035
- drawButton.title = this._i18n.labels.addElement;
1036
- drawButton.onclick = () => {
1037
- if (this._isDrawModeOn) {
1038
- this._resetStateButtons();
1039
- this.activateEditMode();
1040
- }
1041
- else {
1042
- this.activateDrawMode(this._layerToInsertElements);
1043
- }
1044
- };
1045
- // Select geom type
1046
- const select = document.createElement('select');
1047
- select.title = this._i18n.labels.selectDrawType;
1048
- select.className = 'wfst--tools-control--select-draw';
1049
- select.onchange = () => {
1050
- const selectedValue = select.value;
1051
- this._changeStateSelect(this._layerToInsertElements, selectedValue);
1052
- if (this._isDrawModeOn) {
1053
- this.activateDrawMode(this._layerToInsertElements);
1054
- }
1055
- };
1056
- const types = [
1057
- GeometryType.Point,
1058
- GeometryType.MultiPoint,
1059
- GeometryType.LineString,
1060
- GeometryType.MultiLineString,
1061
- GeometryType.Polygon,
1062
- GeometryType.MultiPolygon,
1063
- GeometryType.Circle
1064
- ];
1065
- for (const type of types) {
1066
- const option = document.createElement('option');
1067
- option.value = type;
1068
- option.text = type;
1069
- option.selected =
1070
- this._geoServerData[this._layerToInsertElements]
1071
- .geomType === type || false;
1072
- select.appendChild(option);
1073
- }
1074
- drawContainer.append(drawButton);
1075
- drawContainer.append(select);
1076
- this._selectDraw = select;
1077
- return drawContainer;
1078
- };
1079
- const subControl = document.createElement('div');
1080
- subControl.className = 'wfst--tools-control--head';
1081
- // Upload section
1082
- if (this._options.showUpload) {
1083
- const uploadSection = createUploadElements();
1084
- subControl.append(uploadSection);
1085
- }
1086
- const drawContainer = createDrawContainer();
1087
- subControl.append(drawContainer);
1088
- return subControl;
1089
- };
1090
- const headControl = createHeadControl();
1091
- this._controlWidgetToolsDiv.append(headControl);
1092
- const htmlLayers = createLayersControl();
1093
- this._controlWidgetToolsDiv.append(htmlLayers);
1094
- }
1095
- /**
1096
- * Show Loading
1097
- * @private
1098
- */
1099
- _showLoading() {
1100
- if (!this._modalLoading) {
1101
- this._modalLoading = document.createElement('div');
1102
- this._modalLoading.className = 'ol-wfst--tools-control--loading';
1103
- this._modalLoading.innerHTML = this._i18n.labels.loading;
1104
- this._controlWidgetToolsDiv.append(this._modalLoading);
1105
- }
1106
- this._modalLoading.classList.add('ol-wfst--tools-control--loading-show');
1107
- }
1108
- /**
1109
- * Hide loading
1110
- * @private
1111
- */
1112
- _hideLoading() {
1113
- this._modalLoading.classList.remove('ol-wfst--tools-control--loading-show');
1114
- }
1115
- /**
1116
- * Lock a feature in the geoserver before edit
1117
- *
1118
- * @param featureId
1119
- * @param layerName
1120
- * @param retry
1121
- * @private
1122
- */
1123
- _lockFeature(featureId, layerName, retry = 0) {
1124
- return __awaiter(this, void 0, void 0, function* () {
1125
- const params = new URLSearchParams({
1126
- service: 'wfs',
1127
- version: this._options.geoServerAdvanced.lockFeatureVersion,
1128
- request: 'LockFeature',
1129
- expiry: String(5),
1130
- LockId: 'GeoServer',
1131
- typeName: layerName,
1132
- releaseAction: 'SOME',
1133
- exceptions: 'application/json',
1134
- featureid: `${featureId}`
1135
- });
1136
- const url_fetch = this._options.geoServerUrl + '?' + params.toString();
1137
- try {
1138
- const response = yield fetch(url_fetch, {
1139
- headers: this._options.headers,
1140
- credentials: this._options.credentials
1141
- });
1142
- if (!response.ok) {
1143
- throw new Error(this._i18n.errors.lockFeature);
1144
- }
1145
- const data = yield response.text();
1146
- try {
1147
- // First, check if is a JSON (with errors)
1148
- const dataParsed = JSON.parse(data);
1149
- if ('exceptions' in dataParsed) {
1150
- const exceptions = dataParsed.exceptions;
1151
- if (exceptions[0].code === 'CannotLockAllFeatures') {
1152
- // Maybe the Feature is already blocked, ant thats trigger error, so, we try one locking more time again
1153
- if (!retry) {
1154
- this._lockFeature(featureId, layerName, 1);
1155
- }
1156
- else {
1157
- this._showError(this._i18n.errors.lockFeature, exceptions);
1158
- }
1159
- }
1160
- else {
1161
- this._showError(exceptions[0].text, exceptions);
1162
- }
1163
- }
1164
- }
1165
- catch (err) {
1166
- /*
1167
-
1168
- let dataDoc = (new window.DOMParser()).parseFromString(data, 'text/xml');
1169
-
1170
- let lockId = dataDoc.getElementsByTagName('wfs:LockId');
1171
-
1172
- let featuresLocked: HTMLCollectionOf<Element> = dataDoc.getElementsByTagName('ogc:FeatureId');
1173
-
1174
- for (let featureLocked of featuresLocked as any) {
1175
-
1176
- console.log(featureLocked.getAttribute('fid'));
1177
-
1178
- }
1179
-
1180
- */
1181
- }
1182
- return data;
1183
- }
1184
- catch (err) {
1185
- this._showError(err.message, err);
1186
- }
1187
- });
1188
- }
1189
- /**
1190
- * Show modal with errors
1191
- *
1192
- * @param msg
1193
- * @private
1194
- */
1195
- _showError(msg, originalError = null) {
1196
- Modal.alert('Error: ' + msg, Object.assign({}, this._options.modal)).show();
1197
- if (originalError)
1198
- console.error(originalError);
1199
- }
1200
- /**
1201
- * Make the WFS Transactions
1202
- *
1203
- * @param action
1204
- * @param features
1205
- * @param layerName
1206
- * @private
1207
- */
1208
- _transactWFS(action, features, layerName) {
1209
- return __awaiter(this, void 0, void 0, function* () {
1210
- const transformCircleToPolygon = (feature, geom) => {
1211
- const geomConverted = fromCircle(geom);
1212
- feature.setGeometry(geomConverted);
1213
- };
1214
- const transformGeoemtryCollectionToGeometries = (feature, geom) => {
1215
- let geomConverted = geom.getGeometries()[0];
1216
- if (geomConverted instanceof Circle$1) {
1217
- geomConverted = fromCircle(geomConverted);
1218
- }
1219
- feature.setGeometry(geomConverted);
1220
- };
1221
- features = Array.isArray(features) ? features : [features];
1222
- const cloneFeature = (feature) => {
1223
- this._removeFeatureFromEditList(feature);
1224
- const featureProperties = feature.getProperties();
1225
- delete featureProperties.boundedBy;
1226
- delete featureProperties._layerName_;
1227
- const clone = new Feature(featureProperties);
1228
- clone.setId(feature.getId());
1229
- return clone;
1230
- };
1231
- const refreshWmsLayer = (layer) => {
1232
- const source = layer.getSource();
1233
- // Refrescamos el wms
1234
- source.refresh();
1235
- // Force refresh the tiles
1236
- const params = source.getParams();
1237
- params.t = new Date().getMilliseconds();
1238
- source.updateParams(params);
1239
- };
1240
- const refreshWfsLayer = (layer) => {
1241
- const source = layer.getSource();
1242
- // Refrescamos el wms
1243
- source.refresh();
1244
- };
1245
- const clonedFeatures = [];
1246
- for (const feature of features) {
1247
- let clone = cloneFeature(feature);
1248
- const cloneGeom = clone.getGeometry();
1249
- // Ugly fix to support GeometryCollection on GML
1250
- // See https://github.com/openlayers/openlayers/issues/4220
1251
- if (cloneGeom instanceof GeometryCollection) {
1252
- transformGeoemtryCollectionToGeometries(clone, cloneGeom);
1253
- }
1254
- else if (cloneGeom instanceof Circle$1) {
1255
- // Geoserver has no Support to Circles
1256
- transformCircleToPolygon(clone, cloneGeom);
1257
- }
1258
- if (action === 'insert') {
1259
- // Filters
1260
- if (this._options.beforeInsertFeature) {
1261
- clone = this._options.beforeInsertFeature(clone);
1262
- }
1263
- }
1264
- if (clone) {
1265
- clonedFeatures.push(clone);
1266
- }
1267
- }
1268
- if (!clonedFeatures.length) {
1269
- this._showError(this._i18n.errors.noValidGeometry);
1270
- return false;
1271
- }
1272
- switch (action) {
1273
- case 'insert':
1274
- this._insertFeatures = [
1275
- ...this._insertFeatures,
1276
- ...clonedFeatures
1277
- ];
1278
- break;
1279
- case 'update':
1280
- this._updateFeatures = [
1281
- ...this._updateFeatures,
1282
- ...clonedFeatures
1283
- ];
1284
- break;
1285
- case 'delete':
1286
- this._deleteFeatures = [
1287
- ...this._deleteFeatures,
1288
- ...clonedFeatures
1289
- ];
1290
- break;
1291
- }
1292
- this._countRequests++;
1293
- const numberRequest = this._countRequests;
1294
- return new Promise((resolve, reject) => {
1295
- setTimeout(() => __awaiter(this, void 0, void 0, function* () {
1296
- try {
1297
- // Prevent fire multiples times
1298
- if (numberRequest !== this._countRequests) {
1299
- return;
1300
- }
1301
- let srs = this._view.getProjection().getCode();
1302
- // Force latitude/longitude order on transactions
1303
- // EPSG:4326 is longitude/latitude (assumption) and is not managed correctly by GML3
1304
- srs =
1305
- srs === 'EPSG:4326'
1306
- ? 'urn:x-ogc:def:crs:EPSG:4326'
1307
- : srs;
1308
- const geoLayer = this._geoServerData[layerName];
1309
- if (!geoLayer) {
1310
- throw new Error(this._i18n.errors.layerNotFound);
1311
- }
1312
- const options = {
1313
- featureNS: geoLayer.namespace,
1314
- featureType: layerName,
1315
- srsName: srs,
1316
- featurePrefix: null,
1317
- nativeElements: null,
1318
- version: this._options.geoServerAdvanced
1319
- .wfsTransactionVersion
1320
- };
1321
- const transaction = this._formatWFS.writeTransaction(this._insertFeatures, this._updateFeatures, this._deleteFeatures, options);
1322
- let payload = this._xs.serializeToString(transaction);
1323
- const geomType = geoLayer.geomType;
1324
- const geomField = geoLayer.geomField;
1325
- // Ugly fix to support GeometryCollection on GML
1326
- // See https://github.com/openlayers/openlayers/issues/4220
1327
- if (geomType === GeometryType.GeometryCollection) {
1328
- if (action === 'insert') {
1329
- payload = payload.replace(/<geometry>/g, `<geometry><MultiGeometry xmlns="http://www.opengis.net/gml" srsName="${srs}"><geometryMember>`);
1330
- payload = payload.replace(/<\/geometry>/g, `</geometryMember></MultiGeometry></geometry>`);
1331
- }
1332
- else if (action === 'update') {
1333
- const gmemberIn = `<MultiGeometry xmlns="http://www.opengis.net/gml" srsName="${srs}"><geometryMember>`;
1334
- const gmemberOut = `</geometryMember></MultiGeometry>`;
1335
- payload = payload.replace(/(.*)(<Name>geometry<\/Name><Value>)(.*?)(<\/Value>)(.*)/g, `$1$2${gmemberIn}$3${gmemberOut}$4$5`);
1336
- }
1337
- }
1338
- // Fixes geometry name, weird bug with GML:
1339
- // The property for the geometry column is always named "geometry"
1340
- if (action === 'insert') {
1341
- payload = payload.replace(/<(\/?)\bgeometry\b>/g, `<$1${geomField}>`);
1342
- }
1343
- else {
1344
- payload = payload.replace(/<Name>geometry<\/Name>/g, `<Name>${geomField}</Name>`);
1345
- }
1346
- // Add default LockId value
1347
- if (this._hasLockFeature &&
1348
- this._useLockFeature &&
1349
- action !== 'insert') {
1350
- payload = payload.replace(`</Transaction>`, `<LockId>GeoServer</LockId></Transaction>`);
1351
- }
1352
- const headers = Object.assign({ 'Content-Type': 'text/xml' }, this._options.headers);
1353
- const response = yield fetch(this._options.geoServerUrl, {
1354
- method: 'POST',
1355
- body: payload,
1356
- headers: headers,
1357
- credentials: this._options.credentials
1358
- });
1359
- if (!response.ok) {
1360
- throw new Error(this._i18n.errors.transaction +
1361
- ' ' +
1362
- response.status);
1363
- }
1364
- const parseResponse = this._formatWFS.readTransactionResponse(response);
1365
- if (!Object.keys(parseResponse).length) {
1366
- const responseStr = yield response.text();
1367
- const findError = String(responseStr).match(/<ows:ExceptionText>([\s\S]*?)<\/ows:ExceptionText>/);
1368
- if (findError) {
1369
- throw new Error(findError[1]);
1370
- }
1371
- }
1372
- if (action !== 'delete') {
1373
- for (const feature of features) {
1374
- this._editLayer.getSource().removeFeature(feature);
1375
- }
1376
- }
1377
- const { mode } = this._options.layers.find((layer) => layer.name === layerName);
1378
- if (mode === 'wfs') {
1379
- refreshWfsLayer(this._mapLayers[layerName]);
1380
- }
1381
- else if (mode === 'wms') {
1382
- refreshWmsLayer(this._mapLayers[layerName]);
1383
- }
1384
- this._hideLoading();
1385
- this._insertFeatures = [];
1386
- this._updateFeatures = [];
1387
- this._deleteFeatures = [];
1388
- this._countRequests = 0;
1389
- resolve(true);
1390
- }
1391
- catch (err) {
1392
- this._showError(err.message, err);
1393
- this._hideLoading();
1394
- this._countRequests = 0;
1395
- reject();
1396
- }
1397
- }), 0);
1398
- });
1399
- });
1400
- }
1401
- /**
1402
- *
1403
- * @param feature
1404
- * @private
1405
- */
1406
- _addFeatureToEditedList(feature) {
1407
- this._editedFeatures.add(String(feature.getId()));
1408
- }
1409
- /**
1410
- *
1411
- * @param feature
1412
- * @private
1413
- */
1414
- _removeFeatureFromEditList(feature) {
1415
- this._editedFeatures.delete(String(feature.getId()));
1416
- }
1417
- /**
1418
- *
1419
- * @param feature
1420
- * @private
1421
- */
1422
- _isFeatureEdited(feature) {
1423
- return this._editedFeatures.has(String(feature.getId()));
1424
- }
1425
- /**
1426
- *
1427
- * @param feature
1428
- * @private
1429
- */
1430
- _deselectEditFeature(feature) {
1431
- this._removeOverlayHelper(feature);
1432
- }
1433
- /**
1434
- *
1435
- * @param feature
1436
- * @param layerName
1437
- * @private
1438
- */
1439
- _restoreFeatureToLayer(feature, layerName) {
1440
- layerName = layerName || feature.get('_layerName_');
1441
- const layer = this._mapLayers[layerName];
1442
- layer.getSource().addFeature(feature);
1443
- }
1444
- /**
1445
- * @private
1446
- * @param feature
1447
- */
1448
- _removeFeatureFromTmpLayer(feature) {
1449
- // Remove element from the Layer
1450
- this._editLayer.getSource().removeFeature(feature);
1451
- }
1452
- /**
1453
- * Trigger on deselecting a feature from in the Edit layer
1454
- *
1455
- * @private
1456
- */
1457
- _onDeselectFeatureEvent() {
1458
- const checkIfFeatureIsChanged = (feature) => {
1459
- const layerName = feature.get('_layerName_');
1460
- const { mode } = this._options.layers.find((layer) => layer.name === layerName);
1461
- if (mode === 'wfs') {
1462
- this.interactionWfsSelect.getFeatures().remove(feature);
1463
- }
1464
- if (this._isFeatureEdited(feature)) {
1465
- this._transactWFS('update', feature, layerName);
1466
- }
1467
- else {
1468
- // Si es wfs y el elemento no tuvo cambios, lo devolvemos a la layer original
1469
- if (mode === 'wfs') {
1470
- this._restoreFeatureToLayer(feature, layerName);
1471
- }
1472
- this._removeFeatureFromTmpLayer(feature);
1473
- }
1474
- };
1475
- // This is fired when a feature is deselected and fires the transaction process
1476
- this._keySelect = this._collectionModify.on('remove', (evt) => {
1477
- const feature = evt.element;
1478
- this._deselectEditFeature(feature);
1479
- checkIfFeatureIsChanged(feature);
1480
- this._editModeOff();
1481
- });
1482
- }
1483
- /**
1484
- * Trigger on removing a feature from the Edit layer
1485
- *
1486
- * @private
1487
- */
1488
- _onRemoveFeatureEvent() {
1489
- // If a feature is removed from the edit layer
1490
- this._keyRemove = this._editLayer
1491
- .getSource()
1492
- .on('removefeature', (evt) => {
1493
- const feature = evt.feature;
1494
- if (!feature.get('_delete_')) {
1495
- return;
1496
- }
1497
- if (this._keySelect) {
1498
- unByKey(this._keySelect);
1499
- }
1500
- const layerName = feature.get('_layerName_');
1501
- this._transactWFS('delete', feature, layerName);
1502
- this._deselectEditFeature(feature);
1503
- this._editModeOff();
1504
- if (this._keySelect) {
1505
- setTimeout(() => {
1506
- this._onDeselectFeatureEvent();
1507
- }, 150);
1508
- }
1509
- });
1510
- }
1511
- /**
1512
- * Master style that handles two modes on the Edit Layer:
1513
- * - one is the basic, showing only the vertices
1514
- * - and the other when modify is active, showing bigger vertices
1515
- *
1516
- * @param feature
1517
- * @private
1518
- */
1519
- _styleFunction(feature) {
1520
- const getVertexs = (feature) => {
1521
- let geometry = feature.getGeometry();
1522
- if (geometry instanceof GeometryCollection) {
1523
- geometry = geometry.getGeometries()[0];
1524
- }
1525
- const coordinates = geometry.getCoordinates();
1526
- let flatCoordinates = null;
1527
- if (geometry instanceof Polygon ||
1528
- geometry instanceof MultiLineString) {
1529
- flatCoordinates = coordinates.flat(1);
1530
- }
1531
- else if (geometry instanceof MultiPolygon) {
1532
- flatCoordinates = coordinates.flat(2);
1533
- }
1534
- else {
1535
- flatCoordinates = coordinates;
1536
- }
1537
- if (!flatCoordinates || !flatCoordinates.length) {
1538
- return;
1539
- }
1540
- return new MultiPoint(flatCoordinates);
1541
- };
1542
- let geometry = feature.getGeometry();
1543
- let type = geometry.getType();
1544
- if (geometry instanceof GeometryCollection) {
1545
- geometry = geometry.getGeometries()[0];
1546
- type = geometry.getType();
1547
- }
1548
- switch (type) {
1549
- case GeometryType.Point:
1550
- case GeometryType.MultiPoint:
1551
- if (this._isEditModeOn) {
1552
- return [
1553
- new Style({
1554
- image: new Circle({
1555
- radius: 6,
1556
- fill: new Fill({
1557
- color: '#000000'
1558
- })
1559
- })
1560
- }),
1561
- new Style({
1562
- image: new Circle({
1563
- radius: 4,
1564
- fill: new Fill({
1565
- color: '#ff0000'
1566
- })
1567
- })
1568
- })
1569
- ];
1570
- }
1571
- else {
1572
- return [
1573
- new Style({
1574
- image: new Circle({
1575
- radius: 5,
1576
- fill: new Fill({
1577
- color: '#ff0000'
1578
- })
1579
- })
1580
- }),
1581
- new Style({
1582
- image: new Circle({
1583
- radius: 2,
1584
- fill: new Fill({
1585
- color: '#000000'
1586
- })
1587
- })
1588
- })
1589
- ];
1590
- }
1591
- default:
1592
- // If editing mode is active, show bigger vertex
1593
- if (this._isEditModeOn || this._isDrawModeOn) {
1594
- return [
1595
- new Style({
1596
- stroke: new Stroke({
1597
- color: 'rgba( 255, 0, 0, 1)',
1598
- width: 4
1599
- }),
1600
- fill: new Fill({
1601
- color: 'rgba(255, 0, 0, 0.7)'
1602
- })
1603
- }),
1604
- new Style({
1605
- image: new Circle({
1606
- radius: 4,
1607
- fill: new Fill({
1608
- color: '#ff0000'
1609
- }),
1610
- stroke: new Stroke({
1611
- width: 2,
1612
- color: 'rgba(5, 5, 5, 0.9)'
1613
- })
1614
- }),
1615
- geometry: (feature) => getVertexs(feature)
1616
- }),
1617
- new Style({
1618
- stroke: new Stroke({
1619
- color: 'rgba(255, 255, 255, 0.7)',
1620
- width: 2
1621
- })
1622
- })
1623
- ];
1624
- }
1625
- else {
1626
- return [
1627
- new Style({
1628
- image: new Circle({
1629
- radius: 2,
1630
- fill: new Fill({
1631
- color: '#000000'
1632
- })
1633
- }),
1634
- geometry: (feature) => getVertexs(feature)
1635
- }),
1636
- new Style({
1637
- stroke: new Stroke({
1638
- color: '#ff0000',
1639
- width: 4
1640
- }),
1641
- fill: new Fill({
1642
- color: 'rgba(255, 0, 0, 0.7)'
1643
- })
1644
- })
1645
- ];
1646
- }
1647
- }
1648
- }
1649
- /**
1650
- *
1651
- * @param feature
1652
- * @private
1653
- */
1654
- _editModeOn(feature) {
1655
- this._editFeatureOriginal = feature.clone();
1656
- this._isEditModeOn = true;
1657
- // To refresh the style
1658
- this._editLayer.getSource().changed();
1659
- this._removeOverlayHelper(feature);
1660
- const controlDiv = document.createElement('div');
1661
- controlDiv.className = 'ol-wfst--changes-control';
1662
- const elements = document.createElement('div');
1663
- elements.className = 'ol-wfst--changes-control-el';
1664
- const elementId = document.createElement('div');
1665
- elementId.className = 'ol-wfst--changes-control-id';
1666
- elementId.innerHTML = `<b>${this._i18n.labels.editMode}</b> - <i>${String(feature.getId())}</i>`;
1667
- const acceptButton = document.createElement('button');
1668
- acceptButton.type = 'button';
1669
- acceptButton.textContent = this._i18n.labels.apply;
1670
- acceptButton.className = 'btn btn-sm btn-primary';
1671
- acceptButton.onclick = () => {
1672
- this._showLoading();
1673
- this._collectionModify.remove(feature);
1674
- };
1675
- const cancelButton = document.createElement('button');
1676
- cancelButton.type = 'button';
1677
- cancelButton.textContent = this._i18n.labels.cancel;
1678
- cancelButton.className = 'btn btn-sm btn-secondary';
1679
- cancelButton.onclick = () => {
1680
- feature.setGeometry(this._editFeatureOriginal.getGeometry());
1681
- this._removeFeatureFromEditList(feature);
1682
- this._collectionModify.remove(feature);
1683
- };
1684
- const deleteButton = document.createElement('button');
1685
- deleteButton.type = 'button';
1686
- deleteButton.textContent = this._i18n.labels.delete;
1687
- deleteButton.className = 'btn btn-sm btn-danger-outline';
1688
- deleteButton.onclick = () => {
1689
- this._deleteFeature(feature, true);
1690
- };
1691
- elements.append(elementId);
1692
- elements.append(cancelButton);
1693
- elements.append(acceptButton);
1694
- elements.append(deleteButton);
1695
- controlDiv.append(elements);
1696
- this._controlApplyDiscardChanges = new Control({
1697
- element: controlDiv
1698
- });
1699
- this._map.addControl(this._controlApplyDiscardChanges);
1700
- }
1701
- /**
1702
- * @private
1703
- */
1704
- _editModeOff() {
1705
- this._isEditModeOn = false;
1706
- this._map.removeControl(this._controlApplyDiscardChanges);
1707
- }
1708
- /**
1709
- * Remove a feature from the edit Layer and from the Geoserver
1710
- *
1711
- * @param feature
1712
- * @private
1713
- */
1714
- _deleteFeature(feature, confirm) {
1715
- const deleteEl = () => {
1716
- const features = Array.isArray(feature) ? feature : [feature];
1717
- features.forEach((feature) => {
1718
- feature.set('_delete_', true, true);
1719
- this._editLayer.getSource().removeFeature(feature);
1720
- });
1721
- this._collectionModify.clear();
1722
- const layerName = feature.get('_layerName_');
1723
- const { mode } = this._options.layers.find((layer) => layer.name === layerName);
1724
- if (mode === 'wfs') {
1725
- this.interactionWfsSelect.getFeatures().remove(feature);
1726
- }
1727
- };
1728
- if (confirm) {
1729
- const confirmModal = Modal.confirm(this._i18n.labels.confirmDelete, Object.assign({}, this._options.modal));
1730
- confirmModal.show().once('dismiss', function (modal, ev, button) {
1731
- if (button && button.value) {
1732
- deleteEl();
1733
- }
1734
- });
1735
- }
1736
- else {
1737
- deleteEl();
1738
- }
1739
- }
1740
- /**
1741
- * Add a feature to the Edit Layer to allow editing, and creates an Overlay Helper to show options
1742
- *
1743
- * @param feature
1744
- * @param coordinate
1745
- * @param layerName
1746
- * @private
1747
- */
1748
- _addFeatureToEdit(feature, coordinate = null, layerName = null) {
1749
- const prepareOverlay = () => {
1750
- const svgFields = `<img src="${img$1}"/>`;
1751
- const editFieldsEl = document.createElement('div');
1752
- editFieldsEl.className = 'ol-wfst--edit-button-cnt';
1753
- editFieldsEl.innerHTML = `<button class="ol-wfst--edit-button" type="button" title="${this._i18n.labels.editFields}">${svgFields}</button>`;
1754
- editFieldsEl.onclick = () => {
1755
- this._initEditFieldsModal(feature);
1756
- };
1757
- const buttons = document.createElement('div');
1758
- buttons.append(editFieldsEl);
1759
- const svgGeom = `<img src="${img$2}"/>`;
1760
- const editGeomEl = document.createElement('div');
1761
- editGeomEl.className = 'ol-wfst--edit-button-cnt';
1762
- editGeomEl.innerHTML = `<button class="ol-wfst--edit-button" type="button" title="${this._i18n.labels.editGeom}">${svgGeom}</button>`;
1763
- editGeomEl.onclick = () => {
1764
- this._editModeOn(feature);
1765
- };
1766
- buttons.append(editGeomEl);
1767
- const position = coordinate || getCenter(feature.getGeometry().getExtent());
1768
- const buttonsOverlay = new Overlay({
1769
- id: feature.getId(),
1770
- position: position,
1771
- positioning: 'center-center',
1772
- element: buttons,
1773
- offset: [0, -40],
1774
- stopEvent: true
1775
- });
1776
- this._map.addOverlay(buttonsOverlay);
1777
- };
1778
- if (layerName) {
1779
- // Guardamos el nombre de la capa de donde sale la feature
1780
- feature.set('_layerName_', layerName);
1781
- }
1782
- const props = feature ? feature.getProperties() : '';
1783
- if (props) {
1784
- if (feature.getGeometry()) {
1785
- this._editLayer.getSource().addFeature(feature);
1786
- this._collectionModify.push(feature);
1787
- prepareOverlay();
1788
- if (this._useLockFeature && this._hasLockFeature) {
1789
- this._lockFeature(feature.getId(), feature.get('_layerName_'));
1790
- }
1791
- }
1792
- }
1793
- }
1794
- /**
1795
- * Removes in the DOM the class of the tools
1796
- * @private
1797
- */
1798
- _resetStateButtons() {
1799
- const activeBtn = document.querySelector('.ol-wfst--tools-control-btn.wfst--active');
1800
- if (activeBtn) {
1801
- activeBtn.classList.remove('wfst--active');
1802
- }
1803
- }
1804
- /**
1805
- * Confirm modal before transact to the GeoServer the features in the file
1806
- *
1807
- * @param content
1808
- * @param featureToInsert
1809
- * @private
1810
- */
1811
- _initUploadFileModal(content, featuresToInsert) {
1812
- const footer = `
1813
- <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">
1814
- ${this._i18n.labels.cancel}
1815
- </button>
1816
- <button type="button" class="btn btn-sm btn-primary" data-action="save" data-dismiss="modal">
1817
- ${this._i18n.labels.upload}
1818
- </button>
1819
- `;
1820
- const modal = new Modal(Object.assign(Object.assign({}, this._options.modal), { header: true, headerClose: false, title: this._i18n.labels.uploadFeatures +
1821
- ' ' +
1822
- this._layerToInsertElements, content: content, backdrop: 'static', footer: footer })).show();
1823
- modal.on('dismiss', (modal, event) => {
1824
- // On saving changes
1825
- if (event.target.dataset.action === 'save') {
1826
- this._transactWFS('insert', featuresToInsert, this._layerToInsertElements);
1827
- }
1828
- else {
1829
- // On cancel button
1830
- this._editLayer.getSource().clear();
1831
- }
1832
- });
1833
- }
1834
- /**
1835
- * Parse and check geometry of uploaded files
1836
- *
1837
- * @param evt
1838
- * @private
1839
- */
1840
- _processUploadFile(evt) {
1841
- return __awaiter(this, void 0, void 0, function* () {
1842
- /**
1843
- * Read data file
1844
- * @param file
1845
- * @private
1846
- */
1847
- const fileReader = (file) => {
1848
- return new Promise((resolve, reject) => {
1849
- const reader = new FileReader();
1850
- reader.addEventListener('load', (e) => __awaiter(this, void 0, void 0, function* () {
1851
- const fileData = e.target.result;
1852
- resolve(fileData);
1853
- }));
1854
- reader.addEventListener('error', (err) => {
1855
- console.error('Error' + err);
1856
- reject();
1857
- });
1858
- reader.readAsText(file);
1859
- });
1860
- };
1861
- /**
1862
- * Attemp to change the geometry feature to the layer
1863
- * @param feature
1864
- * @private
1865
- */
1866
- const fixGeometry = (feature) => {
1867
- // Geometry of the layer
1868
- const geomTypeLayer = this._geoServerData[this._layerToInsertElements].geomType;
1869
- const geomTypeFeature = feature.getGeometry().getType();
1870
- let geom;
1871
- switch (geomTypeFeature) {
1872
- case 'Point': {
1873
- if (geomTypeLayer === 'MultiPoint') {
1874
- const coords = feature.getGeometry().getCoordinates();
1875
- geom = new MultiPoint([coords]);
1876
- }
1877
- break;
1878
- }
1879
- case 'LineString':
1880
- if (geomTypeLayer === 'MultiLineString') {
1881
- const coords = feature.getGeometry().getCoordinates();
1882
- geom = new MultiLineString([coords]);
1883
- }
1884
- break;
1885
- case 'Polygon':
1886
- if (geomTypeLayer === 'MultiPolygon') {
1887
- const coords = feature.getGeometry().getCoordinates();
1888
- geom = new MultiPolygon([coords]);
1889
- }
1890
- break;
1891
- default:
1892
- geom = null;
1893
- }
1894
- if (!geom) {
1895
- return null;
1896
- }
1897
- feature.setGeometry(geom);
1898
- return feature;
1899
- };
1900
- /**
1901
- * Check if the feature has the same geometry as the target layer
1902
- * @param feature
1903
- * @private
1904
- */
1905
- const checkGeometry = (feature) => {
1906
- // Geometry of the layer
1907
- const geomTypeLayer = this._geoServerData[this._layerToInsertElements].geomType;
1908
- const geomTypeFeature = feature.getGeometry().getType();
1909
- // This geom accepts every type of geometry
1910
- if (geomTypeLayer === GeometryType.GeometryCollection) {
1911
- return true;
1912
- }
1913
- return geomTypeFeature === geomTypeLayer;
1914
- };
1915
- const file = evt.target.files[0];
1916
- let features;
1917
- if (!file) {
1918
- return;
1919
- }
1920
- const extension = file.name.split('.').pop().toLowerCase();
1921
- try {
1922
- // If the user uses a custom fucntion...
1923
- if (this._options.processUpload) {
1924
- features = this._options.processUpload(file);
1925
- }
1926
- // If the user functions return features, we dont process anything more
1927
- if (!features) {
1928
- const string = yield fileReader(file);
1929
- if (extension === 'geojson' || extension === 'json') {
1930
- features = this._formatGeoJSON.readFeatures(string, {
1931
- featureProjection: this._view.getProjection().getCode()
1932
- });
1933
- }
1934
- else if (extension === 'kml') {
1935
- features = this._formatKml.readFeatures(string, {
1936
- featureProjection: this._view.getProjection().getCode()
1937
- });
1938
- }
1939
- else {
1940
- this._showError(this._i18n.errors.badFormat);
1941
- }
1942
- }
1943
- }
1944
- catch (err) {
1945
- this._showError(this._i18n.errors.badFile, err);
1946
- }
1947
- let invalidFeaturesCount = 0;
1948
- let validFeaturesCount = 0;
1949
- const featuresToInsert = [];
1950
- for (let feature of features) {
1951
- // If the geometry doesn't correspond to the layer, try to fixit.
1952
- // If we can't, don't use it
1953
- if (!checkGeometry(feature)) {
1954
- feature = fixGeometry(feature);
1955
- }
1956
- if (feature) {
1957
- featuresToInsert.push(feature);
1958
- validFeaturesCount++;
1959
- }
1960
- else {
1961
- invalidFeaturesCount++;
1962
- continue;
1963
- }
1964
- }
1965
- if (!validFeaturesCount) {
1966
- this._showError(this._i18n.errors.noValidGeometry);
1967
- }
1968
- else {
1969
- this._resetStateButtons();
1970
- this.activateEditMode();
1971
- const content = `
1972
- ${this._i18n.labels.validFeatures}: ${validFeaturesCount}<br>
1973
- ${invalidFeaturesCount
1974
- ? `${this._i18n.labels.invalidFeatures}: ${invalidFeaturesCount}`
1975
- : ''}
1976
- `;
1977
- this._editLayer.getSource().addFeatures(featuresToInsert);
1978
- this._initUploadFileModal(content, featuresToInsert);
1979
- this._view.fit(this._editLayer.getSource().getExtent(), {
1980
- size: this._map.getSize(),
1981
- maxZoom: 21,
1982
- padding: [100, 100, 100, 100]
1983
- });
1984
- }
1985
- // Reset the input to allow another onChange trigger
1986
- evt.target.value = null;
1987
- });
1988
- }
1989
- /**
1990
- * Update geom Types availibles to select for this layer
1991
- *
1992
- * @param layerName
1993
- * @param geomDrawTypeSelected
1994
- * @private
1995
- */
1996
- _changeStateSelect(layerName, geomDrawTypeSelected = null) {
1997
- /**
1998
- * Set the geometry type in the select according to the geometry of
1999
- * the layer in the geoserver and disable what does not correspond.
2000
- *
2001
- * @param value
2002
- * @param options
2003
- * @private
2004
- */
2005
- const setSelectState = (value, options) => {
2006
- Array.from(this._selectDraw.options).forEach((option) => {
2007
- option.selected = option.value === value ? true : false;
2008
- option.disabled =
2009
- options === 'all'
2010
- ? false
2011
- : options.includes(option.value)
2012
- ? false
2013
- : true;
2014
- option.title = option.disabled
2015
- ? this._i18n.labels.geomTypeNotSupported
2016
- : '';
2017
- });
2018
- };
2019
- let drawType;
2020
- if (this._selectDraw) {
2021
- const geomLayer = this._geoServerData[layerName].geomType;
2022
- if (geomDrawTypeSelected) {
2023
- drawType = this._selectDraw.value;
2024
- }
2025
- else {
2026
- if (geomLayer === GeometryType.GeometryCollection) {
2027
- drawType = GeometryType.LineString; // Default drawing type for GeometryCollection
2028
- setSelectState(drawType, 'all');
2029
- }
2030
- else if (geomLayer === GeometryType.LinearRing) {
2031
- drawType = GeometryType.LineString; // Default drawing type for GeometryCollection
2032
- setSelectState(drawType, [
2033
- GeometryType.Circle,
2034
- GeometryType.LinearRing,
2035
- GeometryType.Polygon
2036
- ]);
2037
- this._selectDraw.value = drawType;
2038
- }
2039
- else {
2040
- drawType = geomLayer;
2041
- setSelectState(drawType, [geomLayer]);
2042
- }
2043
- }
2044
- }
2045
- return drawType;
2046
- }
2047
- /**
2048
- * Activate/deactivate the draw mode
2049
- *
2050
- * @param layerName
2051
- * @public
2052
- */
2053
- activateDrawMode(layerName) {
2054
- /**
2055
- *
2056
- * @param layerName
2057
- * @private
2058
- */
2059
- const addDrawInteraction = (layerName) => {
2060
- this.activateEditMode(false);
2061
- // If already exists, remove
2062
- if (this.interactionDraw) {
2063
- this._map.removeInteraction(this.interactionDraw);
2064
- }
2065
- const geomDrawType = this._selectDraw.value;
2066
- this.interactionDraw = new Draw({
2067
- source: this._editLayer.getSource(),
2068
- type: geomDrawType,
2069
- style: (feature) => this._styleFunction(feature)
2070
- });
2071
- this._map.addInteraction(this.interactionDraw);
2072
- this.interactionDraw.on('drawstart', (evt) => {
2073
- super.dispatchEvent(evt);
2074
- });
2075
- this.interactionDraw.on('drawend', (evt) => {
2076
- const feature = evt.feature;
2077
- this._transactWFS('insert', feature, layerName);
2078
- super.dispatchEvent(evt);
2079
- });
2080
- };
2081
- if (!this.interactionDraw && !layerName) {
2082
- return;
2083
- }
2084
- if (layerName) {
2085
- // If layer is set to invisible, show warning
2086
- if (!this._mapLayers[layerName].getVisible()) {
2087
- return;
2088
- }
2089
- const btn = document.querySelector('.ol-wfst--tools-control-btn-draw');
2090
- if (btn) {
2091
- btn.classList.add('wfst--active');
2092
- }
2093
- this._viewport.classList.add('draw-mode');
2094
- addDrawInteraction(String(layerName));
2095
- }
2096
- else {
2097
- this._map.removeInteraction(this.interactionDraw);
2098
- this._viewport.classList.remove('draw-mode');
2099
- }
2100
- this._isDrawModeOn = layerName ? true : false;
2101
- }
2102
- /**
2103
- * Activate/desactivate the edit mode
2104
- *
2105
- * @param bool
2106
- * @public
2107
- */
2108
- activateEditMode(bool = true) {
2109
- if (bool) {
2110
- const btn = document.querySelector('.ol-wfst--tools-control-btn-edit');
2111
- if (btn) {
2112
- btn.classList.add('wfst--active');
2113
- }
2114
- this.activateDrawMode(false);
2115
- }
2116
- else {
2117
- // Deselct features
2118
- this._collectionModify.clear();
2119
- }
2120
- if (this.interactionSelectModify) {
2121
- this.interactionSelectModify.setActive(bool);
2122
- }
2123
- this.interactionModify.setActive(bool);
2124
- if (this.interactionWfsSelect)
2125
- this.interactionWfsSelect.setActive(bool);
2126
- }
2127
- /**
2128
- *
2129
- * Add features directly to the geoserver, in a custom layer
2130
- * without checking geometry or showing modal to confirm.
2131
- * Returns `true` if features are inserted correctly
2132
- *
2133
- * @param layerName
2134
- * @param features
2135
- * @returns
2136
- */
2137
- insertFeaturesTo(layerName, features) {
2138
- return __awaiter(this, void 0, void 0, function* () {
2139
- return yield this._transactWFS('insert', features, layerName);
2140
- });
2141
- }
2142
- /**
2143
- * Shows a fields form in a modal window to allow changes in the properties of the feature.
2144
- *
2145
- * @param feature
2146
- * @private
2147
- */
2148
- _initEditFieldsModal(feature) {
2149
- this._editFeature = feature;
2150
- const properties = feature.getProperties();
2151
- const layer = feature.get('_layerName_');
2152
- // Data schema from the geoserver
2153
- const dataSchema = this._geoServerData[layer].properties;
2154
- let content = '<form autocomplete="false">';
2155
- Object.keys(properties).forEach((key) => {
2156
- // If the feature field exists in the geoserver and is not added by openlayers
2157
- const field = dataSchema.find((data) => data.name === key);
2158
- if (field) {
2159
- const typeXsd = field.type;
2160
- let type;
2161
- switch (typeXsd) {
2162
- case 'xsd:string':
2163
- type = 'text';
2164
- break;
2165
- case 'xsd:number':
2166
- case 'xsd:int':
2167
- type = 'number';
2168
- break;
2169
- case 'xsd:date-time':
2170
- type = 'datetime';
2171
- break;
2172
- default:
2173
- type = 'text';
2174
- }
2175
- if (type) {
2176
- content += `
2177
- <div class="ol-wfst--input-field-container">
2178
- <label class="ol-wfst--input-field-label" for="${key}">${key}</label>
2179
- <input placeholder="NULL" class="ol-wfst--input-field-input" type="${type}" name="${key}" value="${properties[key] || ''}">
2180
- </div>`;
2181
- }
2182
- }
2183
- });
2184
- content += '</form>';
2185
- const footer = `
2186
- <button type="button" class="btn btn-sm btn-link btn-third" data-action="delete" data-dismiss="modal">
2187
- ${this._i18n.labels.delete}
2188
- </button>
2189
- <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">
2190
- ${this._i18n.labels.cancel}
2191
- </button>
2192
- <button type="button" class="btn btn-sm btn-primary" data-action="save" data-dismiss="modal">
2193
- ${this._i18n.labels.save}
2194
- </button>
2195
- `;
2196
- const modal = new Modal(Object.assign(Object.assign({}, this._options.modal), { header: true, headerClose: true, title: `${this._i18n.labels.editElement} ${this._editFeature.getId()} `, content: content, footer: footer })).show();
2197
- modal.on('dismiss', (modal, event) => {
2198
- // On saving changes
2199
- if (event.target.dataset.action === 'save') {
2200
- const inputs = modal.el.querySelectorAll('input');
2201
- inputs.forEach((el) => {
2202
- const value = el.value;
2203
- const field = el.name;
2204
- this._editFeature.set(field, value, /*isSilent = */ true);
2205
- });
2206
- this._editFeature.changed();
2207
- this._addFeatureToEditedList(this._editFeature);
2208
- // Force deselect to trigger handler
2209
- this._collectionModify.remove(this._editFeature);
2210
- }
2211
- else if (event.target.dataset.action === 'delete') {
2212
- this._deleteFeature(this._editFeature, true);
2213
- }
2214
- });
2215
- }
2216
- /**
2217
- * Remove the overlay helper atttached to a specify feature
2218
- * @param feature
2219
- * @private
2220
- */
2221
- _removeOverlayHelper(feature) {
2222
- const featureId = feature.getId();
2223
- if (!featureId) {
2224
- return;
2225
- }
2226
- const overlay = this._map.getOverlayById(featureId);
2227
- if (!overlay) {
2228
- return;
2229
- }
2230
- this._map.removeOverlay(overlay);
2231
- }
2232
- }
2233
- /**
2234
- *
2235
- * @param target
2236
- * @param sources
2237
- * @returns
2238
- * @private
2239
- */
2240
- const deepObjectAssign = (target, ...sources) => {
2241
- sources.forEach((source) => {
2242
- Object.keys(source).forEach((key) => {
2243
- const s_val = source[key];
2244
- const t_val = target[key];
2245
- target[key] =
2246
- t_val &&
2247
- s_val &&
2248
- typeof t_val === 'object' &&
2249
- typeof s_val === 'object' &&
2250
- !Array.isArray(t_val) // Don't merge arrays
2251
- ? deepObjectAssign(t_val, s_val)
2252
- : s_val;
2253
- });
2254
- });
2255
- return target;
2256
- };
2257
-
2258
- export default Wfst;
2259
- //# sourceMappingURL=ol-wfst.js.map