FullscreenButton.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {
  2. defined,
  3. destroyObject,
  4. DeveloperError,
  5. getElement,
  6. } from "@cesium/engine";
  7. import knockout from "../ThirdParty/knockout.js";
  8. import FullscreenButtonViewModel from "./FullscreenButtonViewModel.js";
  9. const enterFullScreenPath =
  10. "M 83.96875 17.5625 L 83.96875 17.59375 L 76.65625 24.875 L 97.09375 24.96875 L 76.09375 45.96875 L 81.9375 51.8125 L 102.78125 30.9375 L 102.875 51.15625 L 110.15625 43.875 L 110.1875 17.59375 L 83.96875 17.5625 z M 44.125 17.59375 L 17.90625 17.625 L 17.9375 43.90625 L 25.21875 51.1875 L 25.3125 30.96875 L 46.15625 51.8125 L 52 45.96875 L 31 25 L 51.4375 24.90625 L 44.125 17.59375 z M 46.0625 76.03125 L 25.1875 96.875 L 25.09375 76.65625 L 17.8125 83.9375 L 17.8125 110.21875 L 44 110.25 L 51.3125 102.9375 L 30.90625 102.84375 L 51.875 81.875 L 46.0625 76.03125 z M 82 76.15625 L 76.15625 82 L 97.15625 103 L 76.71875 103.0625 L 84.03125 110.375 L 110.25 110.34375 L 110.21875 84.0625 L 102.9375 76.8125 L 102.84375 97 L 82 76.15625 z";
  11. const exitFullScreenPath =
  12. "M 104.34375 17.5625 L 83.5 38.4375 L 83.40625 18.21875 L 76.125 25.5 L 76.09375 51.78125 L 102.3125 51.8125 L 102.3125 51.78125 L 109.625 44.5 L 89.1875 44.40625 L 110.1875 23.40625 L 104.34375 17.5625 z M 23.75 17.59375 L 17.90625 23.4375 L 38.90625 44.4375 L 18.5 44.53125 L 25.78125 51.8125 L 52 51.78125 L 51.96875 25.53125 L 44.6875 18.25 L 44.625 38.46875 L 23.75 17.59375 z M 25.6875 76.03125 L 18.375 83.3125 L 38.78125 83.40625 L 17.8125 104.40625 L 23.625 110.25 L 44.5 89.375 L 44.59375 109.59375 L 51.875 102.3125 L 51.875 76.0625 L 25.6875 76.03125 z M 102.375 76.15625 L 76.15625 76.1875 L 76.1875 102.4375 L 83.46875 109.71875 L 83.5625 89.53125 L 104.40625 110.375 L 110.25 104.53125 L 89.25 83.53125 L 109.6875 83.46875 L 102.375 76.15625 z";
  13. /**
  14. * A single button widget for toggling fullscreen mode.
  15. *
  16. * @alias FullscreenButton
  17. * @constructor
  18. *
  19. * @param {Element|string} container The DOM element or ID that will contain the widget.
  20. * @param {Element|string} [fullscreenElement=document.body] The element or id to be placed into fullscreen mode.
  21. *
  22. * @exception {DeveloperError} Element with id "container" does not exist in the document.
  23. *
  24. * @see Fullscreen
  25. */
  26. function FullscreenButton(container, fullscreenElement) {
  27. //>>includeStart('debug', pragmas.debug);
  28. if (!defined(container)) {
  29. throw new DeveloperError("container is required.");
  30. }
  31. //>>includeEnd('debug');
  32. container = getElement(container);
  33. const viewModel = new FullscreenButtonViewModel(fullscreenElement, container);
  34. viewModel._exitFullScreenPath = exitFullScreenPath;
  35. viewModel._enterFullScreenPath = enterFullScreenPath;
  36. const element = document.createElement("button");
  37. element.type = "button";
  38. element.className = "cesium-button cesium-fullscreenButton";
  39. element.setAttribute(
  40. "data-bind",
  41. "\
  42. attr: { title: tooltip },\
  43. click: command,\
  44. enable: isFullscreenEnabled,\
  45. cesiumSvgPath: { path: isFullscreen ? _exitFullScreenPath : _enterFullScreenPath, width: 128, height: 128 }"
  46. );
  47. container.appendChild(element);
  48. knockout.applyBindings(viewModel, element);
  49. this._container = container;
  50. this._viewModel = viewModel;
  51. this._element = element;
  52. }
  53. Object.defineProperties(FullscreenButton.prototype, {
  54. /**
  55. * Gets the parent container.
  56. * @memberof FullscreenButton.prototype
  57. *
  58. * @type {Element}
  59. */
  60. container: {
  61. get: function () {
  62. return this._container;
  63. },
  64. },
  65. /**
  66. * Gets the view model.
  67. * @memberof FullscreenButton.prototype
  68. *
  69. * @type {FullscreenButtonViewModel}
  70. */
  71. viewModel: {
  72. get: function () {
  73. return this._viewModel;
  74. },
  75. },
  76. });
  77. /**
  78. * @returns {boolean} true if the object has been destroyed, false otherwise.
  79. */
  80. FullscreenButton.prototype.isDestroyed = function () {
  81. return false;
  82. };
  83. /**
  84. * Destroys the widget. Should be called if permanently
  85. * removing the widget from layout.
  86. */
  87. FullscreenButton.prototype.destroy = function () {
  88. this._viewModel.destroy();
  89. knockout.cleanNode(this._element);
  90. this._container.removeChild(this._element);
  91. return destroyObject(this);
  92. };
  93. export default FullscreenButton;