HomeButtonViewModel.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import defined from "../../Core/defined.js";
  2. import DeveloperError from "../../Core/DeveloperError.js";
  3. import knockout from "../../ThirdParty/knockout.js";
  4. import createCommand from "../createCommand.js";
  5. /**
  6. * The view model for {@link HomeButton}.
  7. * @alias HomeButtonViewModel
  8. * @constructor
  9. *
  10. * @param {Scene} scene The scene instance to use.
  11. * @param {Number} [duration] The duration of the camera flight in seconds.
  12. */
  13. function HomeButtonViewModel(scene, duration) {
  14. //>>includeStart('debug', pragmas.debug);
  15. if (!defined(scene)) {
  16. throw new DeveloperError("scene is required.");
  17. }
  18. //>>includeEnd('debug');
  19. this._scene = scene;
  20. this._duration = duration;
  21. const that = this;
  22. this._command = createCommand(function () {
  23. that._scene.camera.flyHome(that._duration);
  24. });
  25. /**
  26. * Gets or sets the tooltip. This property is observable.
  27. *
  28. * @type {String}
  29. */
  30. this.tooltip = "View Home";
  31. knockout.track(this, ["tooltip"]);
  32. }
  33. Object.defineProperties(HomeButtonViewModel.prototype, {
  34. /**
  35. * Gets the scene to control.
  36. * @memberof HomeButtonViewModel.prototype
  37. *
  38. * @type {Scene}
  39. */
  40. scene: {
  41. get: function () {
  42. return this._scene;
  43. },
  44. },
  45. /**
  46. * Gets the Command that is executed when the button is clicked.
  47. * @memberof HomeButtonViewModel.prototype
  48. *
  49. * @type {Command}
  50. */
  51. command: {
  52. get: function () {
  53. return this._command;
  54. },
  55. },
  56. /**
  57. * Gets or sets the the duration of the camera flight in seconds.
  58. * A value of zero causes the camera to instantly switch to home view.
  59. * The duration will be computed based on the distance when undefined.
  60. * @memberof HomeButtonViewModel.prototype
  61. *
  62. * @type {Number|undefined}
  63. */
  64. duration: {
  65. get: function () {
  66. return this._duration;
  67. },
  68. set: function (value) {
  69. //>>includeStart('debug', pragmas.debug);
  70. if (defined(value) && value < 0) {
  71. throw new DeveloperError("value must be positive.");
  72. }
  73. //>>includeEnd('debug');
  74. this._duration = value;
  75. },
  76. },
  77. });
  78. export default HomeButtonViewModel;