toolMeasuringArea.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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: 'toolMeasuringArea'
  24. }, 'tools:active');
  25. $("#measuringText").show().text('左键单击绘制测量点');
  26. if (map23DData.mouseIn == '3D') {
  27. $("#measuringText").hide();
  28. }
  29. if ($(".tools-area").hasClass("cur")) {
  30. switchTip();
  31. document.onclick = function () {
  32. clickCount++;
  33. if (clickCount > 1) {
  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-area').hasClass('cur')) {
  71. map2DViewer.setAreaTool({
  72. action: 'clear'
  73. })
  74. map3DViewer.measureArea({
  75. action: 'remove'
  76. })
  77. if (type == '2d') {
  78. $("#measuringText").show()
  79. map2DViewer.setAreaTool({
  80. action: 'add'
  81. });
  82. } else if (type == '3d') {
  83. $("#measuringText").hide()
  84. map3DViewer.measureArea({
  85. action: 'add'
  86. });
  87. }
  88. }
  89. }
  90. function clearMeasuring(options) {
  91. if (options) {
  92. if (options.action == 'clear') {
  93. map2DViewer.setAreaTool({
  94. action: 'clear'
  95. });
  96. map3DViewer.measureArea({
  97. action: 'clear'
  98. });
  99. status.firstAddMeasuring = true;
  100. remove({
  101. modName: 'clear'
  102. });
  103. $('#toolsBar .tools-area').removeClass('cur');
  104. }
  105. // else if (options.action == 'hide') {
  106. // map23DControl.group({
  107. // action: 'hide',
  108. // guid: modValue.mearsuringGroup
  109. // })
  110. // } else if (options.action == 'show') {
  111. // map23DControl.group({
  112. // action: 'show',
  113. // guid: modValue.mearsuringGroup
  114. // })
  115. // }
  116. } else {
  117. map2DViewer.setAreaTool({
  118. action: 'clear'
  119. });
  120. map3DViewer.measureArea({
  121. action: 'clear'
  122. });
  123. remove({
  124. modName: 'clear'
  125. });
  126. // status.firstAddMeasuring = true;
  127. // //remove({modName:'clear'});
  128. // $('#toolsBar .tools-area').removeClass('cur');
  129. // ONEMAP.M.mapHolder.mouseHand();
  130. }
  131. };
  132. function remove(options) {
  133. if (options.modName == 'cleanMap') {
  134. clearMeasuring({
  135. action: 'clear'
  136. })
  137. }
  138. if (options.modName == 'toolMeasuringArea') {
  139. if ($('#toolsBar .tools-area').hasClass('cur')) {
  140. if (map23DData.display.map2D) {
  141. map2DViewer.setAreaTool({
  142. action: 'remove',
  143. offset: [150, 50]
  144. });
  145. } else if (map23DData.display.map3D) {
  146. // var chrome = navigator.userAgent.toLowerCase().match(/chrome/) != null || navigator.userAgent.toLowerCase().match(/firefox/) != null;
  147. // if (!chrome) {
  148. // locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态
  149. // locaSpaceMap.Refresh();
  150. // }
  151. map3DViewer.measureArea({
  152. action: 'remove'
  153. });
  154. }
  155. $('#toolsBar .tools-area').removeClass('cur');
  156. ONEMAP.M.mapHolder.mouseHand();
  157. } else {
  158. if (map23DData.display.map2D) {
  159. ONEMAP.M.mapHolder.removeMouseHand();
  160. if (status.firstAddMeasuring) {
  161. map2DViewer.setAreaTool({
  162. action: 'add',
  163. offset: [150, 50],
  164. background: "#fff",
  165. color: "red",
  166. font_size: "14px",
  167. closeButton: true
  168. });
  169. status.firstAddMeasuring = false;
  170. } else {
  171. map2DViewer.setAreaTool({
  172. action: 'restart',
  173. offset: [150, 50]
  174. });
  175. }
  176. } else if (map23DData.display.map3D) {
  177. // var chrome = navigator.userAgent.toLowerCase().match(/chrome/) != null || navigator.userAgent.toLowerCase().match(/firefox/) != null;
  178. // if (!chrome) {
  179. // try {
  180. // locaSpaceMap.Globe.RulerArea.SpaceMeasure = false; // 量算模式为绘制贴地面方式
  181. // locaSpaceMap.Globe.RulerArea.ValueMode = 1; // 量算的面上显示的值是地表面积
  182. // locaSpaceMap.Refresh();
  183. // locaSpaceMap.Globe.Action = 3;
  184. // } catch (e) {}
  185. // }
  186. map3DViewer.measureArea({
  187. action: 'add'
  188. });
  189. }
  190. $('#toolsBar .tools-area').addClass('cur');
  191. // ONEMAP.M.mapHolder.removeMouseHand();
  192. // ONEMAP.C.publisher.publish('add::area','mearsuring');
  193. }
  194. } else {
  195. if (options.modName != "toolMeasuringArea" && options.modName != "toolMeasuringDistance") {
  196. ONEMAP.M.mapHolder.mouseHand();
  197. }
  198. if ($('#toolsBar .tools-area').hasClass('cur')) {
  199. if (map23DData.display.map2D) {
  200. map2DViewer.setAreaTool({
  201. action: 'remove',
  202. offset: [150, 50]
  203. });
  204. } else if (map23DData.display.map3D) {
  205. //if (options.modName != 'toolMeasuringDistance') {
  206. // var chrome = navigator.userAgent.toLowerCase().match(/chrome/) != null || navigator.userAgent.toLowerCase().match(/firefox/) != null;
  207. // if (!chrome) {
  208. // try {
  209. // locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态
  210. // locaSpaceMap.Refresh();
  211. // } catch (e) {}
  212. // }
  213. map3DViewer.measureArea({
  214. action: 'remove'
  215. });
  216. //}
  217. }
  218. $('#toolsBar .tools-area').removeClass('cur');
  219. //ONEMAP.M.mapHolder.mouseHand();
  220. }
  221. }
  222. }
  223. return ONEMAP.M.toolMeasuringArea = {
  224. init: init,
  225. modValue: modValue
  226. }
  227. })