All files / widgets/Source/HomeButton HomeButtonViewModel.js

75% Statements 12/16
33.33% Branches 2/6
66.66% Functions 4/6
75% Lines 12/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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