Add layerName option for WMSGetFeatureInfo format

This option allows the format to read only features of a
given layer. This is useful if you wish to make a single
query to a WMS server with multiple layers in it.
This commit is contained in:
Alexandre Dubé
2016-01-21 10:54:26 -05:00
parent b9c3981261
commit 906a132e89
6 changed files with 384 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.dom.NodeType');
goog.require('goog.object');
goog.require('ol.array');
goog.require('ol.format.GML2');
goog.require('ol.format.XMLFeature');
goog.require('ol.xml');
@@ -16,9 +17,12 @@ goog.require('ol.xml');
*
* @constructor
* @extends {ol.format.XMLFeature}
* @param {olx.format.WMSGetFeatureInfoOptions=} opt_options Options.
* @api
*/
ol.format.WMSGetFeatureInfo = function() {
ol.format.WMSGetFeatureInfo = function(opt_options) {
var options = opt_options ? opt_options : {};
/**
* @private
@@ -33,6 +37,13 @@ ol.format.WMSGetFeatureInfo = function() {
*/
this.gmlFormat_ = new ol.format.GML2();
/**
* @private
* @type {Array.<string>}
*/
this.layers_ = options.layers ? options.layers : null;
goog.base(this);
};
goog.inherits(ol.format.WMSGetFeatureInfo, ol.format.XMLFeature);
@@ -86,7 +97,13 @@ ol.format.WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack
'localName of layer node should match layerIdentifier');
var toRemove = ol.format.WMSGetFeatureInfo.layerIdentifier_;
var featureType = layer.localName.replace(toRemove, '') +
var layerName = layer.localName.replace(toRemove, '');
if (this.layers_ && !ol.array.includes(this.layers_, layerName)) {
continue;
}
var featureType = layerName +
ol.format.WMSGetFeatureInfo.featureIdentifier_;
context['featureType'] = featureType;