popup.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /**
  2. * 弹窗类
  3. */
  4. define([
  5. 'html!templates/meteo/popup_station', //弹窗
  6. ], function (html) {
  7. var popup = {
  8. options: [],
  9. length: [],
  10. chart: null,
  11. initImage: function () {
  12. for (var i = 0; i < 100; i++) {
  13. var image = new Image();
  14. var dayUrl = "";
  15. if (i < 10) {
  16. dayUrl = 'images/meteo/weatherIcon/cww0' + i + '.png';
  17. } else {
  18. dayUrl = 'images/meteo/weatherIcon/cww' + i + '.png';
  19. }
  20. image.src = dayUrl;
  21. }
  22. var dayAndNightImageId = [0, 1, 2, 3, 25, 26, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90];
  23. for (var j = 0; j < dayAndNightImageId.length; j++) {
  24. var image = new Image();
  25. var nightUrl = "";
  26. if (dayAndNightImageId[i] < 10) {
  27. nightUrl = 'images/meteo/weatherIcon/cww0' + i + 'n.png';
  28. } else {
  29. nightUrl = 'images/meteo/weatherIcon/cww' + i + 'n.png';
  30. }
  31. image.src = nightUrl;
  32. }
  33. },
  34. init: function () {
  35. //初始化弹窗
  36. //---------------step1 添加弹窗布局
  37. $('body').append(html);
  38. //---------------step2 弹窗加入拖动功能
  39. require(['meteoDir/other/jquery.easyui.min'], function () {
  40. $('.meteo-popup').draggable();
  41. });
  42. //---------------设置弹窗的23维地图样式切换
  43. ONEMAP.C.publisher.subscribe(function (type) {
  44. if (type == '2d') {
  45. $(".meteo-popup .popup_html").removeClass('TD');
  46. } else if (type == '3d') {
  47. $(".meteo-popup .popup_html").addClass('TD');
  48. }
  49. }, 'change23D');
  50. //滚动条功能
  51. $(".content_scrollx").mCustomScrollbar({
  52. axis: "x",
  53. advanced: {
  54. autoExpandHorizontalScroll: true,
  55. }
  56. });
  57. //------------添加/删除TD为星图添加(用于3D地图显示弹窗)---------------
  58. $('.meteo-weather-dot').click(function (event) {
  59. $('.meteo-popup').show();
  60. if (map23DData.display.map2D) {
  61. $(".meteo-popup .popup_html").removeClass('TD');
  62. } else {
  63. $(".meteo-popup .popup_html").addClass('TD');
  64. }
  65. });
  66. //----------------------------------------------------------------------
  67. //实况 菜单切换
  68. $('.meteo-popup #meteo-popup-bt1').addClass('current');
  69. $('.meteo-popup .meteo-popup-chart>div').eq(0).show().siblings().hide();
  70. $('.meteo-popup .meteo-popup-buttons a').click(function () {
  71. $(this).addClass('current').siblings().removeClass('current');
  72. $('.meteo-popup .meteo-popup-chart>div').eq($(this).index()).show().siblings().hide();
  73. })
  74. $('.meteo-popup .metie-popup-buttons-main').click(function (event) {
  75. $(this).addClass('current').siblings().removeClass('current');
  76. $('.meteo-popup .meteo-popup-main-warp').addClass('current').siblings().removeClass('current');
  77. });
  78. $('.meteo-popup .metie-popup-buttons-chart').click(function (event) {
  79. $(this).addClass('current').siblings().removeClass('current');
  80. $('.meteo-popup .meteo-popup-chart').addClass('current').siblings().removeClass('current');
  81. });
  82. //关闭按钮可关闭弹窗
  83. $('.meteo-popup .meteo-delete').click(function (event) {
  84. popup.hidePopup();
  85. });
  86. //点击地图关闭弹窗 2D
  87. map2DViewer.map.on('click', function () {
  88. $('.meteo-popup').hide();
  89. })
  90. //todo 点击地图关闭弹窗 3D
  91. // locaSpaceMap.attachEvent('Click', function () {
  92. // PubSub.publish('map3D.click', {
  93. // from:'3D'
  94. // });
  95. // // $('#meteo-popup').hide();
  96. // })
  97. },
  98. getUrlForType: function (type) {
  99. var urls =
  100. //地面站
  101. type == 0 ? [meteo.c.http.stationInfo, meteo.c.http.stationReal,
  102. meteo.c.http.stationFcst, meteo.c.http.stationFcstDay] :
  103. //5000站点
  104. type == 1 ? [meteo.c.http.stationGInfo, meteo.c.http.stationGReal, meteo.c.http.stationGFcst] :
  105. //JD站
  106. type == 2 ? [meteo.c.http.amsuInfo, meteo.c.http.amsuReal, meteo.c.http.amsuFcst] :
  107. //自动站
  108. type == 3 ? [meteo.c.http.awsInfo, meteo.c.http.awsReal, meteo.c.http.amsuFcst] :
  109. //船舶报
  110. type == 4 ? [meteo.c.http.shipInfo] :
  111. null;
  112. return urls;
  113. },
  114. showPopup: function (station, name, type) {
  115. var urls = popup.getUrlForType(type);
  116. if (!urls) return;
  117. //---------------------重置为基础位置,重置第一按钮--------------------
  118. $('.meteo-station-popup').css('left', '260px');
  119. $('.meteo-station-popup').css('top', '100px');
  120. $('.meteo-station-popup #meteo-popup-bt1').addClass('current').siblings().removeClass('current');
  121. $('#meteo-popup-cdiv1').hide();
  122. $('#meteo-popup-cdiv2').hide();
  123. $('.meteo-station-popup').show();
  124. //-------------------step2 填充弹窗内数据-----------------------
  125. switch (type) {
  126. case 0:
  127. popup.setContent(station, name, urls[0], function () {
  128. $('.meteo-shikuang-div').show();
  129. },0);
  130. popup.setFcst(station, urls[2]);
  131. popup.setFcstD(station, urls[3]);
  132. break;
  133. case 1:
  134. popup.setContent(station, name, urls[0], function () {
  135. $('.meteo-shikuang-div').show();
  136. },1);
  137. popup.setFcst(station, urls[3]);
  138. popup.setGlobalFcstD(station, urls[2]);
  139. break;
  140. case 2:
  141. popup.setContent(station, name, urls[0], function () {
  142. $('.meteo-shikuang-div').show();
  143. },2);
  144. popup.setFcst(station, urls[2]);
  145. popup.setFcstD(station, urls[3]);
  146. break;
  147. case 3:
  148. popup.setContent(station, name, urls[0], function () {
  149. $('.meteo-shikuang-div').show();
  150. },3);
  151. popup.setFcst(station, urls[2]);
  152. popup.setFcstD(station, urls[3]);
  153. break;
  154. default:
  155. break;
  156. }
  157. },
  158. setContent: function (station, name, url, callback,type, day) {
  159. var par = null;
  160. if (day) {
  161. par = {
  162. odate: day
  163. }
  164. }
  165. meteo.c.http.httpFunction(url, station, par, function (json) {
  166. if (json) {
  167. var date = json.ldate;
  168. popup.setTitle('#meteo-popup-title', name, station, date);
  169. var wth = meteo.c.process.setWth(json.wth);
  170. popup.setPopupData('#meteo-popup-wth', wth);
  171. var tt = meteo.c.process.setTt(json.tt);
  172. popup.setPopupData('#meteo-popup-tt', tt);
  173. var wth1 = meteo.c.process.setWth(json.wth1);
  174. popup.setPopupData('#meteo-popup-wth1', wth1);
  175. var wth2 = meteo.c.process.setWth(json.wth2);
  176. popup.setPopupData('#meteo-popup-wth2', wth2);
  177. var td = meteo.c.process.setTt(json.td);
  178. popup.setPopupData('#meteo-popup-td', td);
  179. var pr = meteo.c.process.setPr(json.pr);
  180. popup.setPopupData('#meteo-popup-pr', pr);
  181. var vis = meteo.c.process.setVis(json.vis);
  182. popup.setPopupData('#meteo-popup-vis', vis);
  183. var rh = meteo.c.process.setRh(json.rh);
  184. popup.setPopupData('#meteo-popup-rh', rh);
  185. var cn = meteo.c.process.setCn(json.cn);
  186. popup.setPopupData('#meteo-popup-cn', cn);
  187. var wd = meteo.c.process.setWd(json.wd);
  188. var rn = meteo.c.process.setRn(json.rn06);
  189. if(type == 1){
  190. wd = meteo.c.process.setShipWd(json.wd);
  191. $('#meteo-popup-rn06').parent().hide();
  192. $('#meteo-popup-ch').parent().hide();
  193. $('#meteo-popup-rh').parent().show();
  194. $('#meteo-popup-cn').parent().show();
  195. var cf = meteo.c.process.setRh(json.cF);
  196. popup.setPopupData('#meteo-popup-cn', cf);
  197. $('#meteo-popup-cn').prev().html('云覆盖率');
  198. $('.meteo-popup-shikuangUl li').width('24.7%');
  199. }else if(type == 2){
  200. rn = meteo.c.process.setRn(json.rn);
  201. $('#meteo-popup-cn').parent().show();
  202. $('#meteo-popup-ch').parent().hide();
  203. $('#meteo-popup-rh').parent().hide();
  204. $('#meteo-popup-rn06').parent().show();
  205. $('#meteo-popup-cn').prev().html('总云量');
  206. $('.meteo-popup-shikuangUl li').width('24.7%');
  207. }else if(type == 3){
  208. rn = meteo.c.process.setRn(json.rn);
  209. $('#meteo-popup-cn').parent().hide();
  210. $('#meteo-popup-ch').parent().hide();
  211. $('#meteo-popup-rh').parent().show();
  212. $('#meteo-popup-rn06').parent().show();
  213. $('.meteo-popup-shikuangUl li').width('24.7%');
  214. }else if(type == 0){
  215. $('#meteo-popup-cn').parent().show();
  216. $('#meteo-popup-ch').parent().show();
  217. $('#meteo-popup-rh').parent().show();
  218. $('#meteo-popup-rn06').parent().show();
  219. $('#meteo-popup-cn').prev().html('总云量');
  220. $('.meteo-popup-shikuangUl li').width('19.7%');
  221. }
  222. popup.setPopupData('#meteo-popup-rn06', rn);
  223. var ws = meteo.c.process.setWs(json.ws);
  224. popup.setPopupData('#meteo-popup-wd', wd);
  225. popup.setPopupData('#meteo-popup-ws', ws);
  226. var dp = meteo.c.process.setPr(json.dp03);
  227. popup.setPopupData('#meteo-popup-dp03', dp);
  228. var cm = meteo.c.process.setCn(json.cm);
  229. popup.setPopupData('#meteo-popup-cm', cm);
  230. var ch = meteo.c.process.setCh(json.ch);
  231. popup.setPopupData('#meteo-popup-ch', ch);
  232. callback ? callback() : null;
  233. } else {
  234. ONEMAP.C.publisher.publish({type: 'warning', message: '暂无当前站点数据'}, 'noteBar::add');
  235. popup.hidePopup();
  236. }
  237. })
  238. },
  239. setReal: function (station, url, day) {
  240. if (!url) {
  241. return;
  242. }
  243. var par = null;
  244. if (day) {
  245. par = {
  246. ldate: day,
  247. odate: day
  248. }
  249. }
  250. meteo.c.http.httpFunction(url, station, par, function (json) {
  251. if (json.length > 0) {
  252. $('#meteo-popup-bt1').show();
  253. $('#meteo-popup-cdiv1').show();
  254. var chartWidth = json.length * 50;
  255. chartWidth = chartWidth < 740 ? 740 : chartWidth;
  256. $('#meteo-popup-chart').css('width', chartWidth); //设置宽度
  257. var chart = meteo.c.chart.getChart('meteo-popup-chart');
  258. var option = meteo.c.chart.getChartOption(json, "实况");
  259. chart.resize();
  260. chart.setOption(option);
  261. $(".content_scrollx").mCustomScrollbar('update');
  262. }
  263. }, function () {
  264. });
  265. },
  266. setFcst: function (station, url, day) {
  267. if (!url) {
  268. $('#meteo-popup-bt2').hide();
  269. return;
  270. }
  271. var par = null;
  272. if (day) {
  273. par = {
  274. ldate: day,
  275. odate: day
  276. }
  277. }
  278. meteo.c.http.httpFunction(url, station, par, function (json) {
  279. if (json.length > 0) {
  280. $('#meteo-popup-bt2').show();
  281. var chartWidth = json.length * 60;
  282. chartWidth = chartWidth < 740 ? 740 : chartWidth;
  283. $('#meteo-popup-chart').css('width', chartWidth); //设置宽度
  284. var chart = meteo.c.chart.getChart('meteo-popup-chart');
  285. chart.clear();
  286. var option = meteo.c.chart.getSurfHourChartOption(json, "预报");
  287. chart.setOption(option);
  288. $(".content_scrollx").mCustomScrollbar('update');
  289. } else {
  290. $('#meteo-popup-cdiv1').hide();
  291. $('#meteo-popup-bt2').hide();
  292. }
  293. }, function () {
  294. $('#meteo-popup-bt2').hide();
  295. })
  296. },
  297. setFcstD: function (station, url, day) {
  298. if (!url) {
  299. $('#meteo-popup-bt3').hide();
  300. return;
  301. }
  302. var par = null;
  303. if (day) {
  304. par = {
  305. ldate: day,
  306. odate: day
  307. }
  308. }
  309. meteo.c.http.httpFunction(url, station, par, function (json) {
  310. if (json.length > 0) {
  311. $('#meteo-popup-bt3').show();
  312. var chartWidth = json.length * 40;
  313. chartWidth = chartWidth < 740 ? 740 : chartWidth;
  314. $('#meteo-popup-chart2').css('width', chartWidth); //设置宽度
  315. var chart = meteo.c.chart.getChart('meteo-popup-chart2');
  316. chart.clear();
  317. var option = meteo.c.chart.getChartOption(json, "七天预报");
  318. chart.setOption(option);
  319. $(".content_scrollx").mCustomScrollbar('update');
  320. } else {
  321. $('#meteo-popup-cdiv2').hide();
  322. $('#meteo-popup-bt3').hide();
  323. }
  324. }, function () {
  325. $('#meteo-popup-bt3').hide();
  326. })
  327. },
  328. setGlobalFcstD: function (station, url, day) {
  329. if (!url) {
  330. $('#meteo-popup-bt3').hide();
  331. return;
  332. }
  333. var par = null;
  334. if (day) {
  335. par = {
  336. ldate: day,
  337. odate: day
  338. }
  339. }
  340. meteo.c.http.httpFunction(url, station, par, function (json) {
  341. if (json.length > 0) {
  342. $('#meteo-popup-bt3').show();
  343. var chartWidth = json.length * 40;
  344. chartWidth = chartWidth < 740 ? 740 : chartWidth;
  345. $('#meteo-popup-chart2').css('width', chartWidth); //设置宽度
  346. var chart = meteo.c.chart.getChart('meteo-popup-chart2');
  347. chart.clear();
  348. var option = meteo.c.chart.getGlobalDaysChartOption(json, "七天预报");
  349. chart.setOption(option);
  350. $(".content_scrollx").mCustomScrollbar('update');
  351. } else {
  352. $('#meteo-popup-bt3').hide();
  353. $('#meteo-popup-chart2').hide();
  354. }
  355. }, function () {
  356. $('#meteo-popup-bt3').hide();
  357. })
  358. },
  359. hidePopup: function () {
  360. $('.meteo-station-popup').hide();
  361. },
  362. setPopupData: function (id, data) {
  363. var html = data ? data : "--";
  364. $(id).html(html);
  365. },
  366. setTitle: function (id, name, station, ldate) {
  367. // var html = data == 0 || data ? data + company : "--";
  368. if (name == "undefined" || !name) name = null;
  369. var html = name ? name + " (" + station + ")" : "(" + station + ")";
  370. html = ldate ? html + " " + ldate : html;
  371. $(id).html(html);
  372. },
  373. }
  374. popup.init();
  375. // popup.initImage();
  376. return popup;
  377. });