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