智慧水务管理系统 - 精河县供水工程综合管理平台

ScaledPositionProperty.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 JulianDate from "../Core/JulianDate.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 ellipsoid 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. Object.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)
  33. ? this._value.referenceFrame
  34. : ReferenceFrame.FIXED;
  35. },
  36. },
  37. });
  38. const timeScratch = new JulianDate();
  39. ScaledPositionProperty.prototype.getValue = function (time, result) {
  40. if (!defined(time)) {
  41. time = JulianDate.now(timeScratch);
  42. }
  43. return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
  44. };
  45. ScaledPositionProperty.prototype.setValue = function (value) {
  46. if (this._value !== value) {
  47. this._value = value;
  48. if (defined(this._removeSubscription)) {
  49. this._removeSubscription();
  50. this._removeSubscription = undefined;
  51. }
  52. if (defined(value)) {
  53. this._removeSubscription = value.definitionChanged.addEventListener(
  54. this._raiseDefinitionChanged,
  55. this,
  56. );
  57. }
  58. this._definitionChanged.raiseEvent(this);
  59. }
  60. };
  61. ScaledPositionProperty.prototype.getValueInReferenceFrame = function (
  62. time,
  63. referenceFrame,
  64. result,
  65. ) {
  66. //>>includeStart('debug', pragmas.debug);
  67. if (!defined(time)) {
  68. throw new DeveloperError("time is required.");
  69. }
  70. if (!defined(referenceFrame)) {
  71. throw new DeveloperError("referenceFrame is required.");
  72. }
  73. //>>includeEnd('debug');
  74. if (!defined(this._value)) {
  75. return undefined;
  76. }
  77. result = this._value.getValueInReferenceFrame(time, referenceFrame, result);
  78. return defined(result)
  79. ? Ellipsoid.default.scaleToGeodeticSurface(result, result)
  80. : undefined;
  81. };
  82. ScaledPositionProperty.prototype.equals = function (other) {
  83. return (
  84. this === other ||
  85. (other instanceof ScaledPositionProperty && this._value === other._value)
  86. );
  87. };
  88. ScaledPositionProperty.prototype._raiseDefinitionChanged = function () {
  89. this._definitionChanged.raiseEvent(this);
  90. };
  91. export default ScaledPositionProperty;