HomeButton.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import defined from "../../Core/defined.js";
  2. import destroyObject from "../../Core/destroyObject.js";
  3. import DeveloperError from "../../Core/DeveloperError.js";
  4. import knockout from "../../ThirdParty/knockout.js";
  5. import getElement from "../getElement.js";
  6. import HomeButtonViewModel from "./HomeButtonViewModel.js";
  7. /**
  8. * A single button widget for returning to the default camera view of the current scene.
  9. *
  10. * @alias HomeButton
  11. * @constructor
  12. *
  13. * @param {Element|String} container The DOM element or ID that will contain the widget.
  14. * @param {Scene} scene The Scene instance to use.
  15. * @param {Number} [duration] The time, in seconds, it takes to complete the camera flight home.
  16. */
  17. function HomeButton(container, scene, duration) {
  18. //>>includeStart('debug', pragmas.debug);
  19. if (!defined(container)) {
  20. throw new DeveloperError("container is required.");
  21. }
  22. //>>includeEnd('debug');
  23. container = getElement(container);
  24. const viewModel = new HomeButtonViewModel(scene, duration);
  25. viewModel._svgPath =
  26. "M14,4l-10,8.75h20l-4.25-3.7188v-4.6562h-2.812v2.1875l-2.938-2.5625zm-7.0938,9.906v10.094h14.094v-10.094h-14.094zm2.1876,2.313h3.3122v4.25h-3.3122v-4.25zm5.8442,1.281h3.406v6.438h-3.406v-6.438z";
  27. const element = document.createElement("button");
  28. element.type = "button";
  29. element.className = "cesium-button cesium-toolbar-button cesium-home-button";
  30. element.setAttribute(
  31. "data-bind",
  32. "\
  33. attr: { title: tooltip },\
  34. click: command,\
  35. cesiumSvgPath: { path: _svgPath, width: 28, height: 28 }"
  36. );
  37. container.appendChild(element);
  38. knockout.applyBindings(viewModel, element);
  39. this._container = container;
  40. this._viewModel = viewModel;
  41. this._element = element;
  42. }
  43. Object.defineProperties(HomeButton.prototype, {
  44. /**
  45. * Gets the parent container.
  46. * @memberof HomeButton.prototype
  47. *
  48. * @type {Element}
  49. */
  50. container: {
  51. get: function () {
  52. return this._container;
  53. },
  54. },
  55. /**
  56. * Gets the view model.
  57. * @memberof HomeButton.prototype
  58. *
  59. * @type {HomeButtonViewModel}
  60. */
  61. viewModel: {
  62. get: function () {
  63. return this._viewModel;
  64. },
  65. },
  66. });
  67. /**
  68. * @returns {Boolean} true if the object has been destroyed, false otherwise.
  69. */
  70. HomeButton.prototype.isDestroyed = function () {
  71. return false;
  72. };
  73. /**
  74. * Destroys the widget. Should be called if permanently
  75. * removing the widget from layout.
  76. */
  77. HomeButton.prototype.destroy = function () {
  78. knockout.cleanNode(this._element);
  79. this._container.removeChild(this._element);
  80. return destroyObject(this);
  81. };
  82. export default HomeButton;