Make GetFeatureInfo format pass ol2 test suite
This commit is contained in:
committed by
Florent gravin
parent
d0d6215550
commit
c0f2187310
@@ -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 = [];
|
||||
|
||||
@@ -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 = '<?xml version="1.0" encoding="ISO-8859-1"?>' +
|
||||
'<msGMLOutput xmlns:gml="http://www.opengis.net/gml"' +
|
||||
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
|
||||
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
|
||||
' <AAA64_layer>' +
|
||||
' </AAA64_layer>' +
|
||||
'</msGMLOutput>';
|
||||
var features = new ol.format.GetFeatureInfo().readFeatures(text);
|
||||
expect(features.length).to.be(0);
|
||||
});
|
||||
|
||||
it('read empty attributes', function() {
|
||||
text =
|
||||
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
|
||||
'<msGMLOutput ' +
|
||||
' xmlns:gml="http://www.opengis.net/gml"' +
|
||||
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
|
||||
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
|
||||
' <AAA64_layer>' +
|
||||
' <AAA64_feature>' +
|
||||
' <gml:boundedBy>' +
|
||||
' <gml:Box srsName="EPSG:4326">' +
|
||||
' <gml:coordinates>' +
|
||||
' 107397.266000,460681.063000 116568.188000,480609.250000' +
|
||||
' </gml:coordinates>' +
|
||||
' </gml:Box>' +
|
||||
' </gml:boundedBy>' +
|
||||
' <FOO>bar</FOO>' +
|
||||
' <EMPTY></EMPTY>' +
|
||||
' </AAA64_feature>' +
|
||||
' </AAA64_layer>' +
|
||||
'</msGMLOutput>';
|
||||
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 =
|
||||
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
|
||||
'<msGMLOutput ' +
|
||||
' xmlns:gml="http://www.opengis.net/gml"' +
|
||||
' xmlns:xlink="http://www.w3.org/1999/xlink"' +
|
||||
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
|
||||
' <AAA64_layer>' +
|
||||
' <AAA64_feature>' +
|
||||
' <gml:boundedBy>' +
|
||||
' <gml:Box srsName="EPSG:4326">' +
|
||||
' <gml:coordinates>' +
|
||||
' 129799.109000,467950.250000 133199.906000,468904.063000' +
|
||||
' </gml:coordinates>' +
|
||||
' </gml:Box>' +
|
||||
' </gml:boundedBy>' +
|
||||
' <OBJECTID>287</OBJECTID>' +
|
||||
' <ROUTE>N403</ROUTE>' +
|
||||
' <ROUTE_CH>#N403</ROUTE_CH>' +
|
||||
' <COUNT>1</COUNT>' +
|
||||
' <BEHEERDER>P</BEHEERDER>' +
|
||||
' <LENGTH>4091.25</LENGTH>' +
|
||||
' <SHAPE><shape></SHAPE>' +
|
||||
' <SE_ANNO_CAD_DATA><null></SE_ANNO_CAD_DATA>' +
|
||||
' </AAA64_feature>' +
|
||||
' </AAA64_layer>' +
|
||||
' <AAA62_layer>' +
|
||||
' <AAA62_feature>' +
|
||||
' <gml:boundedBy>' +
|
||||
' <gml:Box srsName="EPSG:4326">' +
|
||||
' <gml:coordinates>' +
|
||||
' 129936.000000,468362.000000 131686.000000,473119.000000' +
|
||||
' </gml:coordinates>' +
|
||||
' </gml:Box>' +
|
||||
' </gml:boundedBy>' +
|
||||
' <OBJECTID>1251</OBJECTID>' +
|
||||
' <VWK_ID>1515</VWK_ID>' +
|
||||
' <VWK_BEGDTM>00:00:00 01/01/1998</VWK_BEGDTM>' +
|
||||
' <VWJ_ID_BEG>1472</VWJ_ID_BEG>' +
|
||||
' <VWJ_ID_END>1309</VWJ_ID_END>' +
|
||||
' <VAKTYPE>D</VAKTYPE>' +
|
||||
' <VRT_CODE>227</VRT_CODE>' +
|
||||
' <VRT_NAAM>Vecht</VRT_NAAM>' +
|
||||
' <VWG_NR>2</VWG_NR>' +
|
||||
' <VWG_NAAM>Vecht</VWG_NAAM>' +
|
||||
' <BEGKM>18.25</BEGKM>' +
|
||||
' <ENDKM>23.995</ENDKM>' +
|
||||
' <LENGTH>5745.09</LENGTH>' +
|
||||
' <SHAPE><shape></SHAPE>' +
|
||||
' <SE_ANNO_CAD_DATA><null></SE_ANNO_CAD_DATA>' +
|
||||
' </AAA62_feature>' +
|
||||
' </AAA62_layer>' +
|
||||
'</msGMLOutput>';
|
||||
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 =
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' +
|
||||
'<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs"' +
|
||||
' xmlns:wfs="http://www.opengis.net/wfs"' +
|
||||
' xmlns:opengeo="http://opengeo.org"' +
|
||||
' xmlns:gml="http://www.opengis.net/gml"' +
|
||||
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
|
||||
' xsi:schemaLocation="http://opengeo.org ' +
|
||||
' http://demo.opengeo.org:80/geoserver/wfs?service=WFS&' +
|
||||
'version=1.0.0&request=DescribeFeatureType&' +
|
||||
'typeName=opengeo:roads http://www.opengis.net/wfs ' +
|
||||
' http://demo.opengeo.org:80/geoserver/schemas/wfs/1.0.0/' +
|
||||
'WFS-basic.xsd">' +
|
||||
' <gml:boundedBy>' +
|
||||
' <gml:Box' +
|
||||
' srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">' +
|
||||
' <gml:coordinates xmlns:gml="http://www.opengis.net/gml"' +
|
||||
' decimal="." cs="," ts=" ">' +
|
||||
'591943.9375,4925605 593045.625,4925845' +
|
||||
' </gml:coordinates>' +
|
||||
' </gml:Box>' +
|
||||
' </gml:boundedBy>' +
|
||||
' <gml:featureMember>' +
|
||||
' <opengeo:roads fid="roads.90">' +
|
||||
' <opengeo:cat>3</opengeo:cat>' +
|
||||
' <opengeo:label>secondary highway, hard surface' +
|
||||
' </opengeo:label>' +
|
||||
' <opengeo:the_geom>' +
|
||||
' <gml:MultiLineString' +
|
||||
' srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">' +
|
||||
' <gml:lineStringMember>' +
|
||||
' <gml:LineString>' +
|
||||
' <gml:coordinates xmlns:gml="http://www.opengis.net/gml"' +
|
||||
' decimal="." cs="," ts=" ">' +
|
||||
'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' +
|
||||
' </gml:coordinates>' +
|
||||
' </gml:LineString>' +
|
||||
' </gml:lineStringMember>' +
|
||||
' </gml:MultiLineString>' +
|
||||
' </opengeo:the_geom>' +
|
||||
' </opengeo:roads>' +
|
||||
' </gml:featureMember>' +
|
||||
'</wfs:FeatureCollection>';
|
||||
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');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<msGMLOutput xmlns="http://mapserver.gis.umn.edu/mapserver" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<msGMLOutput xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<ADCP_2001_layer>
|
||||
<gml:name>ADCP de coque 2001</gml:name>
|
||||
<ADCP_2001_feature>
|
||||
@@ -42,4 +42,4 @@
|
||||
<NAUTILUS_DATA>http://www.ifremer.fr/sismerData/jsp/visualisationMetadata3.jsp?strPortail=ifremer&langue=FR&pageOrigine=CS&cle1=108842_3&cle2=ADCP01</NAUTILUS_DATA>
|
||||
</ADCP_2001_feature>
|
||||
</ADCP_2001_layer>
|
||||
</msGMLOutput>
|
||||
</msGMLOutput>
|
||||
|
||||
Reference in New Issue
Block a user