ImageryLayerFeatureInfo.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import defined from "../Core/defined.js";
  2. /**
  3. * Describes a rasterized feature, such as a point, polygon, polyline, etc., in an imagery layer.
  4. *
  5. * @alias ImageryLayerFeatureInfo
  6. * @constructor
  7. */
  8. function ImageryLayerFeatureInfo() {
  9. /**
  10. * Gets or sets the name of the feature.
  11. * @type {String|undefined}
  12. */
  13. this.name = undefined;
  14. /**
  15. * Gets or sets an HTML description of the feature. The HTML is not trusted and should
  16. * be sanitized before display to the user.
  17. * @type {String|undefined}
  18. */
  19. this.description = undefined;
  20. /**
  21. * Gets or sets the position of the feature, or undefined if the position is not known.
  22. *
  23. * @type {Cartographic|undefined}
  24. */
  25. this.position = undefined;
  26. /**
  27. * Gets or sets the raw data describing the feature. The raw data may be in any
  28. * number of formats, such as GeoJSON, KML, etc.
  29. * @type {Object|undefined}
  30. */
  31. this.data = undefined;
  32. /**
  33. * Gets or sets the image layer of the feature.
  34. * @type {Object|undefined}
  35. */
  36. this.imageryLayer = undefined;
  37. }
  38. /**
  39. * Configures the name of this feature by selecting an appropriate property. The name will be obtained from
  40. * one of the following sources, in this order: 1) the property with the name 'name', 2) the property with the name 'title',
  41. * 3) the first property containing the word 'name', 4) the first property containing the word 'title'. If
  42. * the name cannot be obtained from any of these sources, the existing name will be left unchanged.
  43. *
  44. * @param {Object} properties An object literal containing the properties of the feature.
  45. */
  46. ImageryLayerFeatureInfo.prototype.configureNameFromProperties = function (
  47. properties
  48. ) {
  49. let namePropertyPrecedence = 10;
  50. let nameProperty;
  51. for (const key in properties) {
  52. if (properties.hasOwnProperty(key) && properties[key]) {
  53. const lowerKey = key.toLowerCase();
  54. if (namePropertyPrecedence > 1 && lowerKey === "name") {
  55. namePropertyPrecedence = 1;
  56. nameProperty = key;
  57. } else if (namePropertyPrecedence > 2 && lowerKey === "title") {
  58. namePropertyPrecedence = 2;
  59. nameProperty = key;
  60. } else if (namePropertyPrecedence > 3 && /name/i.test(key)) {
  61. namePropertyPrecedence = 3;
  62. nameProperty = key;
  63. } else if (namePropertyPrecedence > 4 && /title/i.test(key)) {
  64. namePropertyPrecedence = 4;
  65. nameProperty = key;
  66. }
  67. }
  68. }
  69. if (defined(nameProperty)) {
  70. this.name = properties[nameProperty];
  71. }
  72. };
  73. /**
  74. * Configures the description of this feature by creating an HTML table of properties and their values.
  75. *
  76. * @param {Object} properties An object literal containing the properties of the feature.
  77. */
  78. ImageryLayerFeatureInfo.prototype.configureDescriptionFromProperties = function (
  79. properties
  80. ) {
  81. function describe(properties) {
  82. let html = '<table class="cesium-infoBox-defaultTable">';
  83. for (const key in properties) {
  84. if (properties.hasOwnProperty(key)) {
  85. const value = properties[key];
  86. if (defined(value)) {
  87. if (typeof value === "object") {
  88. html += `<tr><td>${key}</td><td>${describe(value)}</td></tr>`;
  89. } else {
  90. html += `<tr><td>${key}</td><td>${value}</td></tr>`;
  91. }
  92. }
  93. }
  94. }
  95. html += "</table>";
  96. return html;
  97. }
  98. this.description = describe(properties);
  99. };
  100. export default ImageryLayerFeatureInfo;