SelectionIndicator.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 SelectionIndicatorViewModel from './SelectionIndicatorViewModel.js';
  8. /**
  9. * A widget for displaying an indicator on a selected object.
  10. *
  11. * @alias SelectionIndicator
  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. *
  17. * @exception {DeveloperError} Element with id "container" does not exist in the document.
  18. */
  19. function SelectionIndicator(container, scene) {
  20. //>>includeStart('debug', pragmas.debug);
  21. if (!defined(container)) {
  22. throw new DeveloperError('container is required.');
  23. }
  24. //>>includeEnd('debug')
  25. container = getElement(container);
  26. this._container = container;
  27. var el = document.createElement('div');
  28. el.className = 'cesium-selection-wrapper';
  29. el.setAttribute('data-bind', '\
  30. style: { "top" : _screenPositionY, "left" : _screenPositionX },\
  31. css: { "cesium-selection-wrapper-visible" : isVisible }');
  32. container.appendChild(el);
  33. this._element = el;
  34. var svgNS = 'http://www.w3.org/2000/svg';
  35. var path = 'M -34 -34 L -34 -11.25 L -30 -15.25 L -30 -30 L -15.25 -30 L -11.25 -34 L -34 -34 z M 11.25 -34 L 15.25 -30 L 30 -30 L 30 -15.25 L 34 -11.25 L 34 -34 L 11.25 -34 z M -34 11.25 L -34 34 L -11.25 34 L -15.25 30 L -30 30 L -30 15.25 L -34 11.25 z M 34 11.25 L 30 15.25 L 30 30 L 15.25 30 L 11.25 34 L 34 34 L 34 11.25 z';
  36. var svg = document.createElementNS(svgNS, 'svg:svg');
  37. svg.setAttribute('width', 160);
  38. svg.setAttribute('height', 160);
  39. svg.setAttribute('viewBox', '0 0 160 160');
  40. var group = document.createElementNS(svgNS, 'g');
  41. group.setAttribute('transform', 'translate(80,80)');
  42. svg.appendChild(group);
  43. var pathElement = document.createElementNS(svgNS, 'path');
  44. pathElement.setAttribute('data-bind', 'attr: { transform: _transform }');
  45. pathElement.setAttribute('d', path);
  46. group.appendChild(pathElement);
  47. el.appendChild(svg);
  48. var viewModel = new SelectionIndicatorViewModel(scene, this._element, this._container);
  49. this._viewModel = viewModel;
  50. knockout.applyBindings(this._viewModel, this._element);
  51. }
  52. defineProperties(SelectionIndicator.prototype, {
  53. /**
  54. * Gets the parent container.
  55. * @memberof SelectionIndicator.prototype
  56. *
  57. * @type {Element}
  58. */
  59. container : {
  60. get : function() {
  61. return this._container;
  62. }
  63. },
  64. /**
  65. * Gets the view model.
  66. * @memberof SelectionIndicator.prototype
  67. *
  68. * @type {SelectionIndicatorViewModel}
  69. */
  70. viewModel : {
  71. get : function() {
  72. return this._viewModel;
  73. }
  74. }
  75. });
  76. /**
  77. * @returns {Boolean} true if the object has been destroyed, false otherwise.
  78. */
  79. SelectionIndicator.prototype.isDestroyed = function() {
  80. return false;
  81. };
  82. /**
  83. * Destroys the widget. Should be called if permanently
  84. * removing the widget from layout.
  85. */
  86. SelectionIndicator.prototype.destroy = function() {
  87. var container = this._container;
  88. knockout.cleanNode(this._element);
  89. container.removeChild(this._element);
  90. return destroyObject(this);
  91. };
  92. export default SelectionIndicator;