Renaming & better typing
This commit is contained in:
@@ -8,7 +8,6 @@ goog.require('goog.object');
|
|||||||
goog.require('goog.string');
|
goog.require('goog.string');
|
||||||
goog.require('ol.format.GML');
|
goog.require('ol.format.GML');
|
||||||
goog.require('ol.format.GML2');
|
goog.require('ol.format.GML2');
|
||||||
goog.require('ol.format.GMLBase');
|
|
||||||
goog.require('ol.format.XMLFeature');
|
goog.require('ol.format.XMLFeature');
|
||||||
goog.require('ol.xml');
|
goog.require('ol.xml');
|
||||||
|
|
||||||
@@ -16,16 +15,14 @@ goog.require('ol.xml');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
* Format for reading GetFeatureInfo format.It uses
|
* Format for reading WMSGetFeatureInfo format. It uses
|
||||||
* ol.format.GML2 to read features.
|
* {@link ol.format.GML2} to read features.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {olx.format.GMLOptions=} opt_options
|
|
||||||
* Optional configuration object.
|
|
||||||
* @extends {ol.format.XMLFeature}
|
* @extends {ol.format.XMLFeature}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.format.GetFeatureInfo = function(opt_options) {
|
ol.format.WMSGetFeatureInfo = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -36,27 +33,13 @@ ol.format.GetFeatureInfo = function(opt_options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {string}
|
* @type {ol.format.GML2}
|
||||||
*/
|
|
||||||
this.featureIdentifier_ = '_feature';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
this.layerIdentifier_ = '_layer';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {ol.format.GMLBase}
|
|
||||||
*/
|
*/
|
||||||
this.gmlFormat_ = new ol.format.GML2();
|
this.gmlFormat_ = new ol.format.GML2();
|
||||||
|
|
||||||
goog.base(this);
|
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}
|
* @type {string}
|
||||||
* @private
|
* @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.<ol.Feature>} Features.
|
* @return {Array.<ol.Feature>} Features.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) {
|
ol.format.WMSGetFeatureInfo.prototype.readFeatures_ =
|
||||||
|
function(node, objectStack) {
|
||||||
|
|
||||||
node.namespaceURI = this.featureNS_;
|
node.namespaceURI = this.featureNS_;
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
var localName = ol.xml.getLocalName(node);
|
var localName = ol.xml.getLocalName(node);
|
||||||
|
/** @type {Array.<ol.Feature>} */
|
||||||
var features = [];
|
var features = [];
|
||||||
if (node.childNodes.length === 0) {
|
if (node.childNodes.length === 0) {
|
||||||
return features;
|
return features;
|
||||||
@@ -90,10 +83,12 @@ ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) {
|
|||||||
var context = objectStack[0];
|
var context = objectStack[0];
|
||||||
goog.asserts.assert(goog.isObject(context));
|
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,
|
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, 'featureType', featureType);
|
||||||
goog.object.set(context, 'featureNS', this.featureNS_);
|
goog.object.set(context, 'featureNS', this.featureNS_);
|
||||||
@@ -107,17 +102,17 @@ ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) {
|
|||||||
var layerFeatures = ol.xml.pushParseAndPop(
|
var layerFeatures = ol.xml.pushParseAndPop(
|
||||||
[], parsersNS, layer, objectStack, this.gmlFormat_);
|
[], parsersNS, layer, objectStack, this.gmlFormat_);
|
||||||
if (goog.isDef(layerFeatures)) {
|
if (goog.isDef(layerFeatures)) {
|
||||||
goog.array.extend(/** @type {Array} */ (features), layerFeatures);
|
goog.array.extend(features, layerFeatures);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
if (localName == 'FeatureCollection') {
|
if (localName == 'FeatureCollection') {
|
||||||
features = ol.xml.pushParseAndPop([],
|
var gmlFeatures = ol.xml.pushParseAndPop([],
|
||||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||||
[{}], this.gmlFormat_);
|
[{}], this.gmlFormat_);
|
||||||
}
|
if (goog.isDef(gmlFeatures)) {
|
||||||
if (!goog.isDef(features)) {
|
features = gmlFeatures;
|
||||||
features = [];
|
}
|
||||||
}
|
}
|
||||||
return features;
|
return features;
|
||||||
};
|
};
|
||||||
@@ -126,7 +121,7 @@ ol.format.GetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.format.GetFeatureInfo.prototype.readFeaturesFromNode =
|
ol.format.WMSGetFeatureInfo.prototype.readFeaturesFromNode =
|
||||||
function(node, opt_options) {
|
function(node, opt_options) {
|
||||||
var options = {
|
var options = {
|
||||||
'featureType': this.featureType,
|
'featureType': this.featureType,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ describe('ol.format.WMSGetFeatureInfo', function() {
|
|||||||
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/wms/getfeatureinfo.xml', function(data) {
|
afterLoadText('spec/ol/format/wms/getfeatureinfo.xml', function(data) {
|
||||||
try {
|
try {
|
||||||
features = new ol.format.GetFeatureInfo().readFeatures(data);
|
features = new ol.format.WMSGetFeatureInfo().readFeatures(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ describe('ol.format.WMSGetFeatureInfo', function() {
|
|||||||
' <AAA64_layer>' +
|
' <AAA64_layer>' +
|
||||||
' </AAA64_layer>' +
|
' </AAA64_layer>' +
|
||||||
'</msGMLOutput>';
|
'</msGMLOutput>';
|
||||||
var features = new ol.format.GetFeatureInfo().readFeatures(text);
|
var features = new ol.format.WMSGetFeatureInfo().readFeatures(text);
|
||||||
expect(features.length).to.be(0);
|
expect(features.length).to.be(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ describe('ol.format.WMSGetFeatureInfo', function() {
|
|||||||
' </AAA64_feature>' +
|
' </AAA64_feature>' +
|
||||||
' </AAA64_layer>' +
|
' </AAA64_layer>' +
|
||||||
'</msGMLOutput>';
|
'</msGMLOutput>';
|
||||||
var features = new ol.format.GetFeatureInfo().readFeatures(text);
|
var features = new ol.format.WMSGetFeatureInfo().readFeatures(text);
|
||||||
expect(features.length).to.be(1);
|
expect(features.length).to.be(1);
|
||||||
expect(features[0].get('FOO')).to.be('bar');
|
expect(features[0].get('FOO')).to.be('bar');
|
||||||
// FIXME is that really wanted ?
|
// FIXME is that really wanted ?
|
||||||
@@ -132,7 +132,7 @@ describe('ol.format.WMSGetFeatureInfo', function() {
|
|||||||
' </AAA62_feature>' +
|
' </AAA62_feature>' +
|
||||||
' </AAA62_layer>' +
|
' </AAA62_layer>' +
|
||||||
'</msGMLOutput>';
|
'</msGMLOutput>';
|
||||||
var features = new ol.format.GetFeatureInfo().readFeatures(text);
|
var features = new ol.format.WMSGetFeatureInfo().readFeatures(text);
|
||||||
expect(features.length).to.be(2);
|
expect(features.length).to.be(2);
|
||||||
expect(features[0].get('OBJECTID')).to.be('287');
|
expect(features[0].get('OBJECTID')).to.be('287');
|
||||||
expect(features[1].get('OBJECTID')).to.be('1251');
|
expect(features[1].get('OBJECTID')).to.be('1251');
|
||||||
@@ -188,7 +188,7 @@ describe('ol.format.WMSGetFeatureInfo', function() {
|
|||||||
' </opengeo:roads>' +
|
' </opengeo:roads>' +
|
||||||
' </gml:featureMember>' +
|
' </gml:featureMember>' +
|
||||||
'</wfs:FeatureCollection>';
|
'</wfs:FeatureCollection>';
|
||||||
var features = new ol.format.GetFeatureInfo().readFeatures(text);
|
var features = new ol.format.WMSGetFeatureInfo().readFeatures(text);
|
||||||
expect(features.length).to.be(1);
|
expect(features.length).to.be(1);
|
||||||
expect(features[0].get('cat')).to.be('3');
|
expect(features[0].get('cat')).to.be('3');
|
||||||
expect(features[0].getGeometry().getType()).to.be('MultiLineString');
|
expect(features[0].getGeometry().getType()).to.be('MultiLineString');
|
||||||
|
|||||||
Reference in New Issue
Block a user