toolMeasuringDistance.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. define(function () {
  2. var status = {
  3. initialized: false,
  4. firstAddMeasuring: true
  5. };
  6. var modValue = {
  7. mearsuringGroup: null
  8. }
  9. var clickCount = 0;
  10. /**
  11. * 初始化并订阅事件
  12. * @return {[type]} [description]
  13. */
  14. function init() {
  15. if (!status.initialized) {
  16. subscribe();
  17. status.initialized = true
  18. }
  19. afac()
  20. }
  21. function afac() {
  22. ONEMAP.C.publisher.publish({
  23. modName: 'toolMeasuringDistance'
  24. }, 'tools:active');
  25. $("#measuringText").show().text('左键单击绘制测量点');
  26. if(map23DData.mouseIn == '3D'){
  27. $("#measuringText").hide();
  28. }
  29. if ($(".tools-distance").hasClass("cur")) {
  30. switchTip();
  31. document.onclick = function () {
  32. clickCount++;
  33. if (clickCount > 0) {
  34. $("#measuringText").text('左键双击结束测量');
  35. }
  36. switchTip();
  37. }
  38. document.ondblclick = function () {
  39. clickCount = 0;
  40. $("#measuringText").text('左键单击绘制测量点');
  41. switchTip();
  42. }
  43. } else {
  44. $("#measuringText").text('').hide();
  45. }
  46. }
  47. function switchTip() {
  48. document.onmousemove = function (ev) {
  49. var oEvent = ev || event;
  50. var oDiv = document.getElementById('measuringText');
  51. var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  52. var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
  53. oDiv.style.left = oEvent.clientX + scrollLeft + 'px';
  54. oDiv.style.top = oEvent.clientY + scrollTop + 'px';
  55. }
  56. }
  57. /**
  58. * 注册订阅
  59. * @type {Function}
  60. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  61. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  62. */
  63. function subscribe() {
  64. ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  65. ONEMAP.C.publisher.subscribe(clearMeasuring, 'cleanMap');
  66. ONEMAP.C.publisher.subscribe(clearMeasuring, 'controlMearsuring');
  67. ONEMAP.C.publisher.subscribe(change23DMeasureDistance, 'change23D');
  68. }
  69. function change23DMeasureDistance(type) {
  70. if ($('#toolsBar .tools-distance').hasClass('cur')) {
  71. map2DViewer.setDistanceTool({
  72. action: 'clear'
  73. })
  74. map3DViewer.measureDistance({
  75. action: 'remove'
  76. })
  77. if (type == '2d') {
  78. $("#measuringText").show()
  79. map2DViewer.setDistanceTool({
  80. action: 'add'
  81. });
  82. } else if (type == '3d') {
  83. $("#measuringText").hide()
  84. map3DViewer.measureDistance({
  85. action: 'add'
  86. });
  87. }
  88. }
  89. }
  90. function clearMeasuring(options) {
  91. if (options) {
  92. if (options.action == 'clear') {
  93. map2DViewer.setDistanceTool({
  94. action: 'clear'
  95. });
  96. map3DViewer.measureDistance({
  97. action: 'clear'
  98. });
  99. status.firstAddMeasuring = true;
  100. remove({
  101. modName: 'clear'
  102. });
  103. }
  104. } else {
  105. map2DViewer.setDistanceTool({
  106. action: 'clear'
  107. });
  108. map3DViewer.measureDistance({
  109. action: 'clear'
  110. });
  111. status.firstAddMeasuring = true;
  112. remove({
  113. modName: 'clear'
  114. });
  115. }
  116. };
  117. function remove(options) {
  118. if (options.modName == 'cleanMap') {
  119. clearMeasuring({
  120. action: 'clear'
  121. })
  122. }
  123. if (options.modName == 'toolMeasuringDistance') {
  124. if ($('#toolsBar .tools-distance').hasClass('cur')) {
  125. if (map23DData.display.map2D) {
  126. map2DViewer.setDistanceTool({
  127. action: 'remove',
  128. offset: [150, 50]
  129. });
  130. } else if (map23DData.display.map3D) {
  131. map3DViewer.measureDistance({
  132. action: 'remove'
  133. });
  134. }
  135. ONEMAP.M.mapHolder.mouseHand();
  136. $('#toolsBar .tools-distance').removeClass('cur');
  137. } else {
  138. if (map23DData.display.map2D) {
  139. ONEMAP.M.mapHolder.removeMouseHand();
  140. if (status.firstAddMeasuring) {
  141. map2DViewer.setDistanceTool({
  142. action: 'add',
  143. offset: [150, 50],
  144. background: "#fff",
  145. color: "red",
  146. font_size: "14px",
  147. closeButton: true
  148. });
  149. status.firstAddMeasuring = false;
  150. } else {
  151. map2DViewer.setDistanceTool({
  152. action: 'restart',
  153. offset: [150, 50],
  154. background: "#fff",
  155. color: "red",
  156. font_size: "14px",
  157. closeButton: true
  158. });
  159. }
  160. } else if (map23DData.display.map3D) {
  161. map3DViewer.measureDistance({
  162. action: 'add'
  163. });
  164. }
  165. $('#toolsBar .tools-distance').addClass('cur');
  166. // ONEMAP.C.publisher.publish('add::diatance','mearsuring');
  167. }
  168. } else {
  169. if (options.modName != "toolMeasuringArea" && options.modName != "toolMeasuringDistance") {
  170. ONEMAP.M.mapHolder.mouseHand();
  171. }
  172. if ($('#toolsBar .tools-distance').hasClass('cur')) {
  173. if (map23DData.display.map2D) {
  174. map2DViewer.setDistanceTool({
  175. action: 'remove',
  176. offset: [150, 50]
  177. });
  178. } else if (map23DData.display.map3D) {
  179. //if (options.modName != 'toolMeasuringArea') {
  180. map3DViewer.measureDistance({
  181. action: 'remove'
  182. });
  183. //}
  184. }
  185. $('#toolsBar .tools-distance').removeClass('cur');
  186. //ONEMAP.M.mapHolder.mouseHand();
  187. }
  188. }
  189. }
  190. return ONEMAP.M.toolMeasuringDistance = {
  191. init: init,
  192. modValue: modValue
  193. }
  194. })