HomeButton.js 2.9 KB

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