layer/layerRec/shared.js

  1. 'use strict';
  2. // TODO revisit if we still need rv- in these constants.
  3. const states = { // these are used as css classes; hence the `rv` prefix
  4. NEW: 'rv-new',
  5. REFRESH: 'rv-refresh',
  6. LOADING: 'rv-loading',
  7. LOADED: 'rv-loaded', // TODO maybe loaded and default are the same?
  8. DEFAULT: 'rv-default',
  9. ERROR: 'rv-error'
  10. };
  11. // these match strings in the client.
  12. const clientLayerType = {
  13. ESRI_DYNAMIC: 'esriDynamic',
  14. ESRI_FEATURE: 'esriFeature',
  15. ESRI_IMAGE: 'esriImage',
  16. ESRI_TILE: 'esriTile',
  17. ESRI_GROUP: 'esriGroup',
  18. ESRI_RASTER: 'esriRaster',
  19. OGC_WMS: 'ogcWms',
  20. UNRESOLVED: 'unresolved',
  21. UNKNOWN: 'unknown'
  22. };
  23. // legend data is our modified legend structure.
  24. // it is similar to esri's server output, but all individual
  25. // items are promises.
  26. // TODO proper docs
  27. function makeSymbologyArray(legendData) {
  28. return legendData.map(item => {
  29. const symbologyItem = {
  30. svgcode: null,
  31. name: null
  32. };
  33. // file-based layers don't have symbology labels, default to ''
  34. // legend items are promises
  35. item.then(data => {
  36. symbologyItem.svgcode = data.svgcode;
  37. symbologyItem.name = data.label || '';
  38. });
  39. return symbologyItem;
  40. });
  41. }
  42. /**
  43. * @class IdentifyResult
  44. */
  45. class IdentifyResult {
  46. /**
  47. * @param {String} name layer name of the queried layer
  48. * @param {Array} symbology array of layer symbology to be displayed in details panel
  49. * @param {String} format indicates data formating template
  50. * @param {Object} layerRec layer record for the queried layer
  51. * @param {Integer} featureIdx optional feature index of queried layer (should be provided for attribute based layers)
  52. * @param {String} caption optional captions to be displayed along with the name
  53. */
  54. constructor (name, symbology, format, layerRec, featureIdx, caption) {
  55. // TEST STATUS none
  56. // TODO revisit what should be in this class, and what belongs in the app
  57. // also what can be abstacted to come from layerRec
  58. this.isLoading = true;
  59. this.requestId = -1;
  60. this.requester = {
  61. name,
  62. symbology,
  63. format,
  64. caption,
  65. layerRec,
  66. featureIdx
  67. };
  68. this.data = [];
  69. }
  70. }
  71. module.exports = () => ({
  72. states,
  73. clientLayerType,
  74. makeSymbologyArray,
  75. IdentifyResult
  76. });