Implement read transforms for ol.format.WFS
This commit is contained in:
@@ -94,6 +94,7 @@ ol.format.WFS.schemaLocation_ = 'http://www.opengis.net/wfs ' +
|
|||||||
*
|
*
|
||||||
* @function
|
* @function
|
||||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
* @return {Array.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -103,7 +104,7 @@ ol.format.WFS.prototype.readFeatures;
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.WFS.prototype.readFeaturesFromNode = function(node) {
|
ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||||
var objectStack = [{
|
var objectStack = [{
|
||||||
'featureType': this.featureType_,
|
'featureType': this.featureType_,
|
||||||
'featureNS': this.featureNS_
|
'featureNS': this.featureNS_
|
||||||
@@ -113,6 +114,8 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node) {
|
|||||||
if (!goog.isDef(features)) {
|
if (!goog.isDef(features)) {
|
||||||
features = [];
|
features = [];
|
||||||
}
|
}
|
||||||
|
ol.format.XMLFeature.transformFeaturesWithOptions(
|
||||||
|
features, false, this.getReadOptions(node, opt_options));
|
||||||
return features;
|
return features;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,17 @@ describe('ol.format.WFS', function() {
|
|||||||
|
|
||||||
describe('when parsing TOPP states GML from 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) {
|
before(function(done) {
|
||||||
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
|
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 {
|
try {
|
||||||
var config = {
|
xml = data;
|
||||||
'featureNS': 'http://www.openplans.org/topp',
|
|
||||||
'featureType': 'states'
|
|
||||||
};
|
|
||||||
features = new ol.format.WFS(config).readFeatures(xml);
|
features = new ol.format.WFS(config).readFeatures(xml);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done(e);
|
done(e);
|
||||||
@@ -32,6 +34,20 @@ describe('ol.format.WFS', function() {
|
|||||||
expect(feature.getGeometry()).to.be.an(ol.geom.MultiPolygon);
|
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() {
|
describe('when parsing FeatureCollection', function() {
|
||||||
@@ -388,3 +404,4 @@ goog.require('ol.geom.MultiPoint');
|
|||||||
goog.require('ol.geom.MultiPolygon');
|
goog.require('ol.geom.MultiPolygon');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.format.WFS');
|
goog.require('ol.format.WFS');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
|||||||
Reference in New Issue
Block a user