ImageryLayerFeatureInfo.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*global define*/
  2. define([
  3. '../Core/defined'
  4. ], function(
  5. defined) {
  6. "use strict";
  7. /**
  8. * Describes a rasterized feature, such as a point, polygon, polyline, etc., in an imagery layer.
  9. *
  10. * @alias ImageryLayerFeatureInfo
  11. * @constructor
  12. */
  13. var ImageryLayerFeatureInfo = function() {
  14. /**
  15. * Gets or sets the name of the feature.
  16. * @type {String}
  17. */
  18. this.name = undefined;
  19. /**
  20. * Gets or sets an HTML description of the feature. The HTML is not trusted and should
  21. * be sanitized before display to the user.
  22. * @type {String}
  23. */
  24. this.description = undefined;
  25. /**
  26. * Gets or sets the position of the feature, or undefined if the position is not known.
  27. *
  28. * @type {Cartographic}
  29. */
  30. this.position = undefined;
  31. /**
  32. * Gets or sets the raw data describing the feature. The raw data may be in any
  33. * number of formats, such as GeoJSON, KML, etc.
  34. * @type {Object}
  35. */
  36. this.data = 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(properties) {
  47. var namePropertyPrecedence = 10;
  48. var nameProperty;
  49. for (var key in properties) {
  50. if (properties.hasOwnProperty(key) && properties[key]) {
  51. var lowerKey = key.toLowerCase();
  52. if (namePropertyPrecedence > 1 && lowerKey === 'name') {
  53. namePropertyPrecedence = 1;
  54. nameProperty = key;
  55. } else if (namePropertyPrecedence > 2 && lowerKey === 'title') {
  56. namePropertyPrecedence = 2;
  57. nameProperty = key;
  58. } else if (namePropertyPrecedence > 3 && /name/i.test(key)) {
  59. namePropertyPrecedence = 3;
  60. nameProperty = key;
  61. } else if (namePropertyPrecedence > 4 && /title/i.test(key)) {
  62. namePropertyPrecedence = 4;
  63. nameProperty = key;
  64. }
  65. }
  66. }
  67. if (defined(nameProperty)) {
  68. this.name = properties[nameProperty];
  69. }
  70. };
  71. /**
  72. * Configures the description of this feature by creating an HTML table of properties and their values.
  73. *
  74. * @param {Object} properties An object literal containing the properties of the feature.
  75. */
  76. ImageryLayerFeatureInfo.prototype.configureDescriptionFromProperties = function(properties) {
  77. function describe(properties) {
  78. var html = '<table class="cesium-infoBox-defaultTable">';
  79. for (var key in properties) {
  80. if (properties.hasOwnProperty(key)) {
  81. var value = properties[key];
  82. if (defined(value)) {
  83. if (typeof value === 'object') {
  84. html += '<tr><td>' + key + '</td><td>' + describe(value) + '</td></tr>';
  85. } else {
  86. html += '<tr><td>' + key + '</td><td>' + value + '</td></tr>';
  87. }
  88. }
  89. }
  90. }
  91. html += '</table>';
  92. return html;
  93. }
  94. this.description = describe(properties);
  95. };
  96. return ImageryLayerFeatureInfo;
  97. });