layer/layerRec/dynamicFC.js

  1. 'use strict';
  2. const attribFC = require('./attribFC.js')();
  3. /**
  4. * @class DynamicFC
  5. */
  6. class DynamicFC extends attribFC.AttribFC {
  7. // dynamic child variant for feature class object.
  8. // deals with stuff specific to dynamic children (i.e. virtual layer on client)
  9. /**
  10. * Create an feature class object for a feature class that is a child of a dynamic layer
  11. * @param {Object} parent the Record object that this Feature Class belongs to
  12. * @param {String} idx the service index of this Feature Class. an integer in string format. use '0' for non-indexed sources.
  13. * @param {Object} layerPackage a layer package object from the attribute module for this feature class
  14. * @param {Object} config the config object for this sublayer
  15. */
  16. constructor (parent, idx, layerPackage, config) {
  17. super(parent, idx, layerPackage, config);
  18. // store pointer to the layerinfo for this FC.
  19. // while most information here can also be gleaned from the layer object,
  20. // we cannot know the type (e.g. Feature Layer, Raster Layer), so this object
  21. // is required.
  22. // TODO revist _layerInfo and how it is used.
  23. this._layerInfo = parent._layer.layerInfos[idx];
  24. this.opacity = config.state.opacity;
  25. // visibility is kept stateful by the parent. keeping an internal property
  26. // just means we would need to keep it in synch.
  27. // the DynamicRecord onLoad handler will set the initial state, so don't do it here.
  28. }
  29. get supportsOpacity () { return this._parent._isTrueDynamic; }
  30. get opacity () { return this._opacity; }
  31. set opacity (value) {
  32. this._opacity = value;
  33. if (this.supportsOpacity) {
  34. // only attempt to set the layer if we support that kind of magic.
  35. // instead of being consistent, esri using value from 0 to 100 for sublayer transparency where 100 is fully transparent
  36. const optionsArray = [];
  37. const drawingOptions = new this._parent._apiRef.layer.LayerDrawingOptions();
  38. drawingOptions.transparency = (value - 1) * -100;
  39. optionsArray[this._idx] = drawingOptions;
  40. this._parent._layer.setLayerDrawingOptions(optionsArray);
  41. }
  42. }
  43. // returns an object with minScale and maxScale values for the feature class
  44. getScaleSet () {
  45. // get the layerData promise for this FC, wait for it to load,
  46. // then return the scale data
  47. return this.getLayerData().then(lData => {
  48. return {
  49. minScale: lData.minScale,
  50. maxScale: lData.maxScale
  51. };
  52. });
  53. }
  54. get geomType () { return this._geometryType; }
  55. set geomType (value) { this._geometryType = value; }
  56. get featureCount () { return this._fcount; }
  57. set featureCount (value) { this._fcount = value; }
  58. setVisibility (value) {
  59. // update visible layers array
  60. const vLayers = this._parent._layer.visibleLayers.concat();
  61. const intIdx = parseInt(this._idx);
  62. const vIdx = vLayers.indexOf(intIdx);
  63. let dirty = false;
  64. if (value && vIdx === -1) {
  65. // check for first added case
  66. if (vLayers.length === 1 && vLayers[0] === -1) {
  67. vLayers.pop();
  68. }
  69. // was invisible, now visible
  70. vLayers.push(intIdx);
  71. dirty = true;
  72. } else if (!value && vIdx > -1) {
  73. // was visible, now invisible
  74. vLayers.splice(vIdx, 1);
  75. if (vLayers.length === 0) {
  76. vLayers.push(-1); // code for no layers
  77. }
  78. dirty = true;
  79. }
  80. if (dirty) {
  81. this._parent._layer.setVisibleLayers(vLayers);
  82. this._parent._layer.setVisibility(value);
  83. }
  84. // TODO add a timer or something to cache requests.
  85. // use setVisibileLayers(arry, true) to stall the redraw
  86. // then when timer runs out, call layer.refresh
  87. // TODO maybe alert the parent that we changed?
  88. // this.visibleChanged(value);
  89. }
  90. // TODO extend this function to other FC's? do they need it?
  91. getVisibility () {
  92. // TEST STATUS none
  93. // TODO would we ever need to worry about _parent._layer.visible being false while
  94. // the visibleLayers array still contains valid indexes?
  95. return this._parent._layer.visibleLayers.indexOf(parseInt(this._idx)) > -1;
  96. }
  97. }
  98. module.exports = () => ({
  99. DynamicFC
  100. });