# all files / ol/format/ wmsgetfeatureinfoformat.js

96.15% Statements 50/52
71.43% Branches 10/14
100% Functions 3/3
96.15% Lines 50/52

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    1481×

    1×
    1×
    1×
    1×
    1×
    1×
    1×

    1×

    5×

    5×

    5×

    1×

    1×

    1×

    1×

    5×
    5×

    5×

    5×
    5×

    5×
    4×
    11×
    11×
    6×

    5×
    5×

    5×

    5×
    5×

    5×
    5×

    5×
    5×

    5×

    5×
    5×

    5×
    5×

    5×
    1×

    1×
    1×

    5×

    1×

    1×

    5×

    5×

    5×

     goog.provide('ol.format.WMSGetFeatureInfo');

    goog.require('goog.array');
    goog.require('goog.asserts');
    goog.require('goog.dom.NodeType');
    goog.require('goog.object');
    goog.require('ol.format.GML2');
    goog.require('ol.format.XMLFeature');
    goog.require('ol.xml');

    /**
     * @classdesc
     * Format for reading WMSGetFeatureInfo format. It uses
     * {@link ol.format.GML2} to read features.
     *
     * @constructor
     * @extends {ol.format.XMLFeature}
     * @api
     */
    ol.format.WMSGetFeatureInfo = function() {

      /**
       * @private
       * @type {string}
       */
      this.featureNS_ = 'http://mapserver.gis.umn.edu/mapserver';

      /**
       * @private
       * @type {ol.format.GML2}
       */
      this.gmlFormat_ = new ol.format.GML2();

      goog.base(this);
    };
    goog.inherits(ol.format.WMSGetFeatureInfo, ol.format.XMLFeature);

    /**
     * @const
     * @type {string}
     * @private
     */
    ol.format.WMSGetFeatureInfo.featureIdentifier_ = '_feature';

    /**
     * @const
     * @type {string}
     * @private
     */
    ol.format.WMSGetFeatureInfo.layerIdentifier_ = '_layer';

    /**
     * @param {Node} node Node.
     * @param {Array.<*>} objectStack Object stack.
     * @return {Array.<ol.Feature>} Features.
     * @private
     */
    ol.format.WMSGetFeatureInfo.prototype.readFeatures_ =
        function(node, objectStack) {

      node.namespaceURI = this.featureNS_;
      goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
          'node.nodeType should be ELEMENT');
      var localName = ol.xml.getLocalName(node);
      /** @type {Array.<ol.Feature>} */
      var features = [];
      Iif (node.childNodes.length === 0) {
        return features;
      }
      if (localName == 'msGMLOutput') {
        for (var i = 0, ii = node.childNodes.length; i < ii; i++) {
          var layer = node.childNodes[i];
          if (layer.nodeType !== goog.dom.NodeType.ELEMENT) {
            continue;
          }
          var context = objectStack[0];
          goog.asserts.assert(goog.isObject(context),
              'context should be an Object');

          goog.asserts.assert(layer.localName.indexOf(
              ol.format.WMSGetFeatureInfo.layerIdentifier_) >= 0,
              'localName of layer node should match layerIdentifier');

          var toRemove = ol.format.WMSGetFeatureInfo.layerIdentifier_;
          var featureType = layer.localName.replace(toRemove, '') +
              ol.format.WMSGetFeatureInfo.featureIdentifier_;

          context['featureType'] = featureType;
          context['featureNS'] = this.featureNS_;

          var parsers = {};
          parsers[featureType] = ol.xml.makeArrayPusher(
              this.gmlFormat_.readFeatureElement, this.gmlFormat_);
          var parsersNS = ol.xml.makeStructureNS(
              [context['featureNS'], null], parsers);
          layer.namespaceURI = this.featureNS_;
          var layerFeatures = ol.xml.pushParseAndPop(
              [], parsersNS, layer, objectStack, this.gmlFormat_);
          Eif (layerFeatures) {
            goog.array.extend(features, layerFeatures);
          }
        }
      }
      if (localName == 'FeatureCollection') {
        var gmlFeatures = ol.xml.pushParseAndPop([],
            this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
            [{}], this.gmlFormat_);
        Eif (gmlFeatures) {
          features = gmlFeatures;
        }
      }
      return features;
    };

    /**
     * Read all features from a WMSGetFeatureInfo response.
     *
     * @function
     * @param {Document|Node|Object|string} source Source.
     * @param {olx.format.ReadOptions=} opt_options Options.
     * @return {Array.<ol.Feature>} Features.
     * @api stable
     */
    ol.format.WMSGetFeatureInfo.prototype.readFeatures;

    /**
     * @inheritDoc
     */
    ol.format.WMSGetFeatureInfo.prototype.readFeaturesFromNode =
        function(node, opt_options) {
      var options = {
        'featureType': this.featureType,
        'featureNS': this.featureNS
      };
      Iif (opt_options) {
        goog.object.extend(options, this.getReadOptions(node, opt_options));
      }
      return this.readFeatures_(node, [options]);
    };