toolKSFX.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. drawId: []
  19. };
  20. /**
  21. * 可是分析初始化
  22. */
  23. function init() {
  24. if (!status.initialized) {
  25. subscribe();
  26. status.initialized = true;
  27. }
  28. ONEMAP.C.publisher.publish({
  29. modName: 'toolKSFX'
  30. }, 'tools:active');
  31. };
  32. /**
  33. * 注册监听事件
  34. */
  35. function subscribe() {
  36. ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  37. ONEMAP.C.publisher.subscribe(removetoolKSFX, 'cleanMap');
  38. ONEMAP.C.publisher.subscribe(removeEvent, 'change23D');
  39. };
  40. function removeEvent() {
  41. if (map23DData.show3DAlert) {
  42. locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态
  43. locaSpaceMap.Refresh();
  44. }
  45. $('#coverHeightKSFX').hide();
  46. closeCircleControl();
  47. }
  48. /**
  49. * 通视分析加载或移除
  50. */
  51. function remove(options) {
  52. if (options.modName != 'toolKSFX') {
  53. if (options.modName == 'cleanMap') {
  54. removetoolKSFX();
  55. }
  56. $(".tools-KSFX").removeClass('cur');
  57. } else {
  58. if ($(".tools-KSFX").hasClass('cur')) {
  59. $(".tools-KSFX").removeClass('cur');
  60. removetoolKSFX();
  61. } else {
  62. $(".tools-KSFX").addClass('cur');
  63. addtoolKSFX();
  64. }
  65. }
  66. }
  67. /**
  68. *移除通视分析
  69. */
  70. function removetoolKSFX() {
  71. if (map23DData.show3DAlert) {
  72. locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态
  73. locaSpaceMap.Refresh();
  74. }
  75. if (modValue.group) {
  76. map23DControl.group({
  77. action: 'remove',
  78. guid: modValue.group,
  79. })
  80. modValue.group = false;
  81. }
  82. $('#coverHeightKSFX').hide();
  83. closeCircleControl();
  84. };
  85. /**
  86. * 加载通视分析
  87. */
  88. function addtoolKSFX() {
  89. $('#coverHeightKSFX').show();
  90. $('#coverHeightKSFX .cancel').unbind('click').bind('click', function() {
  91. $('#coverHeightKSFX').hide();
  92. $(".tools-KSFX").removeClass('cur');
  93. removetoolKSFX();
  94. });
  95. $('#coverHeightKSFX .sure').unbind('click').bind('click', function() {
  96. if (!modValue.group) {
  97. modValue.group = map23DControl.group({
  98. action: 'add'
  99. })
  100. }
  101. var height = parseInt($('#coverHeightKSFX .input').val());
  102. modValue.viewHeight = height;
  103. if (height > 0 && height < 1000) {
  104. $('#coverHeightKSFX').hide();
  105. if (map23DData.show3DAlert) {
  106. locaSpaceMap.Globe.CenterHeightOfViewshedAnalysis = height;
  107. locaSpaceMap.Globe.Action = 13;
  108. locaSpaceMap.Refresh();
  109. }
  110. openCircleControl();
  111. $(".tools-KSFX").removeClass('cur');
  112. } else {
  113. alert('请输入大于0小于1000的高度值');
  114. }
  115. });
  116. };
  117. function closeCircleControl() {
  118. //map2DViewer.drawCircleResult = function(){}
  119. map2DViewer.removeCircle();
  120. }
  121. function openCircleControl() {
  122. map2DViewer.drawCircleResult = function(data) {
  123. if (data.radius > 10000) {
  124. alert('半径过大,建议小于10000米')
  125. } else {
  126. modValue.radius = data.radius;
  127. modValue.coordinates = data.startpoint;
  128. var guid = map2DViewer.marker({
  129. action: 'add',
  130. groupId: modValue.group,
  131. geojson: {
  132. "properties": {
  133. title: '',
  134. iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/marker/b3.png',
  135. iconSize: [10, 24],
  136. iconAnchor: [5, 24],
  137. },
  138. "geometry": {
  139. "coordinates": [modValue.coordinates[1], modValue.coordinates[0]]
  140. }
  141. }
  142. })
  143. showKSY();
  144. }
  145. }
  146. map2DViewer.drawCircle();
  147. }
  148. function showKSY() {
  149. var coods = [modValue.coordinates[1].toFixed(5),modValue.coordinates[0].toFixed(5)]
  150. $.ajax({
  151. type: 'get',
  152. dataType: 'json',
  153. url: onemapUrlConfig.elevationDataUrl + '/v2.0/geoprocessing/viewshed',
  154. data: {
  155. lng: coods[0],
  156. lat: coods[1],
  157. radius: modValue.radius,
  158. height: modValue.viewHeight
  159. },
  160. success: function(data) {
  161. $.each(data.features, function(i, t) {
  162. var guid = map2DViewer.polygon({
  163. action: 'add',
  164. groupId: modValue.group,
  165. geojson: {
  166. "properties": {
  167. title: '测试polygon',
  168. color: '#00ffcc',
  169. weight: 1,
  170. fillColor: '#00ffcc',
  171. opacity: 0.7,
  172. fillOpacity: 0.7,
  173. popupContent: ''
  174. },
  175. "geometry": {
  176. "type": "Polygon",
  177. "coordinates": t.geometry.coordinates
  178. }
  179. }
  180. })
  181. })
  182. closeCircleControl();
  183. },
  184. error: function(errorData) {
  185. ONEMAP.V.loading.loaded();
  186. }
  187. })
  188. }
  189. return ONEMAP.M.toolKSFX = {
  190. init: init
  191. }
  192. })