ScaledPositionProperty.js 2.6 KB

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