ol-wfst 3.0.3 → 3.0.4
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/README.md +505 -478
- package/dist/assets/i18n/en.d.ts.map +1 -1
- package/dist/assets/i18n/es.d.ts.map +1 -1
- package/dist/assets/i18n/zh.d.ts.map +1 -1
- package/dist/ol-wfst.d.ts +6 -3
- package/dist/ol-wfst.d.ts.map +1 -1
- package/dist/ol-wfst.js +109 -86
- package/dist/ol-wfst.js.map +1 -1
- package/dist/ol-wfst.min.js +1 -1
- package/dist/ol-wfst.min.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/assets/i18n/en.d.ts.map +1 -1
- package/lib/assets/i18n/es.d.ts.map +1 -1
- package/lib/assets/i18n/zh.d.ts.map +1 -1
- package/lib/ol-wfst.d.ts +6 -3
- package/lib/ol-wfst.d.ts.map +1 -1
- package/lib/ol-wfst.js +109 -86
- package/lib/ol-wfst.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/lib/ol-wfst.js
CHANGED
|
@@ -93,6 +93,7 @@ const es = {
|
|
|
93
93
|
capabilities: 'No se pudieron obtener las Capabilidades del GeoServer',
|
|
94
94
|
wfst: 'El GeoServer no tiene soporte a Transacciones',
|
|
95
95
|
layer: 'No se pudieron obtener datos de la capa',
|
|
96
|
+
layerNotFound: 'CApa no encontrada',
|
|
96
97
|
noValidGeometry: 'No se encontraron geometrías válidas para agregar a esta capa',
|
|
97
98
|
geoserver: 'No se pudieron obtener datos desde el GeoServer',
|
|
98
99
|
badFormat: 'Formato no soportado',
|
|
@@ -131,6 +132,7 @@ const en = {
|
|
|
131
132
|
capabilities: 'GeoServer Capabilities could not be downloaded.',
|
|
132
133
|
wfst: 'The GeoServer does not support Transactions',
|
|
133
134
|
layer: 'Could not get data from layer',
|
|
135
|
+
layerNotFound: 'Layer not found',
|
|
134
136
|
noValidGeometry: 'No valid geometries found to add to this layer',
|
|
135
137
|
geoserver: 'Could not get data from the GeoServer',
|
|
136
138
|
badFormat: 'Unsupported format',
|
|
@@ -169,6 +171,7 @@ const zh = {
|
|
|
169
171
|
capabilities: '无法加载GeoServer服务所支持的能力.',
|
|
170
172
|
wfst: 'GeoServer不支持事务',
|
|
171
173
|
layer: '无法从图层获得数据',
|
|
174
|
+
layerNotFound: 'Layer not found',
|
|
172
175
|
noValidGeometry: '不支持的几何类型无法加载到图层',
|
|
173
176
|
geoserver: '无法从GeoServer获取数据',
|
|
174
177
|
badFormat: '不支持的格式',
|
|
@@ -1263,7 +1266,8 @@ class Wfst extends Control {
|
|
|
1263
1266
|
}
|
|
1264
1267
|
}
|
|
1265
1268
|
if (!clonedFeatures.length) {
|
|
1266
|
-
|
|
1269
|
+
this._showError(this._i18n.errors.noValidGeometry);
|
|
1270
|
+
return false;
|
|
1267
1271
|
}
|
|
1268
1272
|
switch (action) {
|
|
1269
1273
|
case 'insert':
|
|
@@ -1287,96 +1291,111 @@ class Wfst extends Control {
|
|
|
1287
1291
|
}
|
|
1288
1292
|
this._countRequests++;
|
|
1289
1293
|
const numberRequest = this._countRequests;
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1294
|
+
return new Promise((resolve, reject) => {
|
|
1295
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
1296
|
+
try {
|
|
1297
|
+
// Prevent fire multiples times
|
|
1298
|
+
if (numberRequest !== this._countRequests) {
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
let srs = this._view.getProjection().getCode();
|
|
1302
|
+
// Force latitude/longitude order on transactions
|
|
1303
|
+
// EPSG:4326 is longitude/latitude (assumption) and is not managed correctly by GML3
|
|
1304
|
+
srs =
|
|
1305
|
+
srs === 'EPSG:4326'
|
|
1306
|
+
? 'urn:x-ogc:def:crs:EPSG:4326'
|
|
1307
|
+
: srs;
|
|
1308
|
+
const geoLayer = this._geoServerData[layerName];
|
|
1309
|
+
if (!geoLayer) {
|
|
1310
|
+
throw new Error(this._i18n.errors.layerNotFound);
|
|
1311
|
+
}
|
|
1312
|
+
const options = {
|
|
1313
|
+
featureNS: geoLayer.namespace,
|
|
1314
|
+
featureType: layerName,
|
|
1315
|
+
srsName: srs,
|
|
1316
|
+
featurePrefix: null,
|
|
1317
|
+
nativeElements: null,
|
|
1318
|
+
version: this._options.geoServerAdvanced
|
|
1319
|
+
.wfsTransactionVersion
|
|
1320
|
+
};
|
|
1321
|
+
const transaction = this._formatWFS.writeTransaction(this._insertFeatures, this._updateFeatures, this._deleteFeatures, options);
|
|
1322
|
+
let payload = this._xs.serializeToString(transaction);
|
|
1323
|
+
const geomType = geoLayer.geomType;
|
|
1324
|
+
const geomField = geoLayer.geomField;
|
|
1325
|
+
// Ugly fix to support GeometryCollection on GML
|
|
1326
|
+
// See https://github.com/openlayers/openlayers/issues/4220
|
|
1327
|
+
if (geomType === GeometryType.GeometryCollection) {
|
|
1328
|
+
if (action === 'insert') {
|
|
1329
|
+
payload = payload.replace(/<geometry>/g, `<geometry><MultiGeometry xmlns="http://www.opengis.net/gml" srsName="${srs}"><geometryMember>`);
|
|
1330
|
+
payload = payload.replace(/<\/geometry>/g, `</geometryMember></MultiGeometry></geometry>`);
|
|
1331
|
+
}
|
|
1332
|
+
else if (action === 'update') {
|
|
1333
|
+
const gmemberIn = `<MultiGeometry xmlns="http://www.opengis.net/gml" srsName="${srs}"><geometryMember>`;
|
|
1334
|
+
const gmemberOut = `</geometryMember></MultiGeometry>`;
|
|
1335
|
+
payload = payload.replace(/(.*)(<Name>geometry<\/Name><Value>)(.*?)(<\/Value>)(.*)/g, `$1$2${gmemberIn}$3${gmemberOut}$4$5`);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
// Fixes geometry name, weird bug with GML:
|
|
1339
|
+
// The property for the geometry column is always named "geometry"
|
|
1316
1340
|
if (action === 'insert') {
|
|
1317
|
-
payload = payload.replace(/<
|
|
1318
|
-
payload = payload.replace(/<\/geometry>/g, `</geometryMember></MultiGeometry></geometry>`);
|
|
1341
|
+
payload = payload.replace(/<(\/?)\bgeometry\b>/g, `<$1${geomField}>`);
|
|
1319
1342
|
}
|
|
1320
|
-
else
|
|
1321
|
-
|
|
1322
|
-
const gmemberOut = `</geometryMember></MultiGeometry>`;
|
|
1323
|
-
payload = payload.replace(/(.*)(<Name>geometry<\/Name><Value>)(.*?)(<\/Value>)(.*)/g, `$1$2${gmemberIn}$3${gmemberOut}$4$5`);
|
|
1343
|
+
else {
|
|
1344
|
+
payload = payload.replace(/<Name>geometry<\/Name>/g, `<Name>${geomField}</Name>`);
|
|
1324
1345
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
}
|
|
1331
|
-
else {
|
|
1332
|
-
payload = payload.replace(/<Name>geometry<\/Name>/g, `<Name>${geomField}</Name>`);
|
|
1333
|
-
}
|
|
1334
|
-
// Add default LockId value
|
|
1335
|
-
if (this._hasLockFeature &&
|
|
1336
|
-
this._useLockFeature &&
|
|
1337
|
-
action !== 'insert') {
|
|
1338
|
-
payload = payload.replace(`</Transaction>`, `<LockId>GeoServer</LockId></Transaction>`);
|
|
1339
|
-
}
|
|
1340
|
-
const headers = Object.assign({ 'Content-Type': 'text/xml' }, this._options.headers);
|
|
1341
|
-
const response = yield fetch(this._options.geoServerUrl, {
|
|
1342
|
-
method: 'POST',
|
|
1343
|
-
body: payload,
|
|
1344
|
-
headers: headers,
|
|
1345
|
-
credentials: this._options.credentials
|
|
1346
|
-
});
|
|
1347
|
-
if (!response.ok) {
|
|
1348
|
-
throw new Error(this._i18n.errors.transaction + ' ' + response.status);
|
|
1349
|
-
}
|
|
1350
|
-
const parseResponse = this._formatWFS.readTransactionResponse(response);
|
|
1351
|
-
if (!Object.keys(parseResponse).length) {
|
|
1352
|
-
const responseStr = yield response.text();
|
|
1353
|
-
const findError = String(responseStr).match(/<ows:ExceptionText>([\s\S]*?)<\/ows:ExceptionText>/);
|
|
1354
|
-
if (findError) {
|
|
1355
|
-
this._showError(findError[1]);
|
|
1346
|
+
// Add default LockId value
|
|
1347
|
+
if (this._hasLockFeature &&
|
|
1348
|
+
this._useLockFeature &&
|
|
1349
|
+
action !== 'insert') {
|
|
1350
|
+
payload = payload.replace(`</Transaction>`, `<LockId>GeoServer</LockId></Transaction>`);
|
|
1356
1351
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1352
|
+
const headers = Object.assign({ 'Content-Type': 'text/xml' }, this._options.headers);
|
|
1353
|
+
const response = yield fetch(this._options.geoServerUrl, {
|
|
1354
|
+
method: 'POST',
|
|
1355
|
+
body: payload,
|
|
1356
|
+
headers: headers,
|
|
1357
|
+
credentials: this._options.credentials
|
|
1358
|
+
});
|
|
1359
|
+
if (!response.ok) {
|
|
1360
|
+
throw new Error(this._i18n.errors.transaction +
|
|
1361
|
+
' ' +
|
|
1362
|
+
response.status);
|
|
1361
1363
|
}
|
|
1364
|
+
const parseResponse = this._formatWFS.readTransactionResponse(response);
|
|
1365
|
+
if (!Object.keys(parseResponse).length) {
|
|
1366
|
+
const responseStr = yield response.text();
|
|
1367
|
+
const findError = String(responseStr).match(/<ows:ExceptionText>([\s\S]*?)<\/ows:ExceptionText>/);
|
|
1368
|
+
if (findError) {
|
|
1369
|
+
throw new Error(findError[1]);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
if (action !== 'delete') {
|
|
1373
|
+
for (const feature of features) {
|
|
1374
|
+
this._editLayer.getSource().removeFeature(feature);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
const { mode } = this._options.layers.find((layer) => layer.name === layerName);
|
|
1378
|
+
if (mode === 'wfs') {
|
|
1379
|
+
refreshWfsLayer(this._mapLayers[layerName]);
|
|
1380
|
+
}
|
|
1381
|
+
else if (mode === 'wms') {
|
|
1382
|
+
refreshWmsLayer(this._mapLayers[layerName]);
|
|
1383
|
+
}
|
|
1384
|
+
this._hideLoading();
|
|
1385
|
+
this._insertFeatures = [];
|
|
1386
|
+
this._updateFeatures = [];
|
|
1387
|
+
this._deleteFeatures = [];
|
|
1388
|
+
this._countRequests = 0;
|
|
1389
|
+
resolve(true);
|
|
1362
1390
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
refreshWmsLayer(this._mapLayers[layerName]);
|
|
1391
|
+
catch (err) {
|
|
1392
|
+
this._showError(err.message, err);
|
|
1393
|
+
this._hideLoading();
|
|
1394
|
+
this._countRequests = 0;
|
|
1395
|
+
reject();
|
|
1369
1396
|
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
catch (err) {
|
|
1373
|
-
this._showError(err.message, err);
|
|
1374
|
-
}
|
|
1375
|
-
this._insertFeatures = [];
|
|
1376
|
-
this._updateFeatures = [];
|
|
1377
|
-
this._deleteFeatures = [];
|
|
1378
|
-
this._countRequests = 0;
|
|
1379
|
-
}), 0);
|
|
1397
|
+
}), 0);
|
|
1398
|
+
});
|
|
1380
1399
|
});
|
|
1381
1400
|
}
|
|
1382
1401
|
/**
|
|
@@ -2106,15 +2125,19 @@ class Wfst extends Control {
|
|
|
2106
2125
|
this.interactionWfsSelect.setActive(bool);
|
|
2107
2126
|
}
|
|
2108
2127
|
/**
|
|
2128
|
+
*
|
|
2109
2129
|
* Add features directly to the geoserver, in a custom layer
|
|
2110
2130
|
* without checking geometry or showing modal to confirm.
|
|
2131
|
+
* Returns `true` if features are inserted correctly
|
|
2111
2132
|
*
|
|
2112
2133
|
* @param layerName
|
|
2113
2134
|
* @param features
|
|
2114
|
-
* @
|
|
2135
|
+
* @returns
|
|
2115
2136
|
*/
|
|
2116
2137
|
insertFeaturesTo(layerName, features) {
|
|
2117
|
-
this
|
|
2138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2139
|
+
return yield this._transactWFS('insert', features, layerName);
|
|
2140
|
+
});
|
|
2118
2141
|
}
|
|
2119
2142
|
/**
|
|
2120
2143
|
* Shows a fields form in a modal window to allow changes in the properties of the feature.
|