智慧水务管理系统 - 精河县供水工程综合管理平台

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import {
  2. buildModuleUrl,
  3. defined,
  4. destroyObject,
  5. DeveloperError,
  6. FeatureDetection,
  7. getElement,
  8. } from "@cesium/engine";
  9. import knockout from "../ThirdParty/knockout.js";
  10. import NavigationHelpButtonViewModel from "./NavigationHelpButtonViewModel.js";
  11. /**
  12. * <p>The NavigationHelpButton is a single button widget for displaying instructions for
  13. * navigating the globe with the mouse.</p><p style="clear: both;"></p><br/>
  14. *
  15. * @alias NavigationHelpButton
  16. * @constructor
  17. *
  18. * @param {object} options Object with the following properties:
  19. * @param {Element|string} options.container The DOM element or ID that will contain the widget.
  20. * @param {boolean} [options.instructionsInitiallyVisible=false] True if the navigation instructions should initially be visible; otherwise, false.
  21. *
  22. * @exception {DeveloperError} Element with id "container" does not exist in the document.
  23. *
  24. * @example
  25. * // In HTML head, include a link to the NavigationHelpButton.css stylesheet,
  26. * // and in the body, include: <div id="navigationHelpButtonContainer"></div>
  27. *
  28. * const navigationHelpButton = new Cesium.NavigationHelpButton({
  29. * container : 'navigationHelpButtonContainer'
  30. * });
  31. */
  32. function NavigationHelpButton(options) {
  33. //>>includeStart('debug', pragmas.debug);
  34. if (!defined(options) || !defined(options.container)) {
  35. throw new DeveloperError("options.container is required.");
  36. }
  37. //>>includeEnd('debug');
  38. const container = getElement(options.container);
  39. const viewModel = new NavigationHelpButtonViewModel();
  40. const showInsructionsDefault = options.instructionsInitiallyVisible ?? false;
  41. viewModel.showInstructions = showInsructionsDefault;
  42. viewModel._svgPath =
  43. "M16,1.466C7.973,1.466,1.466,7.973,1.466,16c0,8.027,6.507,14.534,14.534,14.534c8.027,0,14.534-6.507,14.534-14.534C30.534,7.973,24.027,1.466,16,1.466z M17.328,24.371h-2.707v-2.596h2.707V24.371zM17.328,19.003v0.858h-2.707v-1.057c0-3.19,3.63-3.696,3.63-5.963c0-1.034-0.924-1.826-2.134-1.826c-1.254,0-2.354,0.924-2.354,0.924l-1.541-1.915c0,0,1.519-1.584,4.137-1.584c2.487,0,4.796,1.54,4.796,4.136C21.156,16.208,17.328,16.627,17.328,19.003z";
  44. const wrapper = document.createElement("span");
  45. wrapper.className = "cesium-navigationHelpButton-wrapper";
  46. container.appendChild(wrapper);
  47. const button = document.createElement("button");
  48. button.type = "button";
  49. button.className =
  50. "cesium-button cesium-toolbar-button cesium-navigation-help-button";
  51. button.setAttribute(
  52. "data-bind",
  53. "\
  54. attr: { title: tooltip },\
  55. click: command,\
  56. cesiumSvgPath: { path: _svgPath, width: 32, height: 32 }",
  57. );
  58. wrapper.appendChild(button);
  59. const instructionContainer = document.createElement("div");
  60. instructionContainer.className = "cesium-navigation-help";
  61. instructionContainer.setAttribute(
  62. "data-bind",
  63. 'css: { "cesium-navigation-help-visible" : showInstructions}',
  64. );
  65. wrapper.appendChild(instructionContainer);
  66. const mouseButton = document.createElement("button");
  67. mouseButton.type = "button";
  68. mouseButton.className =
  69. "cesium-navigation-button cesium-navigation-button-left";
  70. mouseButton.setAttribute(
  71. "data-bind",
  72. 'click: showClick, css: {"cesium-navigation-button-selected": !_touch, "cesium-navigation-button-unselected": _touch}',
  73. );
  74. const mouseIcon = document.createElement("img");
  75. mouseIcon.src = buildModuleUrl("Widgets/Images/NavigationHelp/Mouse.svg");
  76. mouseIcon.className = "cesium-navigation-button-icon";
  77. mouseIcon.style.width = "25px";
  78. mouseIcon.style.height = "25px";
  79. mouseButton.appendChild(mouseIcon);
  80. mouseButton.appendChild(document.createTextNode("Mouse"));
  81. const touchButton = document.createElement("button");
  82. touchButton.type = "button";
  83. touchButton.className =
  84. "cesium-navigation-button cesium-navigation-button-right";
  85. touchButton.setAttribute(
  86. "data-bind",
  87. 'click: showTouch, css: {"cesium-navigation-button-selected": _touch, "cesium-navigation-button-unselected": !_touch}',
  88. );
  89. const touchIcon = document.createElement("img");
  90. touchIcon.src = buildModuleUrl("Widgets/Images/NavigationHelp/Touch.svg");
  91. touchIcon.className = "cesium-navigation-button-icon";
  92. touchIcon.style.width = "25px";
  93. touchIcon.style.height = "25px";
  94. touchButton.appendChild(touchIcon);
  95. touchButton.appendChild(document.createTextNode("Touch"));
  96. instructionContainer.appendChild(mouseButton);
  97. instructionContainer.appendChild(touchButton);
  98. const clickInstructions = document.createElement("div");
  99. clickInstructions.className =
  100. "cesium-click-navigation-help cesium-navigation-help-instructions";
  101. clickInstructions.setAttribute(
  102. "data-bind",
  103. 'css: { "cesium-click-navigation-help-visible" : !_touch}',
  104. );
  105. clickInstructions.innerHTML = `\
  106. <table>\
  107. <tr>\
  108. <td><img src="${buildModuleUrl(
  109. "Widgets/Images/NavigationHelp/MouseLeft.svg",
  110. )}" width="48" height="48" /></td>\
  111. <td>\
  112. <div class="cesium-navigation-help-pan">Pan view</div>\
  113. <div class="cesium-navigation-help-details">Left click + drag</div>\
  114. </td>\
  115. </tr>\
  116. <tr>\
  117. <td><img src="${buildModuleUrl(
  118. "Widgets/Images/NavigationHelp/MouseRight.svg",
  119. )}" width="48" height="48" /></td>\
  120. <td>\
  121. <div class="cesium-navigation-help-zoom">Zoom view</div>\
  122. <div class="cesium-navigation-help-details">Right click + drag, or</div>\
  123. <div class="cesium-navigation-help-details">Mouse wheel scroll</div>\
  124. </td>\
  125. </tr>\
  126. <tr>\
  127. <td><img src="${buildModuleUrl(
  128. "Widgets/Images/NavigationHelp/MouseMiddle.svg",
  129. )}" width="48" height="48" /></td>\
  130. <td>\
  131. <div class="cesium-navigation-help-rotate">Rotate view</div>\
  132. <div class="cesium-navigation-help-details">Middle click + drag, or</div>\
  133. <div class="cesium-navigation-help-details">CTRL + Left/Right click + drag</div>\
  134. </td>\
  135. </tr>\
  136. </table>`;
  137. instructionContainer.appendChild(clickInstructions);
  138. const touchInstructions = document.createElement("div");
  139. touchInstructions.className =
  140. "cesium-touch-navigation-help cesium-navigation-help-instructions";
  141. touchInstructions.setAttribute(
  142. "data-bind",
  143. 'css: { "cesium-touch-navigation-help-visible" : _touch}',
  144. );
  145. touchInstructions.innerHTML = `\
  146. <table>\
  147. <tr>\
  148. <td><img src="${buildModuleUrl(
  149. "Widgets/Images/NavigationHelp/TouchDrag.svg",
  150. )}" width="70" height="48" /></td>\
  151. <td>\
  152. <div class="cesium-navigation-help-pan">Pan view</div>\
  153. <div class="cesium-navigation-help-details">One finger drag</div>\
  154. </td>\
  155. </tr>\
  156. <tr>\
  157. <td><img src="${buildModuleUrl(
  158. "Widgets/Images/NavigationHelp/TouchZoom.svg",
  159. )}" width="70" height="48" /></td>\
  160. <td>\
  161. <div class="cesium-navigation-help-zoom">Zoom view</div>\
  162. <div class="cesium-navigation-help-details">Two finger pinch</div>\
  163. </td>\
  164. </tr>\
  165. <tr>\
  166. <td><img src="${buildModuleUrl(
  167. "Widgets/Images/NavigationHelp/TouchTilt.svg",
  168. )}" width="70" height="48" /></td>\
  169. <td>\
  170. <div class="cesium-navigation-help-rotate">Tilt view</div>\
  171. <div class="cesium-navigation-help-details">Two finger drag, same direction</div>\
  172. </td>\
  173. </tr>\
  174. <tr>\
  175. <td><img src="${buildModuleUrl(
  176. "Widgets/Images/NavigationHelp/TouchRotate.svg",
  177. )}" width="70" height="48" /></td>\
  178. <td>\
  179. <div class="cesium-navigation-help-tilt">Rotate view</div>\
  180. <div class="cesium-navigation-help-details">Two finger drag, opposite direction</div>\
  181. </td>\
  182. </tr>\
  183. </table>`;
  184. instructionContainer.appendChild(touchInstructions);
  185. knockout.applyBindings(viewModel, wrapper);
  186. this._container = container;
  187. this._viewModel = viewModel;
  188. this._wrapper = wrapper;
  189. this._closeInstructions = function (e) {
  190. if (!wrapper.contains(e.target)) {
  191. viewModel.showInstructions = false;
  192. }
  193. };
  194. if (FeatureDetection.supportsPointerEvents()) {
  195. document.addEventListener("pointerdown", this._closeInstructions, true);
  196. } else {
  197. document.addEventListener("mousedown", this._closeInstructions, true);
  198. document.addEventListener("touchstart", this._closeInstructions, true);
  199. }
  200. }
  201. Object.defineProperties(NavigationHelpButton.prototype, {
  202. /**
  203. * Gets the parent container.
  204. * @memberof NavigationHelpButton.prototype
  205. *
  206. * @type {Element}
  207. */
  208. container: {
  209. get: function () {
  210. return this._container;
  211. },
  212. },
  213. /**
  214. * Gets the view model.
  215. * @memberof NavigationHelpButton.prototype
  216. *
  217. * @type {NavigationHelpButtonViewModel}
  218. */
  219. viewModel: {
  220. get: function () {
  221. return this._viewModel;
  222. },
  223. },
  224. });
  225. /**
  226. * @returns {boolean} true if the object has been destroyed, false otherwise.
  227. */
  228. NavigationHelpButton.prototype.isDestroyed = function () {
  229. return false;
  230. };
  231. /**
  232. * Destroys the widget. Should be called if permanently
  233. * removing the widget from layout.
  234. */
  235. NavigationHelpButton.prototype.destroy = function () {
  236. if (FeatureDetection.supportsPointerEvents()) {
  237. document.removeEventListener("pointerdown", this._closeInstructions, true);
  238. } else {
  239. document.removeEventListener("mousedown", this._closeInstructions, true);
  240. document.removeEventListener("touchstart", this._closeInstructions, true);
  241. }
  242. knockout.cleanNode(this._wrapper);
  243. this._container.removeChild(this._wrapper);
  244. return destroyObject(this);
  245. };
  246. export default NavigationHelpButton;