Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,19 +1,32 @@
|
||||
/**
|
||||
* @module ol/format/WFS
|
||||
*/
|
||||
import {assert} from '../asserts.js';
|
||||
import GML2 from './GML2.js';
|
||||
import GML3 from './GML3.js';
|
||||
import GMLBase, {GMLNS} from './GMLBase.js';
|
||||
import {and as andFilter, bbox as bboxFilter} from './filter.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import {readNonNegativeIntegerString, readNonNegativeInteger, writeStringTextNode} from './xsd.js';
|
||||
import {
|
||||
XML_SCHEMA_INSTANCE_URI,
|
||||
createElementNS,
|
||||
isDocument,
|
||||
makeArrayPusher,
|
||||
makeChildAppender,
|
||||
makeObjectPropertySetter,
|
||||
makeSimpleNodeFactory,
|
||||
parse,
|
||||
parseNode,
|
||||
pushParseAndPop,
|
||||
pushSerializeAndPop,
|
||||
} from '../xml.js';
|
||||
import {and as andFilter, bbox as bboxFilter} from './filter.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {assign} from '../obj.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {createElementNS, isDocument, makeArrayPusher, makeChildAppender,
|
||||
makeObjectPropertySetter, makeSimpleNodeFactory, parse, parseNode,
|
||||
pushParseAndPop, pushSerializeAndPop, XML_SCHEMA_INSTANCE_URI} from '../xml.js';
|
||||
|
||||
import {
|
||||
readNonNegativeInteger,
|
||||
readNonNegativeIntegerString,
|
||||
writeStringTextNode,
|
||||
} from './xsd.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -22,11 +35,12 @@ import {createElementNS, isDocument, makeArrayPusher, makeChildAppender,
|
||||
const FEATURE_COLLECTION_PARSERS = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'boundedBy': makeObjectPropertySetter(
|
||||
GMLBase.prototype.readGeometryElement, 'bounds')
|
||||
}
|
||||
GMLBase.prototype.readGeometryElement,
|
||||
'bounds'
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -35,11 +49,10 @@ const TRANSACTION_SUMMARY_PARSERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'totalInserted': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'totalUpdated': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger)
|
||||
}
|
||||
'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
@@ -47,23 +60,22 @@ const TRANSACTION_SUMMARY_PARSERS = {
|
||||
const TRANSACTION_RESPONSE_PARSERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'TransactionSummary': makeObjectPropertySetter(
|
||||
readTransactionSummary, 'transactionSummary'),
|
||||
'InsertResults': makeObjectPropertySetter(
|
||||
readInsertResults, 'insertIds')
|
||||
}
|
||||
readTransactionSummary,
|
||||
'transactionSummary'
|
||||
),
|
||||
'InsertResults': makeObjectPropertySetter(readInsertResults, 'insertIds'),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
const QUERY_SERIALIZERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'PropertyName': makeChildAppender(writeStringTextNode)
|
||||
}
|
||||
'PropertyName': makeChildAppender(writeStringTextNode),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
@@ -73,11 +85,10 @@ const TRANSACTION_SERIALIZERS = {
|
||||
'Update': makeChildAppender(writeUpdate),
|
||||
'Delete': makeChildAppender(writeDelete),
|
||||
'Property': makeChildAppender(writeProperty),
|
||||
'Native': makeChildAppender(writeNative)
|
||||
}
|
||||
'Native': makeChildAppender(writeNative),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {Object<string, string>|string} [featureNS] The namespace URI used for features.
|
||||
@@ -86,7 +97,6 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* @property {string} [schemaLocation] Optional schemaLocation to use for serialization, this will override the default.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} WriteGetFeatureOptions
|
||||
* @property {string} featureNS The namespace URI used for features.
|
||||
@@ -112,7 +122,6 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* E.g. `hits` only includes the `numberOfFeatures` attribute in the response and no features.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} WriteTransactionOptions
|
||||
* @property {string} featureNS The namespace URI used for features.
|
||||
@@ -128,7 +137,6 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* @property {string} [version='1.1.0'] WFS version to use for the transaction. Can be either `1.0.0` or `1.1.0`.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Number of features; bounds/extent.
|
||||
* @typedef {Object} FeatureCollectionMetadata
|
||||
@@ -136,7 +144,6 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* @property {import("../extent.js").Extent} bounds
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Total deleted; total inserted; total updated; array of insert ids.
|
||||
* @typedef {Object} TransactionResponse
|
||||
@@ -146,53 +153,47 @@ const TRANSACTION_SERIALIZERS = {
|
||||
* @property {Array<string>} insertIds
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const FEATURE_PREFIX = 'feature';
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const XMLNS = 'http://www.w3.org/2000/xmlns/';
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const OGCNS = 'http://www.opengis.net/ogc';
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const WFSNS = 'http://www.opengis.net/wfs';
|
||||
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const FESNS = 'http://www.opengis.net/fes';
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, string>}
|
||||
*/
|
||||
const SCHEMA_LOCATIONS = {
|
||||
'1.1.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
|
||||
'1.0.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd'
|
||||
'1.1.0':
|
||||
'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
|
||||
'1.0.0':
|
||||
'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd',
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
const DEFAULT_VERSION = '1.1.0';
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading and writing data in the WFS format.
|
||||
@@ -203,7 +204,6 @@ const DEFAULT_VERSION = '1.1.0';
|
||||
* @api
|
||||
*/
|
||||
class WFS extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Optional configuration object.
|
||||
*/
|
||||
@@ -228,15 +228,15 @@ class WFS extends XMLFeature {
|
||||
* @private
|
||||
* @type {GMLBase}
|
||||
*/
|
||||
this.gmlFormat_ = options.gmlFormat ?
|
||||
options.gmlFormat : new GML3();
|
||||
this.gmlFormat_ = options.gmlFormat ? options.gmlFormat : new GML3();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.schemaLocation_ = options.schemaLocation ?
|
||||
options.schemaLocation : SCHEMA_LOCATIONS[DEFAULT_VERSION];
|
||||
this.schemaLocation_ = options.schemaLocation
|
||||
? options.schemaLocation
|
||||
: SCHEMA_LOCATIONS[DEFAULT_VERSION];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,21 +262,25 @@ class WFS extends XMLFeature {
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
const context = {
|
||||
node: node
|
||||
node: node,
|
||||
};
|
||||
assign(context, {
|
||||
'featureType': this.featureType_,
|
||||
'featureNS': this.featureNS_
|
||||
'featureNS': this.featureNS_,
|
||||
});
|
||||
|
||||
assign(context, this.getReadOptions(node, opt_options ? opt_options : {}));
|
||||
const objectStack = [context];
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS[GMLNS][
|
||||
'featureMember'] =
|
||||
makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
|
||||
let features = pushParseAndPop([],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this.gmlFormat_);
|
||||
'featureMember'
|
||||
] = makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
|
||||
let features = pushParseAndPop(
|
||||
[],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS,
|
||||
node,
|
||||
objectStack,
|
||||
this.gmlFormat_
|
||||
);
|
||||
if (!features) {
|
||||
features = [];
|
||||
}
|
||||
@@ -298,9 +302,12 @@ class WFS extends XMLFeature {
|
||||
return this.readTransactionResponseFromDocument(doc);
|
||||
} else if (isDocument(source)) {
|
||||
return this.readTransactionResponseFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
/** @type {Document} */ (source)
|
||||
);
|
||||
} else {
|
||||
return this.readTransactionResponseFromNode(/** @type {Element} */ (source));
|
||||
return this.readTransactionResponseFromNode(
|
||||
/** @type {Element} */ (source)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,10 +327,12 @@ class WFS extends XMLFeature {
|
||||
return this.readFeatureCollectionMetadataFromDocument(doc);
|
||||
} else if (isDocument(source)) {
|
||||
return this.readFeatureCollectionMetadataFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
/** @type {Document} */ (source)
|
||||
);
|
||||
} else {
|
||||
return this.readFeatureCollectionMetadataFromNode(
|
||||
/** @type {Element} */ (source));
|
||||
/** @type {Element} */ (source)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +344,9 @@ class WFS extends XMLFeature {
|
||||
readFeatureCollectionMetadataFromDocument(doc) {
|
||||
for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFeatureCollectionMetadataFromNode(/** @type {Element} */ (n));
|
||||
return this.readFeatureCollectionMetadataFromNode(
|
||||
/** @type {Element} */ (n)
|
||||
);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
@@ -349,11 +360,16 @@ class WFS extends XMLFeature {
|
||||
readFeatureCollectionMetadataFromNode(node) {
|
||||
const result = {};
|
||||
const value = readNonNegativeIntegerString(
|
||||
node.getAttribute('numberOfFeatures'));
|
||||
node.getAttribute('numberOfFeatures')
|
||||
);
|
||||
result['numberOfFeatures'] = value;
|
||||
return pushParseAndPop(
|
||||
/** @type {FeatureCollectionMetadata} */ (result),
|
||||
FEATURE_COLLECTION_PARSERS, node, [], this.gmlFormat_);
|
||||
FEATURE_COLLECTION_PARSERS,
|
||||
node,
|
||||
[],
|
||||
this.gmlFormat_
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,8 +391,11 @@ class WFS extends XMLFeature {
|
||||
*/
|
||||
readTransactionResponseFromNode(node) {
|
||||
return pushParseAndPop(
|
||||
/** @type {TransactionResponse} */({}),
|
||||
TRANSACTION_RESPONSE_PARSERS, node, []);
|
||||
/** @type {TransactionResponse} */ ({}),
|
||||
TRANSACTION_RESPONSE_PARSERS,
|
||||
node,
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,10 +434,12 @@ class WFS extends XMLFeature {
|
||||
}
|
||||
filter = options.filter;
|
||||
if (options.bbox) {
|
||||
assert(options.geometryName,
|
||||
12); // `options.geometryName` must also be provided when `options.bbox` is set
|
||||
assert(options.geometryName, 12); // `options.geometryName` must also be provided when `options.bbox` is set
|
||||
const bbox = bboxFilter(
|
||||
/** @type {string} */ (options.geometryName), options.bbox, options.srsName);
|
||||
/** @type {string} */ (options.geometryName),
|
||||
options.bbox,
|
||||
options.srsName
|
||||
);
|
||||
if (filter) {
|
||||
// if bbox and filter are both set, combine the two into a single filter
|
||||
filter = andFilter(filter, bbox);
|
||||
@@ -427,10 +448,14 @@ class WFS extends XMLFeature {
|
||||
}
|
||||
}
|
||||
}
|
||||
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', this.schemaLocation_);
|
||||
node.setAttributeNS(
|
||||
XML_SCHEMA_INSTANCE_URI,
|
||||
'xsi:schemaLocation',
|
||||
this.schemaLocation_
|
||||
);
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
const context = {
|
||||
node: node
|
||||
node: node,
|
||||
};
|
||||
assign(context, {
|
||||
'srsName': options.srsName,
|
||||
@@ -438,12 +463,15 @@ class WFS extends XMLFeature {
|
||||
'featurePrefix': options.featurePrefix,
|
||||
'geometryName': options.geometryName,
|
||||
'filter': filter,
|
||||
'propertyNames': options.propertyNames ? options.propertyNames : []
|
||||
'propertyNames': options.propertyNames ? options.propertyNames : [],
|
||||
});
|
||||
|
||||
assert(Array.isArray(options.featureTypes),
|
||||
11); // `options.featureTypes` should be an Array
|
||||
writeGetFeature(node, /** @type {!Array<string>} */ (options.featureTypes), [context]);
|
||||
assert(Array.isArray(options.featureTypes), 11); // `options.featureTypes` should be an Array
|
||||
writeGetFeature(
|
||||
node,
|
||||
/** @type {!Array<string>} */ (options.featureTypes),
|
||||
[context]
|
||||
);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -474,43 +502,87 @@ class WFS extends XMLFeature {
|
||||
}
|
||||
}
|
||||
const schemaLocation = SCHEMA_LOCATIONS[version];
|
||||
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', schemaLocation);
|
||||
const featurePrefix = options.featurePrefix ? options.featurePrefix : FEATURE_PREFIX;
|
||||
node.setAttributeNS(
|
||||
XML_SCHEMA_INSTANCE_URI,
|
||||
'xsi:schemaLocation',
|
||||
schemaLocation
|
||||
);
|
||||
const featurePrefix = options.featurePrefix
|
||||
? options.featurePrefix
|
||||
: FEATURE_PREFIX;
|
||||
if (inserts) {
|
||||
obj = assign({node: node}, {'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName});
|
||||
obj = assign(
|
||||
{node: node},
|
||||
{
|
||||
'featureNS': options.featureNS,
|
||||
'featureType': options.featureType,
|
||||
'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion,
|
||||
'hasZ': options.hasZ,
|
||||
'srsName': options.srsName,
|
||||
}
|
||||
);
|
||||
assign(obj, baseObj);
|
||||
pushSerializeAndPop(obj,
|
||||
pushSerializeAndPop(
|
||||
obj,
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Insert'), inserts,
|
||||
objectStack);
|
||||
makeSimpleNodeFactory('Insert'),
|
||||
inserts,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
if (updates) {
|
||||
obj = assign({node: node}, {'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName});
|
||||
obj = assign(
|
||||
{node: node},
|
||||
{
|
||||
'featureNS': options.featureNS,
|
||||
'featureType': options.featureType,
|
||||
'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion,
|
||||
'hasZ': options.hasZ,
|
||||
'srsName': options.srsName,
|
||||
}
|
||||
);
|
||||
assign(obj, baseObj);
|
||||
pushSerializeAndPop(obj,
|
||||
pushSerializeAndPop(
|
||||
obj,
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Update'), updates,
|
||||
objectStack);
|
||||
makeSimpleNodeFactory('Update'),
|
||||
updates,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
if (deletes) {
|
||||
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'srsName': options.srsName},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Delete'), deletes,
|
||||
objectStack);
|
||||
pushSerializeAndPop(
|
||||
{
|
||||
node: node,
|
||||
'featureNS': options.featureNS,
|
||||
'featureType': options.featureType,
|
||||
'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion,
|
||||
'srsName': options.srsName,
|
||||
},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Delete'),
|
||||
deletes,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
if (options.nativeElements) {
|
||||
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'srsName': options.srsName},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Native'), options.nativeElements,
|
||||
objectStack);
|
||||
pushSerializeAndPop(
|
||||
{
|
||||
node: node,
|
||||
'featureNS': options.featureNS,
|
||||
'featureType': options.featureType,
|
||||
'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion,
|
||||
'srsName': options.srsName,
|
||||
},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Native'),
|
||||
options.nativeElements,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -533,13 +605,15 @@ class WFS extends XMLFeature {
|
||||
* @return {import("../proj/Projection.js").default} Projection.
|
||||
*/
|
||||
readProjectionFromNode(node) {
|
||||
if (node.firstElementChild &&
|
||||
node.firstElementChild.firstElementChild) {
|
||||
if (node.firstElementChild && node.firstElementChild.firstElementChild) {
|
||||
node = node.firstElementChild.firstElementChild;
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (!(n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 &&
|
||||
n.firstChild.nodeType === 3))) {
|
||||
if (
|
||||
!(
|
||||
n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 && n.firstChild.nodeType === 3)
|
||||
)
|
||||
) {
|
||||
const objectStack = [{}];
|
||||
this.gmlFormat_.readGeometryElement(n, objectStack);
|
||||
return getProjection(objectStack.pop().srsName);
|
||||
@@ -551,31 +625,27 @@ class WFS extends XMLFeature {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} Transaction Summary.
|
||||
*/
|
||||
function readTransactionSummary(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
{}, TRANSACTION_SUMMARY_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, TRANSACTION_SUMMARY_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
const OGC_FID_PARSERS = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
'FeatureId': makeArrayPusher(function(node, objectStack) {
|
||||
'FeatureId': makeArrayPusher(function (node, objectStack) {
|
||||
return node.getAttribute('fid');
|
||||
})
|
||||
}
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -584,29 +654,25 @@ function fidParser(node, objectStack) {
|
||||
parseNode(OGC_FID_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
const INSERT_RESULTS_PARSERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'Feature': fidParser
|
||||
}
|
||||
'Feature': fidParser,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Array<string>|undefined} Insert results.
|
||||
*/
|
||||
function readInsertResults(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
[], INSERT_RESULTS_PARSERS, node, objectStack);
|
||||
return pushParseAndPop([], INSERT_RESULTS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
@@ -626,7 +692,6 @@ function writeFeature(node, feature, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {number|string} fid Feature identifier.
|
||||
@@ -640,7 +705,6 @@ function writeOgcFidFilter(node, fid, objectStack) {
|
||||
node.appendChild(filter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|undefined} featurePrefix The prefix of the feature.
|
||||
* @param {string} featureType The type of the feature.
|
||||
@@ -657,7 +721,6 @@ function getTypeName(featurePrefix, featureType) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
@@ -678,7 +741,6 @@ function writeDelete(node, feature, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
@@ -702,23 +764,31 @@ function writeUpdate(node, feature, objectStack) {
|
||||
const value = feature.get(keys[i]);
|
||||
if (value !== undefined) {
|
||||
let name = keys[i];
|
||||
if (value && typeof /** @type {?} */ (value).getSimplifiedGeometry === 'function') {
|
||||
if (
|
||||
value &&
|
||||
typeof (/** @type {?} */ (value).getSimplifiedGeometry) === 'function'
|
||||
) {
|
||||
name = geometryName;
|
||||
}
|
||||
values.push({name: name, value: value});
|
||||
}
|
||||
}
|
||||
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */ (
|
||||
{'gmlVersion': context['gmlVersion'], node: node,
|
||||
'hasZ': context['hasZ'], 'srsName': context['srsName']}),
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Property'), values,
|
||||
objectStack);
|
||||
pushSerializeAndPop(
|
||||
/** @type {import("../xml.js").NodeStackItem} */ ({
|
||||
'gmlVersion': context['gmlVersion'],
|
||||
node: node,
|
||||
'hasZ': context['hasZ'],
|
||||
'srsName': context['srsName'],
|
||||
}),
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Property'),
|
||||
values,
|
||||
objectStack
|
||||
);
|
||||
writeOgcFidFilter(node, fid, objectStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Object} pair Property name and value.
|
||||
@@ -733,13 +803,15 @@ function writeProperty(node, pair, objectStack) {
|
||||
if (pair.value !== undefined && pair.value !== null) {
|
||||
const value = createElementNS(WFSNS, 'Value');
|
||||
node.appendChild(value);
|
||||
if (pair.value && typeof /** @type {?} */ (pair.value).getSimplifiedGeometry === 'function') {
|
||||
if (
|
||||
pair.value &&
|
||||
typeof (/** @type {?} */ (pair.value).getSimplifiedGeometry) ===
|
||||
'function'
|
||||
) {
|
||||
if (gmlVersion === 2) {
|
||||
GML2.prototype.writeGeometryElement(value,
|
||||
pair.value, objectStack);
|
||||
GML2.prototype.writeGeometryElement(value, pair.value, objectStack);
|
||||
} else {
|
||||
GML3.prototype.writeGeometryElement(value,
|
||||
pair.value, objectStack);
|
||||
GML3.prototype.writeGeometryElement(value, pair.value, objectStack);
|
||||
}
|
||||
} else {
|
||||
writeStringTextNode(value, pair.value);
|
||||
@@ -747,7 +819,6 @@ function writeProperty(node, pair, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {{vendorId: string, safeToIgnore: boolean, value: string}} nativeElement The native element.
|
||||
@@ -765,13 +836,12 @@ function writeNative(node, nativeElement, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
||||
*/
|
||||
const GETFEATURE_SERIALIZERS = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'Query': makeChildAppender(writeQuery)
|
||||
'Query': makeChildAppender(writeQuery),
|
||||
},
|
||||
'http://www.opengis.net/ogc': {
|
||||
'During': makeChildAppender(writeDuringFilter),
|
||||
@@ -790,11 +860,10 @@ const GETFEATURE_SERIALIZERS = {
|
||||
'PropertyIsGreaterThanOrEqualTo': makeChildAppender(writeComparisonFilter),
|
||||
'PropertyIsNull': makeChildAppender(writeIsNullFilter),
|
||||
'PropertyIsBetween': makeChildAppender(writeIsBetweenFilter),
|
||||
'PropertyIsLike': makeChildAppender(writeIsLikeFilter)
|
||||
}
|
||||
'PropertyIsLike': makeChildAppender(writeIsLikeFilter),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {string} featureType Feature type.
|
||||
@@ -820,12 +889,18 @@ function writeQuery(node, featureType, objectStack) {
|
||||
if (featureNS) {
|
||||
node.setAttributeNS(XMLNS, 'xmlns:' + featurePrefix, featureNS);
|
||||
}
|
||||
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign({}, context));
|
||||
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign(
|
||||
{},
|
||||
context
|
||||
));
|
||||
item.node = node;
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
QUERY_SERIALIZERS,
|
||||
makeSimpleNodeFactory('PropertyName'), propertyNames,
|
||||
objectStack);
|
||||
makeSimpleNodeFactory('PropertyName'),
|
||||
propertyNames,
|
||||
objectStack
|
||||
);
|
||||
const filter = context['filter'];
|
||||
if (filter) {
|
||||
const child = createElementNS(OGCNS, 'Filter');
|
||||
@@ -834,7 +909,6 @@ function writeQuery(node, featureType, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Filter.js").default} filter Filter.
|
||||
@@ -843,13 +917,15 @@ function writeQuery(node, featureType, objectStack) {
|
||||
function writeFilterCondition(node, filter, objectStack) {
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
const item = {node: node};
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
GETFEATURE_SERIALIZERS,
|
||||
makeSimpleNodeFactory(filter.getTagName()),
|
||||
[filter], objectStack);
|
||||
[filter],
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Bbox.js").default} filter Filter.
|
||||
@@ -863,7 +939,6 @@ function writeBboxFilter(node, filter, objectStack) {
|
||||
GML3.prototype.writeGeometryElement(node, filter.extent, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Contains.js").default} filter Filter.
|
||||
@@ -877,7 +952,6 @@ function writeContainsFilter(node, filter, objectStack) {
|
||||
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Intersects.js").default} filter Filter.
|
||||
@@ -891,7 +965,6 @@ function writeIntersectsFilter(node, filter, objectStack) {
|
||||
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Within.js").default} filter Filter.
|
||||
@@ -905,14 +978,12 @@ function writeWithinFilter(node, filter, objectStack) {
|
||||
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/During.js").default} filter Filter.
|
||||
* @param {Array<*>} objectStack Node stack.
|
||||
*/
|
||||
function writeDuringFilter(node, filter, objectStack) {
|
||||
|
||||
const valueReference = createElementNS(FESNS, 'ValueReference');
|
||||
writeStringTextNode(valueReference, filter.propertyName);
|
||||
node.appendChild(valueReference);
|
||||
@@ -930,7 +1001,6 @@ function writeDuringFilter(node, filter, objectStack) {
|
||||
writeTimeInstant(end, filter.end);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/LogicalNary.js").default} filter Filter.
|
||||
@@ -942,14 +1012,16 @@ function writeLogicalFilter(node, filter, objectStack) {
|
||||
const conditions = filter.conditions;
|
||||
for (let i = 0, ii = conditions.length; i < ii; ++i) {
|
||||
const condition = conditions[i];
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
GETFEATURE_SERIALIZERS,
|
||||
makeSimpleNodeFactory(condition.getTagName()),
|
||||
[condition], objectStack);
|
||||
[condition],
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/Not.js").default} filter Filter.
|
||||
@@ -959,13 +1031,15 @@ function writeNotFilter(node, filter, objectStack) {
|
||||
/** @type {import("../xml.js").NodeStackItem} */
|
||||
const item = {node: node};
|
||||
const condition = filter.condition;
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
GETFEATURE_SERIALIZERS,
|
||||
makeSimpleNodeFactory(condition.getTagName()),
|
||||
[condition], objectStack);
|
||||
[condition],
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./filter/ComparisonBinary.js").default} filter Filter.
|
||||
@@ -979,7 +1053,6 @@ function writeComparisonFilter(node, filter, objectStack) {
|
||||
writeOgcLiteral(node, '' + filter.expression);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/IsNull.js").default} filter Filter.
|
||||
@@ -989,7 +1062,6 @@ function writeIsNullFilter(node, filter, objectStack) {
|
||||
writeOgcPropertyName(node, filter.propertyName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {import("./filter/IsBetween.js").default} filter Filter.
|
||||
@@ -1007,7 +1079,6 @@ function writeIsBetweenFilter(node, filter, objectStack) {
|
||||
writeOgcLiteral(upperBoundary, '' + filter.upperBoundary);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./filter/IsLike.js").default} filter Filter.
|
||||
@@ -1024,7 +1095,6 @@ function writeIsLikeFilter(node, filter, objectStack) {
|
||||
writeOgcLiteral(node, '' + filter.pattern);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} tagName Tag name.
|
||||
* @param {Node} node Node.
|
||||
@@ -1036,7 +1106,6 @@ function writeOgcExpression(tagName, node, value) {
|
||||
node.appendChild(property);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {string} value PropertyName value.
|
||||
@@ -1045,7 +1114,6 @@ function writeOgcPropertyName(node, value) {
|
||||
writeOgcExpression('PropertyName', node, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {string} value PropertyName value.
|
||||
@@ -1054,7 +1122,6 @@ function writeOgcLiteral(node, value) {
|
||||
writeOgcExpression('Literal', node, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {string} time PropertyName value.
|
||||
@@ -1068,7 +1135,6 @@ function writeTimeInstant(node, time) {
|
||||
writeStringTextNode(timePosition, time);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode filter as WFS `Filter` and return the Node.
|
||||
*
|
||||
@@ -1082,7 +1148,6 @@ export function writeFilter(filter) {
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array<string>} featureTypes Feature types.
|
||||
@@ -1090,13 +1155,18 @@ export function writeFilter(filter) {
|
||||
*/
|
||||
function writeGetFeature(node, featureTypes, objectStack) {
|
||||
const context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign({}, context));
|
||||
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign(
|
||||
{},
|
||||
context
|
||||
));
|
||||
item.node = node;
|
||||
pushSerializeAndPop(item,
|
||||
pushSerializeAndPop(
|
||||
item,
|
||||
GETFEATURE_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Query'), featureTypes,
|
||||
objectStack);
|
||||
makeSimpleNodeFactory('Query'),
|
||||
featureTypes,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export default WFS;
|
||||
|
||||
Reference in New Issue
Block a user