toolTSFX.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. define(function() {
  2. /**
  3. * 状态值
  4. * @type {Boolean}
  5. * @default false
  6. * @private
  7. */
  8. var status = {
  9. initialized: false, //是否初始化
  10. veiwHeightType: null
  11. };
  12. /**
  13. * 模块数据 用于数据存储和外部调用
  14. * @type {Object}
  15. * 数据存放
  16. */
  17. var modValue = {
  18. };
  19. /**
  20. * 三维高度测量初始化
  21. */
  22. function init() {
  23. if (!status.initialized) {
  24. subscribe();
  25. status.initialized = true;
  26. }
  27. ONEMAP.C.publisher.publish({
  28. modName: 'toolTSFX'
  29. }, 'tools:active');
  30. };
  31. /**
  32. * 注册监听事件
  33. */
  34. function subscribe() {
  35. ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  36. ONEMAP.C.publisher.subscribe(removeEvent, 'change23D');
  37. ONEMAP.C.publisher.subscribe(removetoolTSFX, 'cleanMap');
  38. };
  39. function removeEvent(){
  40. if (map23DData.show3DAlert) {
  41. locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态
  42. locaSpaceMap.Refresh();
  43. }
  44. remove2DEvent();
  45. }
  46. function mousemove23D(options) {
  47. var screen = options.e.containerPoint;
  48. $(".mouseTip").css({
  49. left: screen.x + 10,
  50. top: screen.y + 10
  51. })
  52. }
  53. function mapClick(options) {
  54. //添加起始点
  55. if (!modValue.arryCoor) {
  56. var guid = map2DViewer.marker({
  57. action: 'add',
  58. groupId: modValue.group,
  59. geojson: {
  60. "properties": {
  61. title: '',
  62. iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/marker/r3.png',
  63. iconSize: [10, 24],
  64. iconAnchor: [5, 24],
  65. },
  66. "geometry": {
  67. "coordinates": [options.lng, options.lat]
  68. }
  69. }
  70. })
  71. $(".mouseTip").html('点击地图添加目标点')
  72. modValue.arryCoor = {
  73. first: [options.lng, options.lat],
  74. scend: null
  75. }
  76. } else {
  77. var guid = map2DViewer.marker({
  78. action: 'add',
  79. groupId: modValue.group,
  80. geojson: {
  81. "properties": {
  82. title: '',
  83. iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/marker/y3.png',
  84. iconSize: [10, 24],
  85. iconAnchor: [5, 24],
  86. },
  87. "geometry": {
  88. "coordinates": [options.lng, options.lat]
  89. }
  90. }
  91. })
  92. modValue.arryCoor.scend = [options.lng, options.lat];
  93. getTSData();
  94. remove2DEvent();
  95. modValue.arryCoor = null;
  96. }
  97. }
  98. function getTSData() {
  99. var coods = [modValue.arryCoor.first[0].toFixed(5),modValue.arryCoor.first[1].toFixed(5),modValue.arryCoor.scend[0].toFixed(5),modValue.arryCoor.scend[1].toFixed(5)]
  100. $.ajax({
  101. type: 'get',
  102. dataType: 'json',
  103. url: onemapUrlConfig.elevationDataUrl + '/v2.0/geoprocessing/sightline',
  104. data: {
  105. lng1: coods[0],
  106. lat1: coods[1],
  107. lng2: coods[2],
  108. lat2: coods[3],
  109. height: 3
  110. },
  111. success: function(data) {
  112. $.each(data.features, function(i, t) {
  113. map2DViewer.polyline({
  114. action: 'add',
  115. groupId: modValue.group,
  116. geojson: {
  117. "type": "Feature",
  118. "properties": {
  119. title: '',
  120. color: t.properties.color,
  121. weight: 3,
  122. opacity: 1,
  123. },
  124. "geometry": {
  125. "coordinates": t.geometry.coordinates
  126. }
  127. }
  128. })
  129. })
  130. },
  131. error: function(errorData) {
  132. ONEMAP.V.loading.loaded();
  133. }
  134. })
  135. }
  136. function remove2DEvent() {
  137. $(".tools-TSFX").removeClass('cur');
  138. ONEMAP.C.publisher.unSubscribe(mapClick, 'mapClick2D');
  139. ONEMAP.C.publisher.unSubscribe(mousemove23D, 'mousemove23D');
  140. $(".mouseTip").remove();
  141. }
  142. /**
  143. * 通视分析加载或移除
  144. */
  145. function remove(options) {
  146. if (options.modName != 'toolTSFX') {
  147. if(options.modName == 'cleanMap'){
  148. removetoolTSFX();
  149. }
  150. $(".tools-TSFX").removeClass('cur');
  151. remove2DEvent();
  152. //removetoolTSFX();
  153. } else {
  154. if ($(".tools-TSFX").hasClass('cur')) {
  155. $(".tools-TSFX").removeClass('cur');
  156. removetoolTSFX();
  157. } else {
  158. $(".tools-TSFX").addClass('cur');
  159. addtoolTSFX();
  160. }
  161. }
  162. }
  163. /**
  164. *移除通视分析
  165. */
  166. function removetoolTSFX() {
  167. if (map23DData.show3DAlert) {
  168. locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态
  169. locaSpaceMap.Refresh();
  170. }
  171. modValue.arryCoor = null;
  172. if(modValue.group){
  173. map23DControl.group({
  174. action: 'remove',
  175. guid:modValue.group,
  176. })
  177. modValue.group = false;
  178. }
  179. remove2DEvent();
  180. };
  181. /**
  182. * 加载通视分析
  183. */
  184. function addtoolTSFX() {
  185. if (!modValue.group) {
  186. modValue.group = map23DControl.group({
  187. action: 'add'
  188. })
  189. }
  190. if (map23DData.show3DAlert) {
  191. locaSpaceMap.Globe.Action = 15;
  192. locaSpaceMap.Refresh();
  193. }
  194. $(".mouseTip").remove();
  195. $('<p class="mouseTip">点击地图添加起点</p>').appendTo($("#map2DWrap"));
  196. ONEMAP.C.publisher.subscribe(mapClick, 'mapClick2D');
  197. ONEMAP.C.publisher.subscribe(mousemove23D, 'mousemove23D');
  198. };
  199. return ONEMAP.M.toolTSFX = {
  200. init: init
  201. }
  202. })