ToggleButtonViewModel.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { defaultValue, defined, DeveloperError } from "@cesium/engine";
  2. import knockout from "./ThirdParty/knockout.js";
  3. /**
  4. * A view model which exposes the properties of a toggle button.
  5. * @alias ToggleButtonViewModel
  6. * @constructor
  7. *
  8. * @param {Command} command The command which will be executed when the button is toggled.
  9. * @param {object} [options] Object with the following properties:
  10. * @param {boolean} [options.toggled=false] A boolean indicating whether the button should be initially toggled.
  11. * @param {string} [options.tooltip=''] A string containing the button's tooltip.
  12. */
  13. function ToggleButtonViewModel(command, options) {
  14. //>>includeStart('debug', pragmas.debug);
  15. if (!defined(command)) {
  16. throw new DeveloperError("command is required.");
  17. }
  18. //>>includeEnd('debug');
  19. this._command = command;
  20. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  21. /**
  22. * Gets or sets whether the button is currently toggled. This property is observable.
  23. * @type {boolean}
  24. * @default false
  25. */
  26. this.toggled = defaultValue(options.toggled, false);
  27. /**
  28. * Gets or sets the button's tooltip. This property is observable.
  29. * @type {string}
  30. * @default ''
  31. */
  32. this.tooltip = defaultValue(options.tooltip, "");
  33. knockout.track(this, ["toggled", "tooltip"]);
  34. }
  35. Object.defineProperties(ToggleButtonViewModel.prototype, {
  36. /**
  37. * Gets the command which will be executed when the button is toggled.
  38. * @memberof ToggleButtonViewModel.prototype
  39. * @type {Command}
  40. */
  41. command: {
  42. get: function () {
  43. return this._command;
  44. },
  45. },
  46. });
  47. export default ToggleButtonViewModel;