From 759386e37e419c1302b89f908949eb5336273246 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 16:17:09 +0200 Subject: [PATCH 1/7] Add WMS GetFeatureInfo reader format --- src/ol/format/getfeatureinfoformat.js | 122 ++++++++++++++++++++++++++ src/ol/format/gml/gmlbase.js | 7 +- 2 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 src/ol/format/getfeatureinfoformat.js diff --git a/src/ol/format/getfeatureinfoformat.js b/src/ol/format/getfeatureinfoformat.js new file mode 100644 index 0000000000..709fe891c9 --- /dev/null +++ b/src/ol/format/getfeatureinfoformat.js @@ -0,0 +1,122 @@ +goog.provide('ol.format.GetFeatureInfo'); + +goog.require('goog.asserts'); +goog.require('goog.dom'); +goog.require('goog.dom.NodeType'); +goog.require('goog.object'); +goog.require('goog.string'); +goog.require('ol.format.GML'); +goog.require('ol.format.GML2'); +goog.require('ol.format.GMLBase'); +goog.require('ol.format.XMLFeature'); +goog.require('ol.xml'); + + + +/** + * @classdesc + * Format for reading MapServer GetFeatureInfo format.It uses + * ol.format.GML2 to read features. + * + * @constructor + * @param {olx.format.GMLOptions=} opt_options + * Optional configuration object. + * @extends {ol.format.XMLFeature} + * @api + */ +ol.format.GetFeatureInfo = function(opt_options) { + + /** + * @private + * @type {string} + */ + this.featureNS_ = 'http://mapserver.gis.umn.edu/mapserver'; + + + /** + * @private + * @type {string} + */ + this.featureIdentifier_ = '_feature'; + + + /** + * @private + * @type {string} + */ + this.layerIdentifier_ = '_layer'; + + + /** + * @private + * @type {ol.format.GMLBase} + */ + this.gmlFormat_ = new ol.format.GML2(); + + goog.base(this); +}; +goog.inherits(ol.format.GetFeatureInfo, ol.format.XMLFeature); + + +/** + * @const + * @type {string} + * @private + */ +ol.format.GetFeatureInfo.schemaLocation_ = ''; + + +/** + * @param {Node} node Node. + * @param {Array.<*>} objectStack Object stack. + * @return {Array.} Features. + * @private + */ +ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) { + + node.namespaceURI = this.featureNS_; + goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); + var localName = ol.xml.getLocalName(node); + var features; + if (localName == 'msGMLOutput') { + var context = objectStack[0]; + goog.asserts.assert(goog.isObject(context)); + + var layer = node.firstElementChild; + goog.asserts.assert(layer.localName.indexOf(this.layerIdentifier_) >= 0); + + var featureType = goog.string.remove(layer.localName, + this.layerIdentifier_) + this.featureIdentifier_; + + goog.object.set(context, 'featureType', featureType); + goog.object.set(context, 'featureNS', this.featureNS_); + + var parsers = {}; + var parsersNS = {}; + parsers[featureType] = ol.xml.makeArrayPusher( + this.gmlFormat_.readFeatureElement, this.gmlFormat_); + parsersNS[goog.object.get(context, 'featureNS')] = parsers; + features = ol.xml.pushParseAndPop([], parsersNS, layer, objectStack, + this.gmlFormat_); + } + if (!goog.isDef(features)) { + features = []; + } + return features; +}; + + +/** + * @inheritDoc + */ +ol.format.GetFeatureInfo.prototype.readFeaturesFromNode = + function(node, opt_options) { + var options = { + 'featureType': this.featureType, + 'featureNS': this.featureNS + }; + if (goog.isDef(opt_options)) { + goog.object.extend(options, this.getReadOptions(node, opt_options)); + } + return this.readFeatures_(node, [options]); +}; diff --git a/src/ol/format/gml/gmlbase.js b/src/ol/format/gml/gmlbase.js index 5133badd8c..1e1e9dcfc7 100644 --- a/src/ol/format/gml/gmlbase.js +++ b/src/ol/format/gml/gmlbase.js @@ -100,8 +100,8 @@ ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) { var parsers = {}; var parsersNS = {}; parsers[featureType] = (localName == 'featureMembers') ? - ol.xml.makeArrayPusher(this.readFeature_, this) : - ol.xml.makeReplacer(this.readFeature_, this); + ol.xml.makeArrayPusher(this.readFeatureElement, this) : + ol.xml.makeReplacer(this.readFeatureElement, this); parsersNS[goog.object.get(context, 'featureNS')] = parsers; features = ol.xml.pushParseAndPop([], parsersNS, node, objectStack); } @@ -150,9 +150,8 @@ ol.format.GMLBase.prototype.readGeometryElement = function(node, objectStack) { * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {ol.Feature} Feature. - * @private */ -ol.format.GMLBase.prototype.readFeature_ = function(node, objectStack) { +ol.format.GMLBase.prototype.readFeatureElement = function(node, objectStack) { var n; var fid = node.getAttribute('fid') || ol.xml.getAttributeNS(node, 'http://www.opengis.net/gml', 'id'); From d0d6215550953c8894e7e3321cb26db865b1c56f Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Fri, 3 Oct 2014 16:20:33 +0200 Subject: [PATCH 2/7] Add tests suite for GetFeatureInfo format --- .../ol/format/getfeatureinfoformat.test.js | 46 +++++++++++++++++++ test/spec/ol/format/wms/getfeatureinfo.xml | 45 ++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 test/spec/ol/format/getfeatureinfoformat.test.js create mode 100644 test/spec/ol/format/wms/getfeatureinfo.xml diff --git a/test/spec/ol/format/getfeatureinfoformat.test.js b/test/spec/ol/format/getfeatureinfoformat.test.js new file mode 100644 index 0000000000..647df35c2d --- /dev/null +++ b/test/spec/ol/format/getfeatureinfoformat.test.js @@ -0,0 +1,46 @@ +goog.provide('ol.test.format.GetFeatureInfo'); + +describe('ol.format.GetFeatureInfo', function() { + + describe('#readFormat', function() { + + describe('read Features', function() { + + var features; + + before(function(done) { + proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326')); + afterLoadText('spec/ol/format/wms/getfeatureinfo.xml', function(data) { + try { + features = new ol.format.GetFeatureInfo().readFeatures(data); + } catch (e) { + done(e); + } + done(); + }); + }); + + it('creates 3 features', function() { + expect(features).to.have.length(3); + }); + + it('creates a feature for 1071', function() { + var feature = features[0]; + expect(feature.getId()).to.be(undefined); + expect(feature.get('FID')).to.equal('1071'); + expect(feature.get('NO_CAMPAGNE')).to.equal('1020050'); + }); + + it('read boundedBy but no geometry', function() { + var feature = features[0]; + expect(feature.getGeometry()).to.be(undefined); + expect(feature.get('boundedBy')).to.eql( + [-531138.686422, 5386348.414671, -117252.819653, 6144475.186022]); + }); + }); + }); +}); + + +goog.require('goog.dom'); +goog.require('ol.format.GetFeatureInfo'); diff --git a/test/spec/ol/format/wms/getfeatureinfo.xml b/test/spec/ol/format/wms/getfeatureinfo.xml new file mode 100644 index 0000000000..f431b15ad3 --- /dev/null +++ b/test/spec/ol/format/wms/getfeatureinfo.xml @@ -0,0 +1,45 @@ + + + + ADCP de coque 2001 + + + + -531138.686422,5386348.414671 -117252.819653,6144475.186022 + + + 1071 + 1020050 + ITSAS II + http://www.ifremer.fr/sismerData/jsp/visualisationMetadata2.jsp?strPortail=ifremer&langue=FR&pageOrigine=CAM&cle1=FI352001020050 + ITSASII_BB150_0_osite.nc + http://www.ifremer.fr/sismerData/jsp/visualisationMetadata3.jsp?strPortail=ifremer&langue=FR&pageOrigine=CS&cle1=71053_1&cle2=ADCP01 + + + + + -531138.686422,5386348.414671 -117252.819653,6144475.186022 + + + 22431 + 1020050 + ITSAS II + http://www.ifremer.fr/sismerData/jsp/visualisationMetadata2.jsp?strPortail=ifremer&langue=FR&pageOrigine=CAM&cle1=FI352001020050 + ITSASII_BB150_figures.tar + http://www.ifremer.fr/sismerData/jsp/visualisationMetadata3.jsp?strPortail=ifremer&langue=FR&pageOrigine=CS&cle1=108842_2&cle2=ADCP01 + + + + + -531138.686422,5386348.414671 -117252.819653,6144475.186022 + + + 22432 + 1020050 + ITSAS II + http://www.ifremer.fr/sismerData/jsp/visualisationMetadata2.jsp?strPortail=ifremer&langue=FR&pageOrigine=CAM&cle1=FI352001020050 + ITSASII_BB150_0_fhv12.nc + http://www.ifremer.fr/sismerData/jsp/visualisationMetadata3.jsp?strPortail=ifremer&langue=FR&pageOrigine=CS&cle1=108842_3&cle2=ADCP01 + + + \ No newline at end of file From c0f2187310bec332a87b950aa938833b40b9085f Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Fri, 10 Oct 2014 13:19:03 +0200 Subject: [PATCH 3/7] Make GetFeatureInfo format pass ol2 test suite --- src/ol/format/getfeatureinfoformat.js | 51 ++++-- .../ol/format/getfeatureinfoformat.test.js | 157 ++++++++++++++++++ test/spec/ol/format/wms/getfeatureinfo.xml | 4 +- 3 files changed, 193 insertions(+), 19 deletions(-) diff --git a/src/ol/format/getfeatureinfoformat.js b/src/ol/format/getfeatureinfoformat.js index 709fe891c9..d8a726cf94 100644 --- a/src/ol/format/getfeatureinfoformat.js +++ b/src/ol/format/getfeatureinfoformat.js @@ -1,5 +1,6 @@ goog.provide('ol.format.GetFeatureInfo'); +goog.require('goog.array'); goog.require('goog.asserts'); goog.require('goog.dom'); goog.require('goog.dom.NodeType'); @@ -15,7 +16,7 @@ goog.require('ol.xml'); /** * @classdesc - * Format for reading MapServer GetFeatureInfo format.It uses + * Format for reading GetFeatureInfo format.It uses * ol.format.GML2 to read features. * * @constructor @@ -77,27 +78,43 @@ ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) { node.namespaceURI = this.featureNS_; goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); var localName = ol.xml.getLocalName(node); - var features; + var features = []; + if (node.childNodes.length === 0) { + return features; + } if (localName == 'msGMLOutput') { - var context = objectStack[0]; - goog.asserts.assert(goog.isObject(context)); + goog.array.forEach(node.childNodes, function(layer) { + if (layer.nodeType !== goog.dom.NodeType.ELEMENT) { + return; + } + var context = objectStack[0]; + goog.asserts.assert(goog.isObject(context)); - var layer = node.firstElementChild; - goog.asserts.assert(layer.localName.indexOf(this.layerIdentifier_) >= 0); + goog.asserts.assert(layer.localName.indexOf(this.layerIdentifier_) >= 0); - var featureType = goog.string.remove(layer.localName, - this.layerIdentifier_) + this.featureIdentifier_; + var featureType = goog.string.remove(layer.localName, + this.layerIdentifier_) + this.featureIdentifier_; - goog.object.set(context, 'featureType', featureType); - goog.object.set(context, 'featureNS', this.featureNS_); + goog.object.set(context, 'featureType', featureType); + goog.object.set(context, 'featureNS', this.featureNS_); - var parsers = {}; - var parsersNS = {}; - parsers[featureType] = ol.xml.makeArrayPusher( - this.gmlFormat_.readFeatureElement, this.gmlFormat_); - parsersNS[goog.object.get(context, 'featureNS')] = parsers; - features = ol.xml.pushParseAndPop([], parsersNS, layer, objectStack, - this.gmlFormat_); + var parsers = {}; + parsers[featureType] = ol.xml.makeArrayPusher( + this.gmlFormat_.readFeatureElement, this.gmlFormat_); + var parsersNS = ol.xml.makeParsersNS( + [goog.object.get(context, 'featureNS'), null], parsers); + layer.namespaceURI = this.featureNS_; + var layerFeatures = ol.xml.pushParseAndPop( + [], parsersNS, layer, objectStack, this.gmlFormat_); + if (goog.isDef(layerFeatures)) { + goog.array.extend(/** @type {Array} */ (features), layerFeatures); + } + }, this); + } + if (localName == 'FeatureCollection') { + features = ol.xml.pushParseAndPop([], + this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node, + [{}], this.gmlFormat_); } if (!goog.isDef(features)) { features = []; diff --git a/test/spec/ol/format/getfeatureinfoformat.test.js b/test/spec/ol/format/getfeatureinfoformat.test.js index 647df35c2d..1b9acd2333 100644 --- a/test/spec/ol/format/getfeatureinfoformat.test.js +++ b/test/spec/ol/format/getfeatureinfoformat.test.js @@ -37,6 +37,163 @@ describe('ol.format.GetFeatureInfo', function() { expect(feature.get('boundedBy')).to.eql( [-531138.686422, 5386348.414671, -117252.819653, 6144475.186022]); }); + + it('read empty response', function() { + // read empty response + var text = '' + + '' + + ' ' + + ' ' + + ''; + var features = new ol.format.GetFeatureInfo().readFeatures(text); + expect(features.length).to.be(0); + }); + + it('read empty attributes', function() { + text = + '' + + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 107397.266000,460681.063000 116568.188000,480609.250000' + + ' ' + + ' ' + + ' ' + + ' bar' + + ' ' + + ' ' + + ' ' + + ''; + var features = new ol.format.GetFeatureInfo().readFeatures(text); + expect(features.length).to.be(1); + expect(features[0].get('FOO')).to.be('bar'); + // FIXME is that really wanted ? + expect(features[0].get('EMPTY')).to.be(undefined); + }); + + it('read features from multiple layers', function() { + text = + '' + + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 129799.109000,467950.250000 133199.906000,468904.063000' + + ' ' + + ' ' + + ' ' + + ' 287' + + ' N403' + + ' #N403' + + ' 1' + + ' P' + + ' 4091.25' + + ' <shape>' + + ' <null>' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 129936.000000,468362.000000 131686.000000,473119.000000' + + ' ' + + ' ' + + ' ' + + ' 1251' + + ' 1515' + + ' 00:00:00 01/01/1998' + + ' 1472' + + ' 1309' + + ' D' + + ' 227' + + ' Vecht' + + ' 2' + + ' Vecht' + + ' 18.25' + + ' 23.995' + + ' 5745.09' + + ' <shape>' + + ' <null>' + + ' ' + + ' ' + + ''; + var features = new ol.format.GetFeatureInfo().readFeatures(text); + expect(features.length).to.be(2); + expect(features[0].get('OBJECTID')).to.be('287'); + expect(features[1].get('OBJECTID')).to.be('1251'); + }); + + it('read geoserver’s response', function() { + text = + '' + + '' + + ' ' + + ' ' + + ' ' + + '591943.9375,4925605 593045.625,4925845' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' 3' + + ' secondary highway, hard surface' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + '593045.60746465,4925605.0059156 593024.32382915,4925606.79305411' + + ' 592907.54863574,4925624.85647524 592687.35111096,' + + '4925670.76834012 592430.76279218,4925678.79393165' + + ' 592285.97636109,4925715.70811767 592173.39165655,' + + '4925761.83511156 592071.1753393,4925793.95523514' + + ' 591985.96972625,4925831.59842486' + + ' 591943.98769455,4925844.93220071' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; + var features = new ol.format.GetFeatureInfo().readFeatures(text); + expect(features.length).to.be(1); + expect(features[0].get('cat')).to.be('3'); + expect(features[0].getGeometry().getType()).to.be('MultiLineString'); + }); + }); }); }); diff --git a/test/spec/ol/format/wms/getfeatureinfo.xml b/test/spec/ol/format/wms/getfeatureinfo.xml index f431b15ad3..f00c6c4f93 100644 --- a/test/spec/ol/format/wms/getfeatureinfo.xml +++ b/test/spec/ol/format/wms/getfeatureinfo.xml @@ -1,5 +1,5 @@ - + ADCP de coque 2001 @@ -42,4 +42,4 @@ http://www.ifremer.fr/sismerData/jsp/visualisationMetadata3.jsp?strPortail=ifremer&langue=FR&pageOrigine=CS&cle1=108842_3&cle2=ADCP01 - \ No newline at end of file + From 0f99f113e3700f0126a2a41a0f23f19ff5c58032 Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Tue, 4 Nov 2014 09:39:19 +0100 Subject: [PATCH 4/7] Change format name to WMSGetFeatureInfo --- .../{getfeatureinfoformat.js => wmsgetfeatureinfoformat.js} | 2 +- ...reinfoformat.test.js => wmsgetfeatureinfoformat.test.js} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/ol/format/{getfeatureinfoformat.js => wmsgetfeatureinfoformat.js} (98%) rename test/spec/ol/format/{getfeatureinfoformat.test.js => wmsgetfeatureinfoformat.test.js} (98%) diff --git a/src/ol/format/getfeatureinfoformat.js b/src/ol/format/wmsgetfeatureinfoformat.js similarity index 98% rename from src/ol/format/getfeatureinfoformat.js rename to src/ol/format/wmsgetfeatureinfoformat.js index d8a726cf94..916ae7790c 100644 --- a/src/ol/format/getfeatureinfoformat.js +++ b/src/ol/format/wmsgetfeatureinfoformat.js @@ -1,4 +1,4 @@ -goog.provide('ol.format.GetFeatureInfo'); +goog.provide('ol.format.WMSGetFeatureInfo'); goog.require('goog.array'); goog.require('goog.asserts'); diff --git a/test/spec/ol/format/getfeatureinfoformat.test.js b/test/spec/ol/format/wmsgetfeatureinfoformat.test.js similarity index 98% rename from test/spec/ol/format/getfeatureinfoformat.test.js rename to test/spec/ol/format/wmsgetfeatureinfoformat.test.js index 1b9acd2333..d402d37161 100644 --- a/test/spec/ol/format/getfeatureinfoformat.test.js +++ b/test/spec/ol/format/wmsgetfeatureinfoformat.test.js @@ -1,6 +1,6 @@ -goog.provide('ol.test.format.GetFeatureInfo'); +goog.provide('ol.test.format.WMSGetFeatureInfo'); -describe('ol.format.GetFeatureInfo', function() { +describe('ol.format.WMSGetFeatureInfo', function() { describe('#readFormat', function() { @@ -200,4 +200,4 @@ describe('ol.format.GetFeatureInfo', function() { goog.require('goog.dom'); -goog.require('ol.format.GetFeatureInfo'); +goog.require('ol.format.WMSGetFeatureInfo'); From fc16c4500d070c901c762a7ee4dbc16cb0748616 Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Tue, 25 Nov 2014 16:24:32 +0100 Subject: [PATCH 5/7] Renaming & better typing --- src/ol/format/wmsgetfeatureinfoformat.js | 59 +++++++++---------- .../ol/format/wmsgetfeatureinfoformat.test.js | 10 ++-- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/ol/format/wmsgetfeatureinfoformat.js b/src/ol/format/wmsgetfeatureinfoformat.js index 916ae7790c..6f3178339f 100644 --- a/src/ol/format/wmsgetfeatureinfoformat.js +++ b/src/ol/format/wmsgetfeatureinfoformat.js @@ -8,7 +8,6 @@ goog.require('goog.object'); goog.require('goog.string'); goog.require('ol.format.GML'); goog.require('ol.format.GML2'); -goog.require('ol.format.GMLBase'); goog.require('ol.format.XMLFeature'); goog.require('ol.xml'); @@ -16,16 +15,14 @@ goog.require('ol.xml'); /** * @classdesc - * Format for reading GetFeatureInfo format.It uses - * ol.format.GML2 to read features. + * Format for reading WMSGetFeatureInfo format. It uses + * {@link ol.format.GML2} to read features. * * @constructor - * @param {olx.format.GMLOptions=} opt_options - * Optional configuration object. * @extends {ol.format.XMLFeature} * @api */ -ol.format.GetFeatureInfo = function(opt_options) { +ol.format.WMSGetFeatureInfo = function() { /** * @private @@ -36,27 +33,13 @@ ol.format.GetFeatureInfo = function(opt_options) { /** * @private - * @type {string} - */ - this.featureIdentifier_ = '_feature'; - - - /** - * @private - * @type {string} - */ - this.layerIdentifier_ = '_layer'; - - - /** - * @private - * @type {ol.format.GMLBase} + * @type {ol.format.GML2} */ this.gmlFormat_ = new ol.format.GML2(); goog.base(this); }; -goog.inherits(ol.format.GetFeatureInfo, ol.format.XMLFeature); +goog.inherits(ol.format.WMSGetFeatureInfo, ol.format.XMLFeature); /** @@ -64,7 +47,15 @@ goog.inherits(ol.format.GetFeatureInfo, ol.format.XMLFeature); * @type {string} * @private */ -ol.format.GetFeatureInfo.schemaLocation_ = ''; +ol.format.WMSGetFeatureInfo.featureIdentifier_ = '_feature'; + + +/** + * @const + * @type {string} + * @private + */ +ol.format.WMSGetFeatureInfo.layerIdentifier_ = '_layer'; /** @@ -73,11 +64,13 @@ ol.format.GetFeatureInfo.schemaLocation_ = ''; * @return {Array.} Features. * @private */ -ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) { +ol.format.WMSGetFeatureInfo.prototype.readFeatures_ = + function(node, objectStack) { node.namespaceURI = this.featureNS_; goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); var localName = ol.xml.getLocalName(node); + /** @type {Array.} */ var features = []; if (node.childNodes.length === 0) { return features; @@ -90,10 +83,12 @@ ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) { var context = objectStack[0]; goog.asserts.assert(goog.isObject(context)); - goog.asserts.assert(layer.localName.indexOf(this.layerIdentifier_) >= 0); + goog.asserts.assert(layer.localName.indexOf( + ol.format.WMSGetFeatureInfo.layerIdentifier_) >= 0); var featureType = goog.string.remove(layer.localName, - this.layerIdentifier_) + this.featureIdentifier_; + ol.format.WMSGetFeatureInfo.layerIdentifier_) + + ol.format.WMSGetFeatureInfo.featureIdentifier_; goog.object.set(context, 'featureType', featureType); goog.object.set(context, 'featureNS', this.featureNS_); @@ -107,17 +102,17 @@ ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) { var layerFeatures = ol.xml.pushParseAndPop( [], parsersNS, layer, objectStack, this.gmlFormat_); if (goog.isDef(layerFeatures)) { - goog.array.extend(/** @type {Array} */ (features), layerFeatures); + goog.array.extend(features, layerFeatures); } }, this); } if (localName == 'FeatureCollection') { - features = ol.xml.pushParseAndPop([], + var gmlFeatures = ol.xml.pushParseAndPop([], this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node, [{}], this.gmlFormat_); - } - if (!goog.isDef(features)) { - features = []; + if (goog.isDef(gmlFeatures)) { + features = gmlFeatures; + } } return features; }; @@ -126,7 +121,7 @@ ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) { /** * @inheritDoc */ -ol.format.GetFeatureInfo.prototype.readFeaturesFromNode = +ol.format.WMSGetFeatureInfo.prototype.readFeaturesFromNode = function(node, opt_options) { var options = { 'featureType': this.featureType, diff --git a/test/spec/ol/format/wmsgetfeatureinfoformat.test.js b/test/spec/ol/format/wmsgetfeatureinfoformat.test.js index d402d37161..f4ec041a59 100644 --- a/test/spec/ol/format/wmsgetfeatureinfoformat.test.js +++ b/test/spec/ol/format/wmsgetfeatureinfoformat.test.js @@ -12,7 +12,7 @@ describe('ol.format.WMSGetFeatureInfo', function() { proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326')); afterLoadText('spec/ol/format/wms/getfeatureinfo.xml', function(data) { try { - features = new ol.format.GetFeatureInfo().readFeatures(data); + features = new ol.format.WMSGetFeatureInfo().readFeatures(data); } catch (e) { done(e); } @@ -47,7 +47,7 @@ describe('ol.format.WMSGetFeatureInfo', function() { ' ' + ' ' + ''; - var features = new ol.format.GetFeatureInfo().readFeatures(text); + var features = new ol.format.WMSGetFeatureInfo().readFeatures(text); expect(features.length).to.be(0); }); @@ -72,7 +72,7 @@ describe('ol.format.WMSGetFeatureInfo', function() { ' ' + ' ' + ''; - var features = new ol.format.GetFeatureInfo().readFeatures(text); + var features = new ol.format.WMSGetFeatureInfo().readFeatures(text); expect(features.length).to.be(1); expect(features[0].get('FOO')).to.be('bar'); // FIXME is that really wanted ? @@ -132,7 +132,7 @@ describe('ol.format.WMSGetFeatureInfo', function() { ' ' + ' ' + ''; - var features = new ol.format.GetFeatureInfo().readFeatures(text); + var features = new ol.format.WMSGetFeatureInfo().readFeatures(text); expect(features.length).to.be(2); expect(features[0].get('OBJECTID')).to.be('287'); expect(features[1].get('OBJECTID')).to.be('1251'); @@ -188,7 +188,7 @@ describe('ol.format.WMSGetFeatureInfo', function() { ' ' + ' ' + ''; - var features = new ol.format.GetFeatureInfo().readFeatures(text); + var features = new ol.format.WMSGetFeatureInfo().readFeatures(text); expect(features.length).to.be(1); expect(features[0].get('cat')).to.be('3'); expect(features[0].getGeometry().getType()).to.be('MultiLineString'); From 638f8275aac89952bdc396937c92f50dfd8f81aa Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Tue, 25 Nov 2014 16:24:51 +0100 Subject: [PATCH 6/7] Export readFeatures method --- src/ol/format/wmsgetfeatureinfoformat.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ol/format/wmsgetfeatureinfoformat.js b/src/ol/format/wmsgetfeatureinfoformat.js index 6f3178339f..0d928189e4 100644 --- a/src/ol/format/wmsgetfeatureinfoformat.js +++ b/src/ol/format/wmsgetfeatureinfoformat.js @@ -118,6 +118,18 @@ ol.format.WMSGetFeatureInfo.prototype.readFeatures_ = }; +/** + * Read all features from a WMSGetFeatureInfo response. + * + * @function + * @param {ArrayBuffer|Document|Node|Object|string} source Source. + * @param {olx.format.ReadOptions=} opt_options Options. + * @return {Array.} Features. + * @api stable + */ +ol.format.WMSGetFeatureInfo.prototype.readFeatures; + + /** * @inheritDoc */ From 22491601ba12d403ccba5944cd9c707b53b945ae Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Tue, 25 Nov 2014 17:38:06 +0100 Subject: [PATCH 7/7] Restore proj4 state after tests --- test/spec/ol/format/wmsgetfeatureinfoformat.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/spec/ol/format/wmsgetfeatureinfoformat.test.js b/test/spec/ol/format/wmsgetfeatureinfoformat.test.js index f4ec041a59..aff68e2dc0 100644 --- a/test/spec/ol/format/wmsgetfeatureinfoformat.test.js +++ b/test/spec/ol/format/wmsgetfeatureinfoformat.test.js @@ -20,6 +20,10 @@ describe('ol.format.WMSGetFeatureInfo', function() { }); }); + after(function() { + proj4.defs('urn:x-ogc:def:crs:EPSG:4326', undefined); + }); + it('creates 3 features', function() { expect(features).to.have.length(3); });