DXAnalysis.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /**
  2. * [ONEMAP.M.mod]
  3. * @return {[object]}
  4. */
  5. define(['html!templates/tools/DXAnalysis',
  6. 'css!styles/tools/DXAnalysis',
  7. ],
  8. function(tplLayout) {
  9. /**
  10. * 模块数据 用于数据存储和外部调用
  11. * @type {Object}
  12. * 数据存放
  13. */
  14. var modValue = {
  15. };
  16. /**
  17. * 模块界面样式 例如:宽,高
  18. * @type {Object}
  19. */
  20. var styles = {};
  21. /**
  22. * 模块状态,用于存储模块的状态 例如:收起,关闭
  23. * @type {Object}
  24. */
  25. var status = {
  26. initialized:false,
  27. initsubscribe:false
  28. };
  29. /**
  30. * 查询参数
  31. * @type {Object}
  32. */
  33. var options = {};
  34. /**
  35. * 初始化并订阅事件
  36. * @return {[type]} [description]
  37. */
  38. function init() {
  39. if(!status.initialized){
  40. $('body').append(tplLayout);
  41. $('#DXAnalysisContent .popup-ct').dragmove($('#DXAnalysisContent'));
  42. var PXdom = document.getElementById("PXContent");
  43. modValue.PXchart = echarts.init(PXdom);
  44. var PDdom = document.getElementById("PDContent");
  45. modValue.PDchart = echarts.init(PDdom);
  46. status.initialized = true;
  47. //subscribe();
  48. }
  49. if(!status.initsubscribe){
  50. status.initsubscribe = true;
  51. subscribe();
  52. }
  53. ONEMAP.C.publisher.publish({
  54. modName: 'toolDX'
  55. }, 'tools:active');
  56. }
  57. /**
  58. * 设置界面
  59. */
  60. function setLayout() {
  61. }
  62. /**
  63. * 界面事件绑定
  64. * @return {[type]} [description]
  65. */
  66. function bindEvent() {
  67. }
  68. /**
  69. * 界面重置
  70. * @return {[type]} [description]
  71. */
  72. function layoutResize() {
  73. }
  74. /**
  75. * 注册订阅
  76. * @type {Function}
  77. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  78. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  79. */
  80. function subscribe() {
  81. ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  82. }
  83. /**
  84. * 取消订阅
  85. * @type {Function}
  86. * 取消订阅:ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  87. */
  88. function unSubscribe() {
  89. ONEMAP.C.publisher.unSubscribe(remove, 'tools:active');
  90. }
  91. function clearMeasuring() {
  92. if (modValue.reGroup) {
  93. map23DControl.group({
  94. action: 'remove',
  95. guid: modValue.reGroup
  96. })
  97. modValue.reGroup = null;
  98. }
  99. if(modValue.imageOverlayGuid){
  100. map23DControl.imageOverlay({
  101. action:'remove',
  102. guid:modValue.imageOverlayGuid
  103. })
  104. modValue.imageOverlayGuid = null;
  105. }
  106. }
  107. function addMapEvent() {
  108. if (!modValue.drawRectangle) {
  109. modValue.drawRectangle = new L.Draw.Rectangle(map2DViewer.map);
  110. }
  111. if (modValue.reGroup) {
  112. map23DControl.group({
  113. action: 'cleanAll',
  114. guid: modValue.reGroup
  115. })
  116. } else {
  117. modValue.reGroup = map23DControl.group({
  118. action: 'add',
  119. })
  120. }
  121. modValue.drawRectangle.enable();
  122. map2DViewer.map.on('draw:created', drawCreated);
  123. }
  124. function drawCreated(e) {
  125. modValue.rectangle = e.layer;
  126. modValue.rectangle.options.fillOpacity = 0;
  127. map2DViewer.groups[modValue.reGroup].addLayer(modValue.rectangle);
  128. modValue.rectangle.editing.enable();
  129. map2DViewer.map.on('edit', updateDXContent);
  130. updateDXContent();
  131. }
  132. function updateDXContent() {
  133. var latlngs = modValue.rectangle.getLatLngs()[0];
  134. var bbox = latlngs[1].lng+","+latlngs[1].lat+","+latlngs[3].lng+","+latlngs[3].lat;
  135. $("#DXAnalysisContent").show();
  136. $(".fenxialert").remove();
  137. //获取区域坡向数据
  138. $.ajax({
  139. type: "get",
  140. dataType: 'json',
  141. data: {
  142. bbox:bbox
  143. },
  144. url: onemapUrlConfig.elevationDataUrl + '/v2.0/geoprocessing/aspect/bbox',
  145. beforeSend: ONEMAP.V.loading.load(),
  146. success: function (data) {
  147. if (data.status == 'ok' && data.result) {
  148. //echarts渲染
  149. var PXIndex = [];
  150. var PXData = [];
  151. for(var i=0;i<data.result.length;i++){
  152. var name = 22.5*i+"-"+22.5*(i+1);
  153. PXIndex.push(name);
  154. PXData.push({
  155. value:data.result[i], name:name
  156. })
  157. }
  158. var app = {};
  159. option = null;
  160. option = {
  161. title : {
  162. text: '区域坡向统计',
  163. x:'center'
  164. },
  165. tooltip : {
  166. trigger: 'item',
  167. formatter: "{a} <br/>{b} : {c} ({d}%)"
  168. },
  169. series : [
  170. {
  171. name: '坡向统计',
  172. type: 'pie',
  173. radius : '55%',
  174. center: ['50%', '50%'],
  175. data:PXData,
  176. itemStyle: {
  177. emphasis: {
  178. shadowBlur: 10,
  179. shadowOffsetX: 0,
  180. shadowColor: 'rgba(0, 0, 0, 0.5)'
  181. }
  182. }
  183. }
  184. ]
  185. };
  186. modValue.PXchart.setOption(option, true);
  187. modValue.PXchart.resize();
  188. } else {
  189. $("<p class='fenxialert'>所选区域暂无数据</p>").appendTo($("#PXContent"))
  190. }
  191. },
  192. completer: ONEMAP.V.loading.loaded()
  193. });
  194. //获取区域坡度数据
  195. $.ajax({
  196. type: "get",
  197. dataType: 'json',
  198. data: {
  199. bbox:bbox
  200. },
  201. url: onemapUrlConfig.elevationDataUrl + '/v2.0/geoprocessing/slope/bbox',
  202. beforeSend: ONEMAP.V.loading.load(),
  203. success: function (data) {
  204. if (data.status == 'ok') {
  205. //echarts渲染
  206. $("#DXAnalysisContent .min_num").html(data.result.min);
  207. $("#DXAnalysisContent .max_num").html(data.result.max);
  208. var PXIndex = [];
  209. var PXData = [];
  210. for(var i=0;i<data.result.bins.length;i++){
  211. PXIndex.push(data.result.bins[i].range);
  212. PXData.push({
  213. value:data.result.bins[i].percentage, name:data.result.bins[i].range
  214. })
  215. }
  216. var app = {};
  217. option = null;
  218. option = {
  219. title : {
  220. text: '区域坡度统计',
  221. x:'center'
  222. },
  223. tooltip : {
  224. trigger: 'item',
  225. formatter: "{a} <br/>{b} : {c} ({d}%)"
  226. },
  227. series : [
  228. {
  229. name: '坡度统计',
  230. type: 'pie',
  231. radius : '55%',
  232. center: ['50%', '50%'],
  233. data:PXData,
  234. itemStyle: {
  235. emphasis: {
  236. shadowBlur: 10,
  237. shadowOffsetX: 0,
  238. shadowColor: 'rgba(0, 0, 0, 0.5)'
  239. }
  240. }
  241. }
  242. ]
  243. };
  244. modValue.PDchart.setOption(option, true);
  245. modValue.PDchart.resize();
  246. } else {
  247. $("<p class='fenxialert'>所选区域暂无数据</p>").appendTo($("#PDContent"))
  248. }
  249. },
  250. completer: ONEMAP.V.loading.loaded()
  251. });
  252. //获取坡度数据图片并添加到地图上
  253. var curzoom = map2DViewer.map.getZoom()+1;
  254. var imageUrl = onemapUrlConfig.elevationDataUrl + '/v2.0/geoprocessing/slope/bbox?bbox='+bbox+'&as_image=1&zoom='+curzoom;
  255. if(modValue.imageOverlayGuid){
  256. map23DControl.imageOverlay({
  257. action:'update',
  258. from:'23D',
  259. guid:modValue.imageOverlayGuid,
  260. type:'imageOverlay',
  261. layers:{
  262. opacity:1,//2D透明度
  263. layerBounds: [[latlngs[1].lng, latlngs[1].lat], [latlngs[3].lng, latlngs[3].lat]],//左上角 右下角
  264. imageUrl2D:imageUrl,//2D图片地址
  265. imageUrl3D:imageUrl//3D图片服务地址
  266. }
  267. })
  268. }else{
  269. modValue.imageOverlayGuid = map23DControl.imageOverlay({
  270. action:'add',
  271. from:'23D',
  272. type:'imageOverlay',
  273. layers:{
  274. opacity:1,//2D透明度
  275. layerBounds: [[latlngs[1].lng, latlngs[1].lat], [latlngs[3].lng, latlngs[3].lat]],//左上角 右下角
  276. imageUrl2D:imageUrl,//2D图片地址
  277. imageUrl3D:imageUrl//3D图片服务地址
  278. }
  279. })
  280. }
  281. }
  282. function removeMapEvent() {
  283. clearMeasuring();
  284. map2DViewer.map.off('draw:created', drawCreated);
  285. map2DViewer.map.off('edit', updateDXContent);
  286. $("#DXAnalysisContent").remove();
  287. status.initialized = false;
  288. //取消订阅
  289. //unSubscribe();
  290. }
  291. /**
  292. * 模块移除
  293. * @return {[type]} [description]
  294. */
  295. function remove(options) {
  296. if (options.modName == 'toolDX') {
  297. if ($('#toolsBar .tools-dixing').hasClass('cur')) {
  298. $('#toolsBar .tools-dixing').removeClass('cur');
  299. removeMapEvent();
  300. } else {
  301. $('#toolsBar .tools-dixing').addClass('cur');
  302. addMapEvent();
  303. }
  304. } else {
  305. $('#toolsBar .tools-dixing').removeClass('cur');
  306. removeMapEvent();
  307. }
  308. }
  309. return ONEMAP.M.DXAnalysis = {
  310. init: init,
  311. remove: remove
  312. }
  313. });