All files / engine/Source/Scene ImageryLayerFeatureInfo.js

86.11% Statements 31/36
85.71% Branches 24/28
100% Functions 4/4
86.11% Lines 31/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                          21x             21x             21x             21x           21x                     1x     10x     10x 90x 86x   86x 2x 2x 84x     84x 7x 7x 77x             10x 9x                 1x     14x 14x 122x 122x 122x 121x     121x         14x   14x     14x      
import defined from "../Core/defined.js";
 
/**
 * Describes a rasterized feature, such as a point, polygon, polyline, etc., in an imagery layer.
 *
 * @alias ImageryLayerFeatureInfo
 * @constructor
 */
function ImageryLayerFeatureInfo() {
  /**
   * Gets or sets the name of the feature.
   * @type {string|undefined}
   */
  this.name = undefined;
 
  /**
   * Gets or sets an HTML description of the feature.  The HTML is not trusted and should
   * be sanitized before display to the user.
   * @type {string|undefined}
   */
  this.description = undefined;
 
  /**
   * Gets or sets the position of the feature, or undefined if the position is not known.
   *
   * @type {Cartographic|undefined}
   */
  this.position = undefined;
 
  /**
   * Gets or sets the raw data describing the feature.  The raw data may be in any
   * number of formats, such as GeoJSON, KML, etc.
   * @type {object|undefined}
   */
  this.data = undefined;
 
  /**
   * Gets or sets the image layer of the feature.
   * @type {object|undefined}
   */
  this.imageryLayer = undefined;
}
 
/**
 * Configures the name of this feature by selecting an appropriate property.  The name will be obtained from
 * one of the following sources, in this order: 1) the property with the name 'name', 2) the property with the name 'title',
 * 3) the first property containing the word 'name', 4) the first property containing the word 'title'.  If
 * the name cannot be obtained from any of these sources, the existing name will be left unchanged.
 *
 * @param {object} properties An object literal containing the properties of the feature.
 */
ImageryLayerFeatureInfo.prototype.configureNameFromProperties = function (
  properties,
) {
  let namePropertyPrecedence = 10;
  let nameProperty;
 
  for (const key in properties) {
    if (properties.hasOwnProperty(key) && properties[key]) {
      const lowerKey = key.toLowerCase();
 
      if (namePropertyPrecedence > 1 && lowerKey === "name") {
        namePropertyPrecedence = 1;
        nameProperty = key;
      } else Iif (namePropertyPrecedence > 2 && lowerKey === "title") {
        namePropertyPrecedence = 2;
        nameProperty = key;
      } else if (namePropertyPrecedence > 3 && /name/i.test(key)) {
        namePropertyPrecedence = 3;
        nameProperty = key;
      } else Iif (namePropertyPrecedence > 4 && /title/i.test(key)) {
        namePropertyPrecedence = 4;
        nameProperty = key;
      }
    }
  }
 
  if (defined(nameProperty)) {
    this.name = properties[nameProperty];
  }
};
 
/**
 * Configures the description of this feature by creating an HTML table of properties and their values.
 *
 * @param {object} properties An object literal containing the properties of the feature.
 */
ImageryLayerFeatureInfo.prototype.configureDescriptionFromProperties =
  function (properties) {
    function describe(properties) {
      let html = '<table class="cesium-infoBox-defaultTable">';
      for (const key in properties) {
        Eif (properties.hasOwnProperty(key)) {
          const value = properties[key];
          if (defined(value)) {
            Iif (typeof value === "object") {
              html += `<tr><td>${key}</td><td>${describe(value)}</td></tr>`;
            } else {
              html += `<tr><td>${key}</td><td>${value}</td></tr>`;
            }
          }
        }
      }
      html += "</table>";
 
      return html;
    }
 
    this.description = describe(properties);
  };
export default ImageryLayerFeatureInfo;