HomeButtonViewModel.js 2.0 KB

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