ScaledPositionProperty.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import defined from '../Core/defined.js';
  2. import defineProperties from '../Core/defineProperties.js';
  3. import DeveloperError from '../Core/DeveloperError.js';
  4. import Ellipsoid from '../Core/Ellipsoid.js';
  5. import Event from '../Core/Event.js';
  6. import ReferenceFrame from '../Core/ReferenceFrame.js';
  7. import Property from './Property.js';
  8. /**
  9. * This is a temporary class for scaling position properties to the WGS84 surface.
  10. * It will go away or be refactored to support data with arbitrary height references.
  11. * @private
  12. */
  13. function ScaledPositionProperty(value) {
  14. this._definitionChanged = new Event();
  15. this._value = undefined;
  16. this._removeSubscription = undefined;
  17. this.setValue(value);
  18. }
  19. defineProperties(ScaledPositionProperty.prototype, {
  20. isConstant : {
  21. get : function() {
  22. return Property.isConstant(this._value);
  23. }
  24. },
  25. definitionChanged : {
  26. get : function() {
  27. return this._definitionChanged;
  28. }
  29. },
  30. referenceFrame : {
  31. get : function() {
  32. return defined(this._value) ? this._value.referenceFrame : ReferenceFrame.FIXED;
  33. }
  34. }
  35. });
  36. ScaledPositionProperty.prototype.getValue = function(time, result) {
  37. return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
  38. };
  39. ScaledPositionProperty.prototype.setValue = function(value) {
  40. if (this._value !== value) {
  41. this._value = value;
  42. if (defined(this._removeSubscription)) {
  43. this._removeSubscription();
  44. this._removeSubscription = undefined;
  45. }
  46. if (defined(value)) {
  47. this._removeSubscription = value.definitionChanged.addEventListener(this._raiseDefinitionChanged, this);
  48. }
  49. this._definitionChanged.raiseEvent(this);
  50. }
  51. };
  52. ScaledPositionProperty.prototype.getValueInReferenceFrame = function(time, referenceFrame, result) {
  53. //>>includeStart('debug', pragmas.debug);
  54. if (!defined(time)) {
  55. throw new DeveloperError('time is required.');
  56. }
  57. if (!defined(referenceFrame)) {
  58. throw new DeveloperError('referenceFrame is required.');
  59. }
  60. //>>includeEnd('debug');
  61. if (!defined(this._value)) {
  62. return undefined;
  63. }
  64. result = this._value.getValueInReferenceFrame(time, referenceFrame, result);
  65. return defined(result) ? Ellipsoid.WGS84.scaleToGeodeticSurface(result, result) : undefined;
  66. };
  67. ScaledPositionProperty.prototype.equals = function(other) {
  68. return this === other || (other instanceof ScaledPositionProperty && this._value === other._value);
  69. };
  70. ScaledPositionProperty.prototype._raiseDefinitionChanged = function() {
  71. this._definitionChanged.raiseEvent(this);
  72. };
  73. export default ScaledPositionProperty;