Merge pull request #1829 from bartvde/wfs2
WFS 1.1.0 format (read/write) (r=@twpayne,@ahocevar)
This commit is contained in:
@@ -117,7 +117,7 @@ ol.format.GML.readFeatures_ = function(node, objectStack) {
|
||||
var features;
|
||||
if (localName == 'FeatureCollection') {
|
||||
features = ol.xml.pushParseAndPop(null,
|
||||
ol.format.GML.FEATURE_COLLECTION_PARSERS_, node, objectStack);
|
||||
ol.format.GML.FEATURE_COLLECTION_PARSERS, node, objectStack);
|
||||
} else if (localName == 'featureMembers') {
|
||||
var parsers = {};
|
||||
var parsersNS = {};
|
||||
@@ -134,9 +134,8 @@ ol.format.GML.readFeatures_ = function(node, objectStack) {
|
||||
|
||||
/**
|
||||
* @type {Object.<string, Object.<string, Object>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.GML.FEATURE_COLLECTION_PARSERS_ = {
|
||||
ol.format.GML.FEATURE_COLLECTION_PARSERS = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'featureMembers': ol.xml.makeReplacer(ol.format.GML.readFeatures_)
|
||||
}
|
||||
@@ -147,9 +146,8 @@ ol.format.GML.FEATURE_COLLECTION_PARSERS_ = {
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {ol.geom.Geometry|undefined} Geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.format.GML.readGeometry_ = function(node, objectStack) {
|
||||
ol.format.GML.readGeometry = function(node, objectStack) {
|
||||
var context = objectStack[0];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
goog.object.set(context, 'srsName',
|
||||
@@ -189,7 +187,7 @@ ol.format.GML.readFeature_ = function(node, objectStack) {
|
||||
values[ol.xml.getLocalName(n)] = value;
|
||||
} else {
|
||||
geometryName = ol.xml.getLocalName(n);
|
||||
values[geometryName] = ol.format.GML.readGeometry_(n, objectStack);
|
||||
values[geometryName] = ol.format.GML.readGeometry(n, objectStack);
|
||||
}
|
||||
}
|
||||
var feature = new ol.Feature(values);
|
||||
@@ -1017,7 +1015,7 @@ ol.format.GML.RING_PARSERS_ = {
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.GML.prototype.readGeometryFromNode = function(node) {
|
||||
var geometry = ol.format.GML.readGeometry_(node, [{}]);
|
||||
var geometry = ol.format.GML.readGeometry(node, [{}]);
|
||||
return (goog.isDef(geometry)) ? geometry : null;
|
||||
};
|
||||
|
||||
@@ -1119,6 +1117,41 @@ ol.format.GML.writePoint_ = function(node, geometry, objectStack) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.GML.ENVELOPE_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'lowerCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode),
|
||||
'upperCorner': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
*/
|
||||
ol.format.GML.writeEnvelope = function(node, extent, objectStack) {
|
||||
goog.asserts.assert(extent.length == 4);
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var srsName = goog.object.get(context, 'srsName');
|
||||
if (goog.isDef(srsName)) {
|
||||
node.setAttribute('srsName', srsName);
|
||||
}
|
||||
var keys = ['lowerCorner', 'upperCorner'];
|
||||
var values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]];
|
||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||
({node: node}), ol.format.GML.ENVELOPE_SERIALIZERS_,
|
||||
ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
|
||||
values,
|
||||
objectStack, keys);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.geom.LinearRing} geometry LinearRing geometry.
|
||||
@@ -1368,11 +1401,10 @@ ol.format.GML.writeCurveSegments_ = function(node, line, objectStack) {
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.geom.Geometry} geometry Geometry.
|
||||
* @param {ol.geom.Geometry|ol.Extent} geometry Geometry.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.GML.writeGeometry_ = function(node, geometry, objectStack) {
|
||||
ol.format.GML.writeGeometry = function(node, geometry, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var item = goog.object.clone(context);
|
||||
@@ -1387,9 +1419,8 @@ ol.format.GML.writeGeometry_ = function(node, geometry, objectStack) {
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.GML.writeFeature_ = function(node, feature, objectStack) {
|
||||
ol.format.GML.writeFeature = function(node, feature, objectStack) {
|
||||
var fid = feature.getId();
|
||||
if (goog.isDef(fid)) {
|
||||
node.setAttribute('fid', fid);
|
||||
@@ -1405,17 +1436,20 @@ ol.format.GML.writeFeature_ = function(node, feature, objectStack) {
|
||||
var properties = feature.getProperties();
|
||||
var keys = [], values = [];
|
||||
for (var key in properties) {
|
||||
keys.push(key);
|
||||
values.push(properties[key]);
|
||||
if (key == geometryName) {
|
||||
if (!(key in context.serializers[featureNS])) {
|
||||
context.serializers[featureNS][key] = ol.xml.makeChildAppender(
|
||||
ol.format.GML.writeGeometry_);
|
||||
}
|
||||
} else {
|
||||
if (!(key in context.serializers[featureNS])) {
|
||||
context.serializers[featureNS][key] = ol.xml.makeChildAppender(
|
||||
ol.format.XSD.writeStringTextNode);
|
||||
var value = properties[key];
|
||||
if (!goog.isNull(value)) {
|
||||
keys.push(key);
|
||||
values.push(value);
|
||||
if (key == geometryName) {
|
||||
if (!(key in context.serializers[featureNS])) {
|
||||
context.serializers[featureNS][key] = ol.xml.makeChildAppender(
|
||||
ol.format.GML.writeGeometry);
|
||||
}
|
||||
} else {
|
||||
if (!(key in context.serializers[featureNS])) {
|
||||
context.serializers[featureNS][key] = ol.xml.makeChildAppender(
|
||||
ol.format.XSD.writeStringTextNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1423,7 +1457,7 @@ ol.format.GML.writeFeature_ = function(node, feature, objectStack) {
|
||||
item.node = node;
|
||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||
(item), context.serializers,
|
||||
ol.xml.OBJECT_PROPERTY_NODE_FACTORY,
|
||||
ol.xml.makeSimpleNodeFactory(undefined, featureNS),
|
||||
values,
|
||||
objectStack, keys);
|
||||
};
|
||||
@@ -1443,7 +1477,7 @@ ol.format.GML.writeFeatureMembers_ = function(node, features, objectStack) {
|
||||
var serializers = {};
|
||||
serializers[featureNS] = {};
|
||||
serializers[featureNS][featureType] = ol.xml.makeChildAppender(
|
||||
ol.format.GML.writeFeature_);
|
||||
ol.format.GML.writeFeature);
|
||||
var item = goog.object.clone(context);
|
||||
item.node = node;
|
||||
ol.xml.pushSerializeAndPop(/** @type {ol.xml.NodeStackItem} */
|
||||
@@ -1526,7 +1560,9 @@ ol.format.GML.GEOMETRY_SERIALIZERS_ = {
|
||||
ol.format.GML.writeMultiSurfaceOrPolygon_),
|
||||
'Surface': ol.xml.makeChildAppender(ol.format.GML.writeSurfaceOrPolygon_),
|
||||
'MultiSurface': ol.xml.makeChildAppender(
|
||||
ol.format.GML.writeMultiSurfaceOrPolygon_)
|
||||
ol.format.GML.writeMultiSurfaceOrPolygon_),
|
||||
'Envelope': ol.xml.makeChildAppender(
|
||||
ol.format.GML.writeEnvelope)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1577,18 +1613,22 @@ ol.format.GML.GEOMETRY_NODE_FACTORY_ = function(value, objectStack,
|
||||
var surface = goog.object.get(context, 'surface');
|
||||
var curve = goog.object.get(context, 'curve');
|
||||
var multiCurve = goog.object.get(context, 'multiCurve');
|
||||
goog.asserts.assertInstanceof(value, ol.geom.Geometry);
|
||||
var parentNode = objectStack[objectStack.length - 1].node;
|
||||
goog.asserts.assert(ol.xml.isNode(parentNode));
|
||||
var nodeName = value.getType();
|
||||
if (nodeName === 'MultiPolygon' && multiSurface === true) {
|
||||
nodeName = 'MultiSurface';
|
||||
} else if (nodeName === 'Polygon' && surface === true) {
|
||||
nodeName = 'Surface';
|
||||
} else if (nodeName === 'LineString' && curve === true) {
|
||||
nodeName = 'Curve';
|
||||
} else if (nodeName === 'MultiLineString' && multiCurve === true) {
|
||||
nodeName = 'MultiCurve';
|
||||
if (!goog.isArray(value)) {
|
||||
goog.asserts.assertInstanceof(value, ol.geom.Geometry);
|
||||
var nodeName = value.getType();
|
||||
if (nodeName === 'MultiPolygon' && multiSurface === true) {
|
||||
nodeName = 'MultiSurface';
|
||||
} else if (nodeName === 'Polygon' && surface === true) {
|
||||
nodeName = 'Surface';
|
||||
} else if (nodeName === 'LineString' && curve === true) {
|
||||
nodeName = 'Curve';
|
||||
} else if (nodeName === 'MultiLineString' && multiCurve === true) {
|
||||
nodeName = 'MultiCurve';
|
||||
}
|
||||
} else {
|
||||
nodeName = 'Envelope';
|
||||
}
|
||||
return ol.xml.createElementNS('http://www.opengis.net/gml',
|
||||
nodeName);
|
||||
|
||||
6
src/ol/format/wfsformat.exports
Normal file
6
src/ol/format/wfsformat.exports
Normal file
@@ -0,0 +1,6 @@
|
||||
@exportSymbol ol.format.WFS
|
||||
@exportProperty ol.format.WFS.prototype.readFeatures
|
||||
@exportProperty ol.format.WFS.prototype.readTransactionResponse
|
||||
@exportProperty ol.format.WFS.prototype.readFeatureCollectionMetadata
|
||||
@exportProperty ol.format.WFS.prototype.writeGetFeature
|
||||
@exportProperty ol.format.WFS.prototype.writeTransaction
|
||||
646
src/ol/format/wfsformat.js
Normal file
646
src/ol/format/wfsformat.js
Normal file
@@ -0,0 +1,646 @@
|
||||
goog.provide('ol.format.WFS');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom.NodeType');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.format.GML');
|
||||
goog.require('ol.format.XMLFeature');
|
||||
goog.require('ol.format.XSD');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.xml');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {olx.format.WFSOptions=} opt_options
|
||||
* Optional configuration object.
|
||||
* @extends {ol.format.XMLFeature}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.format.WFS = function(opt_options) {
|
||||
var options = /** @type {olx.format.WFSOptions} */
|
||||
(goog.isDef(opt_options) ? opt_options : {});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.featureType_ = options.featureType;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.featureNS_ = options.featureNS;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.schemaLocation_ = goog.isDef(options.schemaLocation) ?
|
||||
options.schemaLocation : ol.format.WFS.schemaLocation_;
|
||||
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.format.WFS, ol.format.XMLFeature);
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{numberOfFeatures: number,
|
||||
* bounds: ol.Extent}}
|
||||
*/
|
||||
ol.format.WFS.FeatureCollectionMetadata;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{totalDeleted: number,
|
||||
* totalInserted: number,
|
||||
totalUpdated: number,
|
||||
insertIds: Array.<string>}}
|
||||
*/
|
||||
ol.format.WFS.TransactionResponse;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.schemaLocation_ = 'http://www.opengis.net/wfs ' +
|
||||
'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd';
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WFS.prototype.readFeaturesFromNode = function(node) {
|
||||
var objectStack = [{
|
||||
'featureType': this.featureType_,
|
||||
'featureNS': this.featureNS_
|
||||
}];
|
||||
var features = ol.xml.pushParseAndPop(null,
|
||||
ol.format.GML.FEATURE_COLLECTION_PARSERS, node, objectStack);
|
||||
if (!goog.isDef(features)) {
|
||||
features = [];
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @return {ol.format.WFS.TransactionResponse|undefined} Transaction response.
|
||||
*/
|
||||
ol.format.WFS.prototype.readTransactionResponse = function(source) {
|
||||
if (ol.xml.isDocument(source)) {
|
||||
return this.readTransactionResponseFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
} else if (ol.xml.isNode(source)) {
|
||||
return this.readTransactionResponseFromNode(/** @type {Node} */ (source));
|
||||
} else if (goog.isString(source)) {
|
||||
var doc = ol.xml.load(source);
|
||||
return this.readTransactionResponseFromDocument(doc);
|
||||
} else {
|
||||
goog.asserts.fail();
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @return {ol.format.WFS.FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
*/
|
||||
ol.format.WFS.prototype.readFeatureCollectionMetadata = function(source) {
|
||||
if (ol.xml.isDocument(source)) {
|
||||
return this.readFeatureCollectionMetadataFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
} else if (ol.xml.isNode(source)) {
|
||||
return this.readFeatureCollectionMetadataFromNode(
|
||||
/** @type {Node} */ (source));
|
||||
} else if (goog.isString(source)) {
|
||||
var doc = ol.xml.load(source);
|
||||
return this.readFeatureCollectionMetadataFromDocument(doc);
|
||||
} else {
|
||||
goog.asserts.fail();
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {ol.format.WFS.FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
*/
|
||||
ol.format.WFS.prototype.readFeatureCollectionMetadataFromDocument =
|
||||
function(doc) {
|
||||
goog.asserts.assert(doc.nodeType == goog.dom.NodeType.DOCUMENT);
|
||||
for (var n = doc.firstChild; !goog.isNull(n); n = n.nextSibling) {
|
||||
if (n.nodeType == goog.dom.NodeType.ELEMENT) {
|
||||
return this.readFeatureCollectionMetadataFromNode(n);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.FEATURE_COLLECTION_PARSERS_ = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'boundedBy': ol.xml.makeObjectPropertySetter(
|
||||
ol.format.GML.readGeometry, 'bounds')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {ol.format.WFS.FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
*/
|
||||
ol.format.WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) {
|
||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||
goog.asserts.assert(node.localName == 'FeatureCollection');
|
||||
var result = {};
|
||||
var value = ol.format.XSD.readNonNegativeIntegerString(
|
||||
node.getAttribute('numberOfFeatures'));
|
||||
goog.object.set(result, 'numberOfFeatures', value);
|
||||
return ol.xml.pushParseAndPop(
|
||||
/** @type {ol.format.WFS.FeatureCollectionMetadata} */ (result),
|
||||
ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, []);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.TRANSACTION_SUMMARY_PARSERS_ = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'totalInserted': ol.xml.makeObjectPropertySetter(
|
||||
ol.format.XSD.readNonNegativeInteger),
|
||||
'totalUpdated': ol.xml.makeObjectPropertySetter(
|
||||
ol.format.XSD.readNonNegativeInteger),
|
||||
'totalDeleted': ol.xml.makeObjectPropertySetter(
|
||||
ol.format.XSD.readNonNegativeInteger)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} Transaction Summary.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.readTransactionSummary_ = function(node, objectStack) {
|
||||
return ol.xml.pushParseAndPop(
|
||||
{}, ol.format.WFS.TRANSACTION_SUMMARY_PARSERS_, node, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.OGC_FID_PARSERS_ = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
'FeatureId': ol.xml.makeArrayPusher(function(node, objectStack) {
|
||||
return node.getAttribute('fid');
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.fidParser_ = function(node, objectStack) {
|
||||
ol.xml.parse(ol.format.WFS.OGC_FID_PARSERS_, node, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.INSERT_RESULTS_PARSERS_ = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'Feature': ol.format.WFS.fidParser_
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {Array.<string>|undefined} Insert results.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.readInsertResults_ = function(node, objectStack) {
|
||||
return ol.xml.pushParseAndPop(
|
||||
[], ol.format.WFS.INSERT_RESULTS_PARSERS_, node, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.TRANSACTION_RESPONSE_PARSERS_ = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'TransactionSummary': ol.xml.makeObjectPropertySetter(
|
||||
ol.format.WFS.readTransactionSummary_, 'transactionSummary'),
|
||||
'InsertResults': ol.xml.makeObjectPropertySetter(
|
||||
ol.format.WFS.readInsertResults_, 'insertIds')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {ol.format.WFS.TransactionResponse|undefined} Transaction response.
|
||||
*/
|
||||
ol.format.WFS.prototype.readTransactionResponseFromDocument = function(doc) {
|
||||
goog.asserts.assert(doc.nodeType == goog.dom.NodeType.DOCUMENT);
|
||||
for (var n = doc.firstChild; !goog.isNull(n); n = n.nextSibling) {
|
||||
if (n.nodeType == goog.dom.NodeType.ELEMENT) {
|
||||
return this.readTransactionResponseFromNode(n);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {ol.format.WFS.TransactionResponse|undefined} Transaction response.
|
||||
*/
|
||||
ol.format.WFS.prototype.readTransactionResponseFromNode = function(node) {
|
||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||
goog.asserts.assert(node.localName == 'TransactionResponse');
|
||||
return ol.xml.pushParseAndPop(
|
||||
/** @type {ol.format.WFS.TransactionResponse} */({}),
|
||||
ol.format.WFS.TRANSACTION_RESPONSE_PARSERS_, node, []);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.QUERY_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'PropertyName': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeFeature_ = function(node, feature, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var featureType = goog.object.get(context, 'featureType');
|
||||
var featureNS = goog.object.get(context, 'featureNS');
|
||||
var child = ol.xml.createElementNS(featureNS, featureType);
|
||||
node.appendChild(child);
|
||||
ol.format.GML.writeFeature(child, feature, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {number|string} fid Feature identifier.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeOgcFidFilter_ = function(node, fid, objectStack) {
|
||||
var filter = ol.xml.createElementNS('http://www.opengis.net/ogc', 'Filter');
|
||||
var child = ol.xml.createElementNS('http://www.opengis.net/ogc', 'FeatureId');
|
||||
filter.appendChild(child);
|
||||
child.setAttribute('fid', fid);
|
||||
node.appendChild(filter);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var featureType = goog.object.get(context, 'featureType');
|
||||
var featurePrefix = goog.object.get(context, 'featurePrefix');
|
||||
node.setAttribute('typeName', featurePrefix + ':' + featureType);
|
||||
var fid = feature.getId();
|
||||
if (goog.isDef(fid)) {
|
||||
ol.format.WFS.writeOgcFidFilter_(node, fid, objectStack);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var featureType = goog.object.get(context, 'featureType');
|
||||
var featurePrefix = goog.object.get(context, 'featurePrefix');
|
||||
node.setAttribute('typeName', featurePrefix + ':' + featureType);
|
||||
var fid = feature.getId();
|
||||
if (goog.isDef(fid)) {
|
||||
var keys = feature.getKeys();
|
||||
var values = [];
|
||||
for (var i = 0, ii = keys.length; i < ii; i++) {
|
||||
var value = feature.get(keys[i]);
|
||||
if (goog.isDef(value)) {
|
||||
values.push({name: keys[i], value: value});
|
||||
}
|
||||
}
|
||||
ol.xml.pushSerializeAndPop({node: node},
|
||||
ol.format.WFS.TRANSACTION_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory('Property'), values,
|
||||
objectStack);
|
||||
ol.format.WFS.writeOgcFidFilter_(node, fid, objectStack);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Object} pair Property name and value.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeProperty_ = function(node, pair, objectStack) {
|
||||
var name = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Name');
|
||||
node.appendChild(name);
|
||||
ol.format.XSD.writeStringTextNode(name, pair.name);
|
||||
if (goog.isDefAndNotNull(pair.value)) {
|
||||
var value = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Value');
|
||||
node.appendChild(value);
|
||||
if (pair.value instanceof ol.geom.Geometry) {
|
||||
ol.format.GML.writeGeometry(value, pair.value, objectStack);
|
||||
} else {
|
||||
ol.format.XSD.writeStringTextNode(value, pair.value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {{vendorId: string, safeToIgnore: boolean, value: string}}
|
||||
* nativeElement The native element.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeNative_ = function(node, nativeElement, objectStack) {
|
||||
if (goog.isDef(nativeElement.vendorId)) {
|
||||
node.setAttribute('vendorId', nativeElement.vendorId);
|
||||
}
|
||||
if (goog.isDef(nativeElement.safeToIgnore)) {
|
||||
node.setAttribute('safeToIgnore', nativeElement.safeToIgnore);
|
||||
}
|
||||
if (goog.isDef(nativeElement.value)) {
|
||||
ol.format.XSD.writeStringTextNode(node, nativeElement.value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.TRANSACTION_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'Insert': ol.xml.makeChildAppender(ol.format.WFS.writeFeature_),
|
||||
'Update': ol.xml.makeChildAppender(ol.format.WFS.writeUpdate_),
|
||||
'Delete': ol.xml.makeChildAppender(ol.format.WFS.writeDelete_),
|
||||
'Property': ol.xml.makeChildAppender(ol.format.WFS.writeProperty_),
|
||||
'Native': ol.xml.makeChildAppender(ol.format.WFS.writeNative_)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {string} featureType Feature type.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeQuery_ = function(node, featureType, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var featurePrefix = goog.object.get(context, 'featurePrefix');
|
||||
var featureNS = goog.object.get(context, 'featureNS');
|
||||
var propertyNames = goog.object.get(context, 'propertyNames');
|
||||
var srsName = goog.object.get(context, 'srsName');
|
||||
var prefix = goog.isDef(featurePrefix) ? featurePrefix + ':' : '';
|
||||
node.setAttribute('typeName', prefix + featureType);
|
||||
if (goog.isDef(srsName)) {
|
||||
node.setAttribute('srsName', srsName);
|
||||
}
|
||||
if (goog.isDef(featureNS)) {
|
||||
node.setAttribute('xmlns:' + featurePrefix, featureNS);
|
||||
}
|
||||
var item = goog.object.clone(context);
|
||||
item.node = node;
|
||||
ol.xml.pushSerializeAndPop(item,
|
||||
ol.format.WFS.QUERY_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory('PropertyName'), propertyNames,
|
||||
objectStack);
|
||||
var bbox = goog.object.get(context, 'bbox');
|
||||
if (goog.isDef(bbox)) {
|
||||
var child = ol.xml.createElementNS('http://www.opengis.net/ogc', 'Filter');
|
||||
ol.format.WFS.writeOgcBBOX_(child, bbox, objectStack);
|
||||
node.appendChild(child);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {string} value PropertyName value.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeOgcPropertyName_ = function(node, value, objectStack) {
|
||||
var property = ol.xml.createElementNS('http://www.opengis.net/ogc',
|
||||
'PropertyName');
|
||||
ol.format.XSD.writeStringTextNode(property, value);
|
||||
node.appendChild(property);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.Extent} bbox Bounding box.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeOgcBBOX_ = function(node, bbox, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var geometryName = goog.object.get(context, 'geometryName');
|
||||
var bboxNode = ol.xml.createElementNS('http://www.opengis.net/ogc', 'BBOX');
|
||||
node.appendChild(bboxNode);
|
||||
ol.format.WFS.writeOgcPropertyName_(bboxNode, geometryName, objectStack);
|
||||
ol.format.GML.writeGeometry(bboxNode, bbox, objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object.<string, Object.<string, ol.xml.Serializer>>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.GETFEATURE_SERIALIZERS_ = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'Query': ol.xml.makeChildAppender(
|
||||
ol.format.WFS.writeQuery_)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<{string}>} featureTypes Feature types.
|
||||
* @param {Array.<*>} objectStack Node stack.
|
||||
* @private
|
||||
*/
|
||||
ol.format.WFS.writeGetFeature_ = function(node, featureTypes, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
goog.asserts.assert(goog.isObject(context));
|
||||
var item = goog.object.clone(context);
|
||||
item.node = node;
|
||||
ol.xml.pushSerializeAndPop(item,
|
||||
ol.format.WFS.GETFEATURE_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory('Query'), featureTypes,
|
||||
objectStack);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {olx.format.WFSWriteGetFeatureOptions} options Options.
|
||||
* @return {ArrayBuffer|Node|Object|string} Result.
|
||||
*/
|
||||
ol.format.WFS.prototype.writeGetFeature = function(options) {
|
||||
var node = ol.xml.createElementNS('http://www.opengis.net/wfs',
|
||||
'GetFeature');
|
||||
node.setAttribute('service', 'WFS');
|
||||
node.setAttribute('version', '1.1.0');
|
||||
if (goog.isDef(options)) {
|
||||
if (goog.isDef(options.handle)) {
|
||||
node.setAttribute('handle', options.handle);
|
||||
}
|
||||
if (goog.isDef(options.outputFormat)) {
|
||||
node.setAttribute('outputFormat', options.outputFormat);
|
||||
}
|
||||
if (goog.isDef(options.maxFeatures)) {
|
||||
node.setAttribute('maxFeatures', options.maxFeatures);
|
||||
}
|
||||
if (goog.isDef(options.resultType)) {
|
||||
node.setAttribute('resultType', options.resultType);
|
||||
}
|
||||
if (goog.isDef(options.startIndex)) {
|
||||
node.setAttribute('startIndex', options.startIndex);
|
||||
}
|
||||
if (goog.isDef(options.count)) {
|
||||
node.setAttribute('count', options.count);
|
||||
}
|
||||
}
|
||||
ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation_);
|
||||
var context = {
|
||||
node: node,
|
||||
srsName: options.srsName,
|
||||
featureNS: goog.isDef(options.featureNS) ?
|
||||
options.featureNS : this.featureNS_,
|
||||
featurePrefix: options.featurePrefix,
|
||||
geometryName: options.geometryName,
|
||||
bbox: options.bbox,
|
||||
propertyNames: goog.isDef(options.propertyNames) ?
|
||||
options.propertyNames : []
|
||||
};
|
||||
goog.asserts.assert(goog.isArray(options.featureTypes));
|
||||
ol.format.WFS.writeGetFeature_(node, options.featureTypes, [context]);
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.Feature>} inserts The features to insert.
|
||||
* @param {Array.<ol.Feature>} updates The features to update.
|
||||
* @param {Array.<ol.Feature>} deletes The features to delete.
|
||||
* @param {olx.format.WFSWriteTransactionOptions} options Write options.
|
||||
* @return {ArrayBuffer|Node|Object|string} Result.
|
||||
*/
|
||||
ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
|
||||
options) {
|
||||
var objectStack = [];
|
||||
var node = ol.xml.createElementNS('http://www.opengis.net/wfs',
|
||||
'Transaction');
|
||||
node.setAttribute('service', 'WFS');
|
||||
node.setAttribute('version', '1.1.0');
|
||||
if (goog.isDef(options)) {
|
||||
if (goog.isDef(options.handle)) {
|
||||
node.setAttribute('handle', options.handle);
|
||||
}
|
||||
}
|
||||
ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation_);
|
||||
if (goog.isDefAndNotNull(inserts)) {
|
||||
ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS,
|
||||
featureType: options.featureType},
|
||||
ol.format.WFS.TRANSACTION_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory('Insert'), inserts,
|
||||
objectStack);
|
||||
}
|
||||
if (goog.isDefAndNotNull(updates)) {
|
||||
ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS,
|
||||
featureType: options.featureType, featurePrefix: options.featurePrefix},
|
||||
ol.format.WFS.TRANSACTION_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory('Update'), updates,
|
||||
objectStack);
|
||||
}
|
||||
if (goog.isDefAndNotNull(deletes)) {
|
||||
ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS,
|
||||
featureType: options.featureType, featurePrefix: options.featurePrefix},
|
||||
ol.format.WFS.TRANSACTION_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory('Delete'), deletes,
|
||||
objectStack);
|
||||
}
|
||||
if (goog.isDef(options.nativeElements)) {
|
||||
ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS,
|
||||
featureType: options.featureType, featurePrefix: options.featurePrefix},
|
||||
ol.format.WFS.TRANSACTION_SERIALIZERS_,
|
||||
ol.xml.makeSimpleNodeFactory('Native'), options.nativeElements,
|
||||
objectStack);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
Reference in New Issue
Block a user