layer/layerRec/placeholderFC.js

  1. 'use strict';
  2. const root = require('./root.js')();
  3. const shared = require('./shared.js')();
  4. const rcolour = require('rcolor');
  5. class PlaceholderFC extends root.Root {
  6. // contains dummy stuff to stop placeholder states from freaking out
  7. // prior to a layer being loaded.
  8. /**
  9. * Create a placeholder FC to provide enough information for the UI to display
  10. * content while we wait for the layer to load.
  11. *
  12. * @param {Object} parent the Record object the placeholder belongs to
  13. * @param {String} name visible name for placeholder (shown in app)
  14. */
  15. constructor (parent, name) {
  16. super();
  17. this._parent = parent;
  18. this.name = name;
  19. this._layerType = shared.clientLayerType.UNKNOWN;
  20. const c = rcolour({ saturation: 0.4, value: 0.8 });
  21. this.symbology = [parent._apiRef.symbology.generatePlaceholderSymbology(name || '?', c)];
  22. }
  23. /**
  24. * Indicates visibility of the FC.
  25. *
  26. * @function getVisibility
  27. * @returns {Boolean} the visibility of the FC
  28. */
  29. getVisibility () {
  30. // TODO enhance to have some default value, assigned in constructor?
  31. // TODO can a user toggle placeholders? does state need to be updated?
  32. return true;
  33. }
  34. // TODO do we need to check if parent exists? Placeholder use-cases are not flushed out right now.
  35. get state () { return this._parent._state; }
  36. get layerType () {return this._layerType; }
  37. set layerType (value) { this._layerType = value; }
  38. // really this is the client layer type. how it is implemented in the map stack.
  39. // for FCs, it is essentially giving information about what type of Record
  40. // the FC is living in. Helps differentiate a feature-based FC living in a
  41. // feature Record (feature layer) vs a dynamic Record (dynamic layer)
  42. get parentLayerType () { return this._parent.layerType; }
  43. }
  44. module.exports = () => ({
  45. PlaceholderFC
  46. });