HomeButton.js 3.0 KB

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