SpaceWeather.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //空间天气
  2. define(['html!templates/meteo/spaceWeather'], function (html) {
  3. function init() {
  4. //--------------添加布局----------------
  5. $('body').append(html);
  6. require(['meteoDir/other/jquery.easyui.min'], function () {
  7. $('.meteo-popup').draggable();
  8. });
  9. //----------------功能开启/关闭----------------
  10. $('#meteo-bt-space').click(function () {
  11. if ($('.meteo-sw-box').is(':hidden')) {
  12. //设置zIndex 为最高
  13. var zIndex = ONEMAP.M.sideBar.getZIndex();
  14. $('#meteo-control-sweatherList').css({zIndex: zIndex});
  15. ONEMAP.D.currentSideBarMod = 'atlas';
  16. //开启侧栏
  17. ONEMAP.C.publisher.publish('handShow', 'layout::sideBar');
  18. getDate();
  19. $('.meteo-sw-box').show();
  20. } else {
  21. $('.meteo-sw-box').hide();
  22. }
  23. });
  24. map2DViewer.map.on('click', function () {
  25. $('.meteo-sw-box').hide(); //点击地图关闭弹窗
  26. })
  27. $('#meteo-sw-close').click(function () {
  28. $('.meteo-sw-box').hide(); //点击X关闭弹窗
  29. });
  30. //------------下一张以及上一张-------------
  31. $('#meteo-sw-next').click(function (e) {
  32. next();
  33. })
  34. $('#meteo-sw-last').click(function (e) {
  35. last();
  36. })
  37. }
  38. //获取列表数据
  39. function getDate() {
  40. meteo.c.http.httpFunction(meteo.c.http.space, null, '', function (json) {
  41. var list = json['image'];
  42. var data = json['data'];
  43. var listHtml = '';
  44. for (var i = 0; i < list.length; i++) {
  45. var elem = "'" + list[i]['elem'] + "'";
  46. var odate = "'" + list[i]['odate'] + "'";
  47. var sinElem = list[i]['elem'];
  48. sinElem = sinElem.indexOf('proton') != -1 ? '质子数据' :
  49. sinElem.indexOf('dscovr_mag') != -1 ? '卫星磁场' :
  50. sinElem.indexOf('dscovr_plasma') != -1 ? '卫星等离子体' :
  51. sinElem.indexOf('electro') != -1 ? '电子数据' :
  52. sinElem.indexOf('kp') != -1 ? '地磁指数数据' :
  53. sinElem.indexOf('sdo') != -1 ? 'SDO太阳极紫外图' :
  54. sinElem.indexOf('xray') != -1 ? 'X射线流量' : elem ;
  55. //listHtml += '<div class="meteo-sw-item" odate=' + odate + ' elem=' + elem + ' >' + sinElem + '</div>';
  56. listHtml += '<li class="meteo-twoLi meteo-lastLi">' +
  57. '<a href="javascript:;" id="meteo-swe-item' + i + '" class="meteo-twoBtn meteo-lastBtn meteo-sw-item"' +
  58. ' odate= '+ odate + ' elem= ' + elem + ' >"' + sinElem;
  59. listHtml += '</a></li>';
  60. }
  61. $('#meteo-sw-general').html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + data.data);
  62. // $('#meteo-sw-list').html(listHtml);
  63. $('#meteo-list-spaWeather').html(listHtml);
  64. getElemData(list[0]['odate'], list[0]['elem']); //获取第一条详细数据
  65. $("#meteo-swe-item0").parent().addClass('current');
  66. $('.meteo-sw-item').click(function (e) {
  67. var data = e.currentTarget.attributes;
  68. getElemData(data.odate.value, data.elem.value); //添加列表点击事件
  69. $(this).parent().addClass('current');
  70. $(this).parent().siblings().removeClass('current');
  71. })
  72. }, function () {
  73. })
  74. }
  75. var elemData;
  76. //获取详细数据 /根据事件及elem
  77. function getElemData(odate, elem) {
  78. var param = {
  79. dateStr: odate,
  80. elem: elem
  81. };
  82. meteo.c.http.httpFunction(meteo.c.http.spaceInfo, null, param, function (json) {
  83. elemData = [];
  84. for (var i = 0; i < json.length; i++) {
  85. if(!json[i].image) continue;
  86. for (var j = 0; j < json[i].image.length; j++) {
  87. if (elemData.length >= 10) break; //数据可能有很多,目前最多取10条
  88. var tElem = json[i].image[j];
  89. if (json[i].desc && json[i].desc.data) {
  90. tElem.desc = json[i].desc.data;
  91. } else {
  92. tElem.desc = '暂无描述';
  93. }
  94. elemData[elemData.length] = tElem;
  95. }
  96. }
  97. showIndex = 0;
  98. showElemData();
  99. }, function () {
  100. })
  101. }
  102. var showIndex = 0;
  103. function showElemData() { //更换当前显示的数据
  104. $('#meteo-sw-img').attr("src", elemData[showIndex].data);
  105. // $('#meteo-sw-img').attr("src", 'http://107.1.170.200:10000/space/space_20190304_000012_1024_0094.jpg');
  106. $('#meteo-sw-top').html(elemData[showIndex].odate + " " + elemData[showIndex].elem);
  107. $('#meteo-sw-gen').html(elemData[showIndex].desc);
  108. }
  109. function next() {
  110. if (showIndex == elemData.length - 1) return;
  111. showIndex++;
  112. showElemData();
  113. }
  114. function last() {
  115. if (showIndex == 0) return;
  116. showIndex--;
  117. showElemData();
  118. }
  119. init();
  120. meteo.f.spWeather = {
  121. init: init,
  122. };
  123. return meteo.f.spWeather;
  124. });