diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 2f64506664..ca7eea37d1 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -94,6 +94,7 @@ ol.format.WFS.schemaLocation_ = 'http://www.opengis.net/wfs ' + * * @function * @param {ArrayBuffer|Document|Node|Object|string} source Source. + * @param {olx.format.ReadOptions=} opt_options Read options. * @return {Array.} Features. * @api */ @@ -103,7 +104,7 @@ ol.format.WFS.prototype.readFeatures; /** * @inheritDoc */ -ol.format.WFS.prototype.readFeaturesFromNode = function(node) { +ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) { var objectStack = [{ 'featureType': this.featureType_, 'featureNS': this.featureNS_ @@ -113,6 +114,8 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node) { if (!goog.isDef(features)) { features = []; } + ol.format.XMLFeature.transformFeaturesWithOptions( + features, false, this.getReadOptions(node, opt_options)); return features; }; diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 411842bf2f..a68e3b1e55 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -4,15 +4,17 @@ describe('ol.format.WFS', function() { describe('when parsing TOPP states GML from WFS', function() { - var features, feature; + var features, feature, xml; + var config = { + 'featureNS': 'http://www.openplans.org/topp', + 'featureType': 'states' + }; + before(function(done) { proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326')); - afterLoadText('spec/ol/format/wfs/topp-states-wfs.xml', function(xml) { + afterLoadText('spec/ol/format/wfs/topp-states-wfs.xml', function(data) { try { - var config = { - 'featureNS': 'http://www.openplans.org/topp', - 'featureType': 'states' - }; + xml = data; features = new ol.format.WFS(config).readFeatures(xml); } catch (e) { done(e); @@ -32,6 +34,20 @@ describe('ol.format.WFS', function() { expect(feature.getGeometry()).to.be.an(ol.geom.MultiPolygon); }); + it('transforms and creates a polygon for Illinois', function() { + features = new ol.format.WFS(config).readFeatures(xml, { + featureProjection: 'EPSG:3857' + }); + feature = features[0]; + expect(feature.getId()).to.equal('states.1'); + expect(feature.get('STATE_NAME')).to.equal('Illinois'); + var geom = feature.getGeometry(); + expect(geom).to.be.an(ol.geom.MultiPolygon); + var p = ol.proj.transform([-88.071, 37.511], 'EPSG:4326', 'EPSG:3857'); + p.push(0); + expect(geom.getFirstCoordinate()).to.eql(p); + }); + }); describe('when parsing FeatureCollection', function() { @@ -388,3 +404,4 @@ goog.require('ol.geom.MultiPoint'); goog.require('ol.geom.MultiPolygon'); goog.require('ol.geom.Polygon'); goog.require('ol.format.WFS'); +goog.require('ol.proj');