From 7ebf97406d92e39750a0b8036faa0ea119245cc1 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 6 Mar 2014 09:24:39 +0100 Subject: [PATCH 1/9] Add support for writing WFS GetFeature --- src/objectliterals.jsdoc | 18 ++ src/ol/format/gmlformat.js | 5 +- src/ol/format/wfsformat.js | 177 +++++++++++++++ test/spec/ol/format/wfs/topp-states-wfs.xml | 233 ++++++++++++++++++++ test/spec/ol/format/wfsformat.test.js | 97 ++++++++ 5 files changed, 527 insertions(+), 3 deletions(-) create mode 100644 src/ol/format/wfsformat.js create mode 100644 test/spec/ol/format/wfs/topp-states-wfs.xml create mode 100644 test/spec/ol/format/wfsformat.test.js diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 19ef7ded72..8d6b967eed 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -325,6 +325,24 @@ * when writing out the GML, this will override the default provided. */ +/** + * @typedef {Object} olx.format.WFSOptions + * @property {string} featureNS The namespace URI used for features. + * @property {string} featureType + */ + +/** + * @typedef {Object} olx.format.WFSWriteGetFeatureOptions + * @property {string} featureNS The namespace URI used for features. + * @property {string} featurePrefix The prefix for the feature namespace. + * @property {Array.} featureTypes The feature type names. + * @property {string|undefined} srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @property {string|undefined} handle Handle. + * @property {string|undefined} outputFormat Output format. + * @property {number} maxFeatures Maximum number of features to fetch. + */ + /** * @typedef {Object} olx.interaction.DoubleClickZoomOptions * @property {number|undefined} duration Animation duration in milliseconds. Default is `250`. diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 0eaeabf093..101fcf0f25 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -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.>} - * @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_) } diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js new file mode 100644 index 0000000000..e4504ac911 --- /dev/null +++ b/src/ol/format/wfsformat.js @@ -0,0 +1,177 @@ +goog.provide('ol.format.WFS'); + +goog.require('goog.asserts'); +goog.require('goog.object'); +goog.require('ol.format.GML'); +goog.require('ol.format.XMLFeature'); +goog.require('ol.format.XSD'); +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 : ('http://www.opengis.net/wfs ' + + 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd'); + + goog.base(this); +}; +goog.inherits(ol.format.WFS, ol.format.XMLFeature); + + +/** + * @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; +}; + + +/** + * @type {Object.>} + * @private + */ +ol.format.WFS.QUERY_SERIALIZERS_ = { + 'http://www.opengis.net/wfs': { + 'PropertyName': ol.xml.makeChildAppender(ol.format.XSD.writeStringTextNode) + } +}; + + +/** + * @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); + node.setAttribute('srsName', srsName); + if (goog.isDef(featureNS)) { + node.setAttribute('xmlns:' + featurePrefix, featureNS); + } + var item = goog.object.clone(context); + goog.object.set(item, 'node', node); + ol.xml.pushSerializeAndPop(item, + ol.format.WFS.QUERY_SERIALIZERS_, + ol.xml.makeSimpleNodeFactory('PropertyName'), propertyNames, + objectStack); +}; + + +/** + * @type {Object.>} + * @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); + goog.object.set(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, + propertyNames: goog.isDef(options.propertyNames) ? + options.propertyNames : [] + }; + goog.asserts.assert(goog.isArray(options.featureTypes)); + ol.format.WFS.writeGetFeature_(node, options.featureTypes, [context]); + return node; +}; diff --git a/test/spec/ol/format/wfs/topp-states-wfs.xml b/test/spec/ol/format/wfs/topp-states-wfs.xml new file mode 100644 index 0000000000..352a01fa51 --- /dev/null +++ b/test/spec/ol/format/wfs/topp-states-wfs.xml @@ -0,0 +1,233 @@ + + + + + + + 36.986 -91.516 + 42.509 -87.507 + + + + + + + + + 37.511 -88.071 37.476 -88.087 37.442 -88.311 37.409 + -88.359 37.421 -88.419 37.401 -88.467 37.296 -88.511 37.257 + -88.501 37.205 -88.451 37.156 -88.422 37.098 -88.451 37.072 + -88.476 37.068 -88.491 37.064 -88.517 37.072 -88.559 37.109 + -88.614 37.135 -88.688 37.141 -88.739 37.152 -88.746 37.202 + -88.863 37.218 -88.932 37.221 -88.993 37.185 -89.065 37.112 + -89.116 37.093 -89.146 37.064 -89.169 37.025 -89.174 36.998 + -89.151 36.988 -89.129 36.986 -89.193 37.028 -89.211 37.041 + -89.237 37.087 -89.264 37.091 -89.284 37.085 -89.303 37.061 + -89.309 37.027 -89.264 37.008 -89.262 36.999 -89.282 37.009 + -89.311 37.049 -89.382 37.099 -89.379 37.137 -89.423 37.165 + -89.441 37.224 -89.468 37.253 -89.465 37.256 -89.489 37.276 + -89.513 37.304 -89.513 37.329 -89.501 37.339 -89.468 37.355 + -89.435 37.411 -89.427 37.453 -89.453 37.491 -89.494 37.571 + -89.524 37.615 -89.513 37.651 -89.519 37.679 -89.513 37.694 + -89.521 37.706 -89.581 37.745 -89.666 37.783 -89.675 37.804 + -89.691 37.841 -89.728 37.905 -89.851 37.905 -89.861 37.891 + -89.866 37.875 -89.901 37.878 -89.937 37.911 -89.978 37.963 + -89.958 37.969 -90.011 37.993 -90.041 38.032 -90.119 38.053 + -90.134 38.088 -90.207 38.122 -90.254 38.166 -90.289 38.188 + -90.336 38.234 -90.364 38.323 -90.369 38.365 -90.358 38.391 + -90.339 38.427 -90.301 38.518 -90.265 38.532 -90.261 38.562 + -90.241 38.611 -90.183 38.658 -90.183 38.701 -90.202 38.723 + -90.196 38.773 -90.163 38.785 -90.135 38.801 -90.121 38.831 + -90.113 38.853 -90.132 38.914 -90.243 38.924 -90.278 38.924 + -90.319 38.962 -90.413 38.959 -90.469 38.891 -90.531 38.871 + -90.571 38.881 -90.627 38.935 -90.668 39.037 -90.706 39.058 + -90.707 39.093 -90.691 39.144 -90.716 39.195 -90.718 39.224 + -90.732 39.247 -90.738 39.296 -90.779 39.351 -90.851 39.401 + -90.947 39.444 -91.036 39.473 -91.064 39.528 -91.093 39.552 + -91.156 39.601 -91.203 39.685 -91.317 39.724 -91.367 39.761 + -91.373 39.803 -91.381 39.863 -91.449 39.885 -91.451 39.901 + -91.434 39.921 -91.431 39.946 -91.447 40.005 -91.487 40.066 + -91.504 40.134 -91.516 40.201 -91.506 40.251 -91.498 40.309 + -91.486 40.371 -91.448 40.386 -91.418 40.392 -91.385 40.402 + -91.372 40.447 -91.385 40.503 -91.374 40.528 -91.382 40.547 + -91.412 40.572 -91.411 40.603 -91.375 40.639 -91.262 40.643 + -91.214 40.656 -91.162 40.682 -91.129 40.705 -91.119 40.761 + -91.092 40.833 -91.088 40.879 -91.049 40.923 -90.983 40.951 + -90.961 41.071 -90.954 41.104 -90.957 41.144 -90.991 41.165 + -91.018 41.176 -91.056 41.231 -91.101 41.267 -91.102 41.334 + -91.073 41.401 -91.055 41.423 -91.027 41.431 -91.001 41.421 + -90.949 41.444 -90.844 41.449 -90.779 41.451 -90.708 41.462 + -90.658 41.509 -90.601 41.525 -90.541 41.527 -90.454 41.543 + -90.434 41.567 -90.423 41.586 -90.348 41.602 -90.339 41.649 + -90.341 41.722 -90.326 41.756 -90.304 41.781 -90.255 41.806 + -90.195 41.931 -90.154 41.983 -90.142 42.033 -90.151 42.061 + -90.168 42.103 -90.166 42.121 -90.176 42.122 -90.191 42.159 + -90.231 42.197 -90.323 42.211 -90.367 42.242 -90.407 42.263 + -90.417 42.341 -90.427 42.361 -90.441 42.388 -90.491 42.421 + -90.563 42.461 -90.605 42.475 -90.648 42.494 -90.651 42.509 + -90.638 42.508 -90.419 42.504 -89.923 42.503 -89.834 42.497 + -89.401 42.497 -89.359 42.491 -88.939 42.491 -88.764 42.489 + -88.706 42.491 -88.297 42.489 -88.194 42.489 -87.797 42.314 + -87.836 42.156 -87.761 42.059 -87.671 41.847 -87.612 41.723 + -87.529 41.469 -87.532 41.301 -87.532 41.173 -87.531 41.009 + -87.532 40.745 -87.532 40.494 -87.537 40.483 -87.535 40.166 + -87.535 39.887 -87.535 39.609 -87.535 39.477 -87.538 39.351 + -87.541 39.338 -87.597 39.307 -87.625 39.297 -87.611 39.281 + -87.615 39.258 -87.606 39.248 -87.584 39.208 -87.588 39.198 + -87.594 39.196 -87.607 39.168 -87.644 39.146 -87.671 39.131 + -87.659 39.113 -87.662 39.103 -87.631 39.088 -87.631 39.084 + -87.612 39.062 -87.585 38.995 -87.581 38.994 -87.591 38.977 + -87.547 38.963 -87.533 38.931 -87.531 38.904 -87.539 38.869 + -87.559 38.857 -87.551 38.795 -87.507 38.776 -87.519 38.769 + -87.508 38.736 -87.508 38.685 -87.543 38.672 -87.588 38.642 + -87.625 38.622 -87.628 38.599 -87.619 38.593 -87.641 38.573 + -87.652 38.547 -87.672 38.515 -87.651 38.501 -87.653 38.504 + -87.679 38.481 -87.692 38.466 -87.756 38.457 -87.758 38.445 + -87.738 38.417 -87.748 38.378 -87.784 38.352 -87.834 38.286 + -87.851 38.285 -87.863 38.316 -87.874 38.315 -87.883 38.301 + -87.888 38.281 -87.914 38.302 -87.913 38.304 -87.925 38.241 + -87.981 38.234 -87.986 38.201 -87.977 38.171 -87.932 38.157 + -87.931 38.136 -87.951 38.131 -87.973 38.103 -88.018 38.092 + -88.012 38.096 -87.964 38.073 -87.975 38.054 -88.034 38.045 + -88.043 38.038 -88.041 38.033 -88.021 38.008 -88.029 37.975 + -88.021 37.956 -88.042 37.934 -88.041 37.929 -88.064 37.944 + -88.078 37.923 -88.084 37.917 -88.031 37.905 -88.026 37.896 + -88.044 37.906 -88.101 37.895 -88.101 37.867 -88.075 37.843 + -88.034 37.827 -88.042 37.831 -88.089 37.817 -88.086 37.805 + -88.035 37.735 -88.072 37.701 -88.133 37.661 -88.159 37.628 + -88.157 37.583 -88.134 37.511 -88.071 + + + + + + + Illinois + 17 + E N Cen + IL + 143986.61 + 1993.335 + 1.143E7 + 2924880.0 + 4202240.0 + 5552233.0 + 5878369.0 + 4199206.0 + 3741715.0 + 652603.0 + 538071.0 + 5417967.0 + 385040.0 + 1360159.0 + 828906.0 + 0.486 + 0.514 + 1747776.0 + + + + + 38.788 -77.122 + 38.993 -76.911 + + + + + + + + + 38.966 -77.008 38.889 -76.911 38.788 -77.045 38.813 + -77.035 38.829 -77.045 38.838 -77.041 38.862 -77.039 38.886 + -77.067 38.915 -77.078 38.932 -77.122 38.993 -77.042 38.966 + -77.008 + + + + + + + District of Columbia + 11 + S Atl + DC + 159.055 + 17.991 + 606900.0 + 122087.0 + 249634.0 + 282970.0 + 323930.0 + 229975.0 + 106694.0 + 36621.0 + 111422.0 + 303994.0 + 23442.0 + 65498.0 + 22407.0 + 0.466 + 0.534 + 72696.0 + + + + + 38.449 -75.791 + 39.841 -75.045 + + + + + + + + + 38.557 -75.707 38.649 -75.711 38.831 -75.724 39.141 + -75.752 39.247 -75.761 39.295 -75.764 39.383 -75.772 39.723 + -75.791 39.724 -75.775 39.774 -75.745 39.821 -75.695 39.838 + -75.644 39.841 -75.583 39.826 -75.471 39.798 -75.421 39.789 + -75.412 39.778 -75.428 39.763 -75.461 39.741 -75.475 39.719 + -75.476 39.714 -75.489 39.612 -75.611 39.566 -75.562 39.463 + -75.591 39.366 -75.515 39.257 -75.402 39.073 -75.397 39.012 + -75.324 38.945 -75.307 38.808 -75.191 38.799 -75.083 38.449 + -75.045 38.449 -75.068 38.451 -75.093 38.455 -75.351 38.463 + -75.699 38.557 -75.707 + + + + + + + Delaware + 10 + S Atl + DE + 5062.456 + 1385.022 + 666168.0 + 175867.0 + 247497.0 + 322968.0 + 343200.0 + 247566.0 + 258087.0 + 42968.0 + 8069.0 + 335147.0 + 13945.0 + 87973.0 + 44140.0 + 0.485 + 0.515 + 102776.0 + + + diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js new file mode 100644 index 0000000000..78200336d5 --- /dev/null +++ b/test/spec/ol/format/wfsformat.test.js @@ -0,0 +1,97 @@ +goog.provide('ol.test.format.WFS'); + +describe('ol.format.WFS', function() { + + describe('when parsing TOPP states GML from WFS', function() { + + var features, feature; + before(function(done) { + afterLoadText('spec/ol/format/wfs/topp-states-wfs.xml', function(xml) { + try { + var config = { + 'featureNS': 'http://www.openplans.org/topp', + 'featureType': 'states' + }; + features = new ol.format.WFS(config).readFeatures(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('creates 3 features', function() { + expect(features).to.have.length(3); + }); + + it('creates a polygon for Illinois', function() { + feature = features[0]; + expect(feature.getId()).to.equal('states.1'); + expect(feature.get('STATE_NAME')).to.equal('Illinois'); + expect(feature.getGeometry()).to.be.an(ol.geom.MultiPolygon); + }); + + }); + + describe('when writing out a GetFeature request', function() { + + it('creates the expected output', function() { + var text = + '' + + ' ' + + ' STATE_NAME' + + ' STATE_FIPS' + + ' STATE_ABBR' + + ' ' + + ''; + var serialized = new ol.format.WFS().writeGetFeature({ + resultType: 'hits', + featureTypes: ['states'], + featureNS: 'http://www.openplans.org/topp', + featurePrefix: 'topp', + srsName: 'urn:ogc:def:crs:EPSG::4326', + propertyNames: ['STATE_NAME', 'STATE_FIPS', 'STATE_ABBR'] + }); + expect(serialized).to.xmleql(ol.xml.load(text)); + }); + + it('creates paging headers', function() { + var text = + '' + + ' ' + + ' ' + + ''; + var serialized = new ol.format.WFS().writeGetFeature({ + count: 10, + startIndex: 20, + srsName: 'urn:ogc:def:crs:EPSG::4326', + featureNS: 'http://www.openplans.org/topp', + featurePrefix: 'topp', + featureTypes: ['states'] + }); + expect(serialized).to.xmleql(ol.xml.load(text)); + }); + }); + +}); + + +goog.require('ol.xml'); +goog.require('ol.geom.MultiPolygon'); +goog.require('ol.format.WFS'); From 2310ccdb912740cba3fdf1e322ce636ed9a73134 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 6 Mar 2014 19:04:23 +0100 Subject: [PATCH 2/9] Add reading of TransactionResponse --- src/ol/format/wfsformat.js | 154 +++++++++++++++++- .../ol/format/wfs}/TransactionResponse.xml | 0 test/spec/ol/format/wfsformat.test.js | 22 +++ 3 files changed, 173 insertions(+), 3 deletions(-) rename {old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0 => test/spec/ol/format/wfs}/TransactionResponse.xml (100%) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index e4504ac911..39076e04d9 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -1,6 +1,7 @@ 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'); @@ -37,14 +38,22 @@ ol.format.WFS = function(opt_options) { * @type {string} */ this.schemaLocation_ = goog.isDef(options.schemaLocation) ? - options.schemaLocation : ('http://www.opengis.net/wfs ' + - 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd'); + options.schemaLocation : ol.format.WFS.schemaLocation_; goog.base(this); }; goog.inherits(ol.format.WFS, ol.format.XMLFeature); +/** + * @const + * @type {string} + * @private + */ +ol.format.WFS.schemaLocation_ = 'http://www.opengis.net/wfs ' + + 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd'; + + /** * @inheritDoc */ @@ -62,6 +71,145 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node) { }; +/** + * @param {ArrayBuffer|Document|Node|Object|string} source Source. + * @return {Object|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 null; + } +}; + + +/** + * @const + * @type {Object.>} + * @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.>} + * @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.>} + * @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 {Object|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.>} + * @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 {Object|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 null; +}; + + +/** + * @param {Node} node Node. + * @return {Object|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({}, + ol.format.WFS.TRANSACTION_RESPONSE_PARSERS_, node, []); +}; + + /** * @type {Object.>} * @private @@ -93,7 +241,7 @@ ol.format.WFS.writeQuery_ = function(node, featureType, objectStack) { node.setAttribute('xmlns:' + featurePrefix, featureNS); } var item = goog.object.clone(context); - goog.object.set(item, 'node', node); + item.node = node; ol.xml.pushSerializeAndPop(item, ol.format.WFS.QUERY_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('PropertyName'), propertyNames, diff --git a/old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/TransactionResponse.xml b/test/spec/ol/format/wfs/TransactionResponse.xml similarity index 100% rename from old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/TransactionResponse.xml rename to test/spec/ol/format/wfs/TransactionResponse.xml diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 78200336d5..94a8b7ce36 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -33,6 +33,28 @@ describe('ol.format.WFS', function() { }); + describe('when parsing TransactionResponse', function() { + var response; + before(function(done) { + afterLoadText('spec/ol/format/wfs/TransactionResponse.xml', + function(xml) { + try { + response = new ol.format.WFS().readTransactionResponse(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + it('returns the correct TransactionResponse object', function() { + expect(response.transactionSummary.totalDeleted).to.equal(0); + expect(response.transactionSummary.totalInserted).to.equal(0); + expect(response.transactionSummary.totalUpdated).to.equal(1); + expect(response.insertIds).to.have.length(2); + expect(response.insertIds[0]).to.equal('parcelle.40'); + }); + }); + describe('when writing out a GetFeature request', function() { it('creates the expected output', function() { From c05e8d0292e011157722a0b6cc4f5f733675b5b9 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 7 Mar 2014 10:32:17 +0100 Subject: [PATCH 3/9] Read the metadata of a FeatureCollection --- src/ol/format/gmlformat.js | 7 +- src/ol/format/wfsformat.js | 66 +++++++++++++++++++ .../spec/ol/format/wfs}/NumberOfFeatures.xml | 0 .../spec/ol/format/wfs}/boundedBy.xml | 0 test/spec/ol/format/wfsformat.test.js | 37 +++++++++++ 5 files changed, 106 insertions(+), 4 deletions(-) rename {old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0 => test/spec/ol/format/wfs}/NumberOfFeatures.xml (100%) rename {old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0 => test/spec/ol/format/wfs}/boundedBy.xml (100%) diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 101fcf0f25..65621e014b 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -146,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', @@ -188,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); @@ -1016,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; }; diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 39076e04d9..11109ae724 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -91,6 +91,72 @@ ol.format.WFS.prototype.readTransactionResponse = function(source) { }; +/** + * @param {ArrayBuffer|Document|Node|Object|string} source Source. + * @return {Object|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 null; + } +}; + + +/** + * @param {Document} doc Document. + * @return {Object|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 null; +}; + + +/** + * @const + * @type {Object.>} + * @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 {Object|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( + result, ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, []); +}; + + /** * @const * @type {Object.>} diff --git a/old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/NumberOfFeatures.xml b/test/spec/ol/format/wfs/NumberOfFeatures.xml similarity index 100% rename from old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/NumberOfFeatures.xml rename to test/spec/ol/format/wfs/NumberOfFeatures.xml diff --git a/old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/boundedBy.xml b/test/spec/ol/format/wfs/boundedBy.xml similarity index 100% rename from old/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/boundedBy.xml rename to test/spec/ol/format/wfs/boundedBy.xml diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 94a8b7ce36..603e15a388 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -33,6 +33,43 @@ describe('ol.format.WFS', function() { }); + describe('when parsing FeatureCollection', function() { + var response; + before(function(done) { + afterLoadText('spec/ol/format/wfs/NumberOfFeatures.xml', + function(xml) { + try { + response = new ol.format.WFS().readFeatureCollectionMetadata(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + it('returns the correct number of features', function() { + expect(response.numberOfFeatures).to.equal(625); + }); + }); + + describe('when parsing FeatureCollection', function() { + var response; + before(function(done) { + afterLoadText('spec/ol/format/wfs/boundedBy.xml', + function(xml) { + try { + response = new ol.format.WFS().readFeatureCollectionMetadata(xml); + } catch (e) { + done(e); + } + done(); + }); + }); + it('returns the correct bounds', function() { + expect(response.bounds).to.eql([3197.88, 306457.313, + 280339.156, 613850.438]); + }); + }); + describe('when parsing TransactionResponse', function() { var response; before(function(done) { From 2ce92ac6a29f53cc162d546418806b103869c662 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 7 Mar 2014 16:44:24 +0100 Subject: [PATCH 4/9] Add write support for BBOX filter --- src/objectliterals.jsdoc | 5 +- src/ol/format/gmlformat.js | 70 +++++++++++++++++++++------ src/ol/format/wfsformat.js | 41 +++++++++++++++- test/spec/ol/format/wfsformat.test.js | 28 +++++++++++ 4 files changed, 127 insertions(+), 17 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 8d6b967eed..1f222add18 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -340,7 +340,10 @@ * set on geometries when this is not provided. * @property {string|undefined} handle Handle. * @property {string|undefined} outputFormat Output format. - * @property {number} maxFeatures Maximum number of features to fetch. + * @property {number|undefined} maxFeatures Maximum number of features to fetch. + * @property {string|undefined} geometryName Geometry name to use in a BBOX + * filter. + * @property {ol.Extent|undefined} bbox Extent to use for the BBOX filter. */ /** diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 65621e014b..291c65c772 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -1117,6 +1117,41 @@ ol.format.GML.writePoint_ = function(node, geometry, objectStack) { }; +/** + * @type {Object.>} + * @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. @@ -1366,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); @@ -1408,7 +1442,7 @@ ol.format.GML.writeFeature_ = function(node, feature, objectStack) { if (key == geometryName) { if (!(key in context.serializers[featureNS])) { context.serializers[featureNS][key] = ol.xml.makeChildAppender( - ol.format.GML.writeGeometry_); + ol.format.GML.writeGeometry); } } else { if (!(key in context.serializers[featureNS])) { @@ -1524,7 +1558,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) } }; @@ -1575,18 +1611,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); diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 11109ae724..72ee897470 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -312,6 +312,43 @@ ol.format.WFS.writeQuery_ = function(node, featureType, objectStack) { 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.writeBBOX_(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.writeBBOX_ = 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); }; @@ -337,7 +374,7 @@ 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); - goog.object.set(item, 'node', node); + item.node = node; ol.xml.pushSerializeAndPop(item, ol.format.WFS.GETFEATURE_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('Query'), featureTypes, @@ -382,6 +419,8 @@ ol.format.WFS.prototype.writeGetFeature = function(options) { 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 : [] }; diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 603e15a388..cb500361c0 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -146,6 +146,34 @@ describe('ol.format.WFS', function() { }); expect(serialized).to.xmleql(ol.xml.load(text)); }); + + it('creates a BBOX filter', function() { + var text = + '' + + ' ' + + ' ' + + ' the_geom' + + ' ' + + ' 1 2' + + ' 3 4' + + ' ' + + ' ' + + ' ' + + ''; + var serialized = new ol.format.WFS().writeGetFeature({ + srsName: 'urn:ogc:def:crs:EPSG::4326', + featureNS: 'http://www.openplans.org/topp', + featurePrefix: 'topp', + featureTypes: ['states'], + geometryName: 'the_geom', + bbox: [1, 2, 3, 4] + }); + expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + }); + }); }); From 4e5e75f525ce13604f3c4c90ff4cfa0918cbd74c Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 10 Mar 2014 14:58:03 +0100 Subject: [PATCH 5/9] Add write support for Transaction --- src/objectliterals.jsdoc | 12 ++ src/ol/format/gmlformat.js | 32 ++-- src/ol/format/wfsformat.js | 164 ++++++++++++++++++ .../spec/ol/format/wfs}/TransactionMulti.xml | 8 +- test/spec/ol/format/wfsformat.test.js | 60 +++++++ 5 files changed, 257 insertions(+), 19 deletions(-) rename {old/test/spec/ol/parser/ogc/xml/wfs_v1 => test/spec/ol/format/wfs}/TransactionMulti.xml (84%) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 1f222add18..346688201a 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -346,6 +346,18 @@ * @property {ol.Extent|undefined} bbox Extent to use for the BBOX filter. */ +/** + * @typedef {Object} olx.format.WFSWriteTransactionOptions + * @property {string} featureNS The namespace URI used for features. + * @property {string} featurePrefix The prefix for the feature namespace. + * @property {string} featureType The feature type name. + * @property {string|undefined} srsName SRS name. No srsName attribute will be + * set on geometries when this is not provided. + * @property {string|undefined} handle Handle. + * @property {Array.} nativeElements Native elements. Currently not + * supported. + */ + /** * @typedef {Object} olx.interaction.DoubleClickZoomOptions * @property {number|undefined} duration Animation duration in milliseconds. Default is `250`. diff --git a/src/ol/format/gmlformat.js b/src/ol/format/gmlformat.js index 291c65c772..d08b6e0e30 100644 --- a/src/ol/format/gmlformat.js +++ b/src/ol/format/gmlformat.js @@ -1419,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); @@ -1437,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); + } } } } @@ -1455,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); }; @@ -1475,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} */ diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 72ee897470..2e9718c748 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -6,6 +6,7 @@ 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'); @@ -287,6 +288,124 @@ ol.format.WFS.QUERY_SERIALIZERS_ = { }; +/** + * @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); + } + } +}; + + +/** + * @type {Object.>} + * @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_) + } +}; + + /** * @param {Node} node Node. * @param {string} featureType Feature type. @@ -428,3 +547,48 @@ ol.format.WFS.prototype.writeGetFeature = function(options) { ol.format.WFS.writeGetFeature_(node, options.featureTypes, [context]); return node; }; + + +/** + * @param {Array.} inserts The features to insert. + * @param {Array.} updates The features to update. + * @param {Array.} 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 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, + []); + } + 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, + []); + } + 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, + []); + } + return node; +}; diff --git a/old/test/spec/ol/parser/ogc/xml/wfs_v1/TransactionMulti.xml b/test/spec/ol/format/wfs/TransactionMulti.xml similarity index 84% rename from old/test/spec/ol/parser/ogc/xml/wfs_v1/TransactionMulti.xml rename to test/spec/ol/format/wfs/TransactionMulti.xml index 22c0886045..1154cb38c0 100644 --- a/old/test/spec/ol/parser/ogc/xml/wfs_v1/TransactionMulti.xml +++ b/test/spec/ol/format/wfs/TransactionMulti.xml @@ -1,11 +1,11 @@ - + - 1,2 + 1 2 @@ -20,7 +20,7 @@ - 1,2 + 1 2 @@ -42,4 +42,4 @@ - \ No newline at end of file + diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index cb500361c0..d6e13ef40b 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -176,9 +176,69 @@ describe('ol.format.WFS', function() { }); + describe('when writing out a Transaction request', function() { + + it('creates a handle', function() { + var text = + ''; + var serialized = new ol.format.WFS().writeTransaction(null, null, null, + {handle: 'handle_t'}); + expect(serialized).to.xmleql(ol.xml.load(text)); + }); + + }); + + describe('when writing out a Transaction request', function() { + var text; + before(function(done) { + afterLoadText('spec/ol/format/wfs/TransactionMulti.xml', function(xml) { + text = xml; + done(); + }); + }); + + it('creates the correct transaction body', function() { + var format = new ol.format.WFS(); + var insertFeature = new ol.Feature({ + the_geom: new ol.geom.MultiPoint([[1, 2]]), + foo: 'bar', + nul: null + }); + insertFeature.setGeometryName('the_geom'); + var inserts = [insertFeature]; + var updateFeature = new ol.Feature({ + the_geom: new ol.geom.MultiPoint([[1, 2]]), + foo: 'bar', + // null value gets Property element with no Value + nul: null, + // undefined value means don't create a Property element + unwritten: undefined + }); + updateFeature.setId('fid.42'); + var updates = [updateFeature]; + + var deleteFeature = new ol.Feature(); + deleteFeature.setId('fid.37'); + var deletes = [deleteFeature]; + var serialized = format.writeTransaction(inserts, updates, deletes, { + featureNS: 'http://www.openplans.org/topp', + featureType: 'states', + featurePrefix: 'topp' + }); + expect(serialized).to.xmleql(ol.xml.load(text)); + }); + + }); + }); goog.require('ol.xml'); +goog.require('ol.Feature'); +goog.require('ol.geom.MultiPoint'); goog.require('ol.geom.MultiPolygon'); goog.require('ol.format.WFS'); From 33abbfced1540f0797c0dcfae0e076e4fec72115 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 10 Mar 2014 15:24:00 +0100 Subject: [PATCH 6/9] Add support for writing Native --- src/ol/format/wfsformat.js | 37 +++++++++++++++++-- .../spec/ol/format/wfs}/Native.xml | 0 test/spec/ol/format/wfsformat.test.js | 25 +++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) rename {old/test/spec/ol/parser/ogc/xml/wfs_v1 => test/spec/ol/format/wfs}/Native.xml (100%) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 2e9718c748..ec1cf31e24 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -392,6 +392,26 @@ ol.format.WFS.writeProperty_ = function(node, pair, objectStack) { }; +/** + * @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.>} * @private @@ -401,7 +421,8 @@ ol.format.WFS.TRANSACTION_SERIALIZERS_ = { '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_) + 'Property': ol.xml.makeChildAppender(ol.format.WFS.writeProperty_), + 'Native': ol.xml.makeChildAppender(ol.format.WFS.writeNative_) } }; @@ -558,6 +579,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) { */ 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'); @@ -574,21 +596,28 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, 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; }; diff --git a/old/test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml b/test/spec/ol/format/wfs/Native.xml similarity index 100% rename from old/test/spec/ol/parser/ogc/xml/wfs_v1/Native.xml rename to test/spec/ol/format/wfs/Native.xml diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index d6e13ef40b..cd03aa504e 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -234,6 +234,31 @@ describe('ol.format.WFS', function() { }); + describe('when writing out a Transaction request', function() { + var text; + before(function(done) { + afterLoadText('spec/ol/format/wfs/Native.xml', function(xml) { + text = xml; + done(); + }); + }); + + it('handles writing out Native', function() { + var format = new ol.format.WFS(); + var serialized = format.writeTransaction(null, null, null, { + nativeElements: [{ + vendorId: 'ORACLE', + safeToIgnore: true, + value: 'ALTER SESSION ENABLE PARALLEL DML' + }, { + vendorId: 'ORACLE', + safeToIgnore: false, + value: 'Another native line goes here' + }] + }); + expect(serialized).to.xmleql(ol.xml.load(text)); + }); + }); }); From 6800a3290bf3cd535dad8891ec50a9b158b7c6b9 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 10 Mar 2014 15:37:29 +0100 Subject: [PATCH 7/9] Port over test case for multiple Query elements --- src/ol/format/wfsformat.js | 4 +++- .../ol/format/wfs}/GetFeatureMultiple.xml | 2 +- test/spec/ol/format/wfsformat.test.js | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) rename {old/test/spec/ol/parser/ogc/xml/wfs_v1 => test/spec/ol/format/wfs}/GetFeatureMultiple.xml (57%) diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index ec1cf31e24..ed99a47c15 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -442,7 +442,9 @@ ol.format.WFS.writeQuery_ = function(node, featureType, objectStack) { var srsName = goog.object.get(context, 'srsName'); var prefix = goog.isDef(featurePrefix) ? featurePrefix + ':' : ''; node.setAttribute('typeName', prefix + featureType); - node.setAttribute('srsName', srsName); + if (goog.isDef(srsName)) { + node.setAttribute('srsName', srsName); + } if (goog.isDef(featureNS)) { node.setAttribute('xmlns:' + featurePrefix, featureNS); } diff --git a/old/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml b/test/spec/ol/format/wfs/GetFeatureMultiple.xml similarity index 57% rename from old/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml rename to test/spec/ol/format/wfs/GetFeatureMultiple.xml index e1717ddc38..10dcdb2fa7 100644 --- a/old/test/spec/ol/parser/ogc/xml/wfs_v1/GetFeatureMultiple.xml +++ b/test/spec/ol/format/wfs/GetFeatureMultiple.xml @@ -1,4 +1,4 @@ - + diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index cd03aa504e..760e3d8e6d 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -259,6 +259,27 @@ describe('ol.format.WFS', function() { expect(serialized).to.xmleql(ol.xml.load(text)); }); }); + + describe('when writing out a GetFeature request', function() { + var text; + before(function(done) { + afterLoadText('spec/ol/format/wfs/GetFeatureMultiple.xml', function(xml) { + text = xml; + done(); + }); + }); + + it('handles writing multiple Query elements', function() { + var format = new ol.format.WFS(); + var serialized = format.writeGetFeature({ + featureNS: 'http://www.openplans.org/topp', + featureTypes: ['states', 'cities'], + featurePrefix: 'topp' + }); + expect(serialized).to.xmleql(ol.xml.load(text)); + }); + }); + }); From 431a4d17255af66b16a503e3daebb203eeac0e6b Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 10 Mar 2014 15:40:55 +0100 Subject: [PATCH 8/9] Restore the exports --- src/ol/format/wfsformat.exports | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/ol/format/wfsformat.exports diff --git a/src/ol/format/wfsformat.exports b/src/ol/format/wfsformat.exports new file mode 100644 index 0000000000..130a353c6d --- /dev/null +++ b/src/ol/format/wfsformat.exports @@ -0,0 +1,3 @@ +@exportSymbol ol.format.WFS +@exportProperty ol.format.WFS.prototype.writeGetFeature +@exportProperty ol.format.WFS.prototype.writeTransaction From 041479f1b7aba880e5c5e5a4ab0968cced3ef0ac Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Mon, 10 Mar 2014 16:40:00 +0100 Subject: [PATCH 9/9] Add more typedefs for return objects --- src/objectliterals.jsdoc | 5 +++- src/ol/format/wfsformat.exports | 3 ++ src/ol/format/wfsformat.js | 51 +++++++++++++++++++++++---------- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 346688201a..69a2afd8fa 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -328,7 +328,10 @@ /** * @typedef {Object} olx.format.WFSOptions * @property {string} featureNS The namespace URI used for features. - * @property {string} featureType + * @property {string} featureType The feature type to parse. Only used for + * read operations. + * @property {string|undefined} schemaLocation Optional schemaLocation to use + * for serialization, this will override the default. */ /** diff --git a/src/ol/format/wfsformat.exports b/src/ol/format/wfsformat.exports index 130a353c6d..d37ea38997 100644 --- a/src/ol/format/wfsformat.exports +++ b/src/ol/format/wfsformat.exports @@ -1,3 +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 diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index ed99a47c15..330c900dbb 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -46,6 +46,22 @@ ol.format.WFS = function(opt_options) { 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.}} + */ +ol.format.WFS.TransactionResponse; + + /** * @const * @type {string} @@ -74,7 +90,7 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node) { /** * @param {ArrayBuffer|Document|Node|Object|string} source Source. - * @return {Object|undefined} Transaction response. + * @return {ol.format.WFS.TransactionResponse|undefined} Transaction response. */ ol.format.WFS.prototype.readTransactionResponse = function(source) { if (ol.xml.isDocument(source)) { @@ -87,14 +103,15 @@ ol.format.WFS.prototype.readTransactionResponse = function(source) { return this.readTransactionResponseFromDocument(doc); } else { goog.asserts.fail(); - return null; + return undefined; } }; /** * @param {ArrayBuffer|Document|Node|Object|string} source Source. - * @return {Object|undefined} FeatureCollection metadata. + * @return {ol.format.WFS.FeatureCollectionMetadata|undefined} + * FeatureCollection metadata. */ ol.format.WFS.prototype.readFeatureCollectionMetadata = function(source) { if (ol.xml.isDocument(source)) { @@ -108,14 +125,15 @@ ol.format.WFS.prototype.readFeatureCollectionMetadata = function(source) { return this.readFeatureCollectionMetadataFromDocument(doc); } else { goog.asserts.fail(); - return null; + return undefined; } }; /** * @param {Document} doc Document. - * @return {Object|undefined} FeatureCollection metadata. + * @return {ol.format.WFS.FeatureCollectionMetadata|undefined} + * FeatureCollection metadata. */ ol.format.WFS.prototype.readFeatureCollectionMetadataFromDocument = function(doc) { @@ -125,7 +143,7 @@ ol.format.WFS.prototype.readFeatureCollectionMetadataFromDocument = return this.readFeatureCollectionMetadataFromNode(n); } } - return null; + return undefined; }; @@ -144,7 +162,8 @@ ol.format.WFS.FEATURE_COLLECTION_PARSERS_ = { /** * @param {Node} node Node. - * @return {Object|undefined} FeatureCollection metadata. + * @return {ol.format.WFS.FeatureCollectionMetadata|undefined} + * FeatureCollection metadata. */ ol.format.WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); @@ -154,7 +173,8 @@ ol.format.WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) { node.getAttribute('numberOfFeatures')); goog.object.set(result, 'numberOfFeatures', value); return ol.xml.pushParseAndPop( - result, ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, []); + /** @type {ol.format.WFS.FeatureCollectionMetadata} */ (result), + ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, []); }; @@ -226,7 +246,7 @@ ol.format.WFS.INSERT_RESULTS_PARSERS_ = { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @return {Object|undefined} Insert results. + * @return {Array.|undefined} Insert results. * @private */ ol.format.WFS.readInsertResults_ = function(node, objectStack) { @@ -252,7 +272,7 @@ ol.format.WFS.TRANSACTION_RESPONSE_PARSERS_ = { /** * @param {Document} doc Document. - * @return {Object|undefined} Transaction response. + * @return {ol.format.WFS.TransactionResponse|undefined} Transaction response. */ ol.format.WFS.prototype.readTransactionResponseFromDocument = function(doc) { goog.asserts.assert(doc.nodeType == goog.dom.NodeType.DOCUMENT); @@ -261,18 +281,19 @@ ol.format.WFS.prototype.readTransactionResponseFromDocument = function(doc) { return this.readTransactionResponseFromNode(n); } } - return null; + return undefined; }; /** * @param {Node} node Node. - * @return {Object|undefined} Transaction response. + * @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({}, + return ol.xml.pushParseAndPop( + /** @type {ol.format.WFS.TransactionResponse} */({}), ol.format.WFS.TRANSACTION_RESPONSE_PARSERS_, node, []); }; @@ -457,7 +478,7 @@ ol.format.WFS.writeQuery_ = function(node, featureType, 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.writeBBOX_(child, bbox, objectStack); + ol.format.WFS.writeOgcBBOX_(child, bbox, objectStack); node.appendChild(child); } }; @@ -483,7 +504,7 @@ ol.format.WFS.writeOgcPropertyName_ = function(node, value, objectStack) { * @param {Array.<*>} objectStack Node stack. * @private */ -ol.format.WFS.writeBBOX_ = function(node, bbox, objectStack) { +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');