cloudMap.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /**
  2. * Created by Administrator on 2017/10/31.
  3. * 云图类
  4. */
  5. define(['modDir/menu/myLayerActions'], function (_myLayerActions) {
  6. var cloud = {
  7. id: 'cloud',
  8. title: '风云2 云图',
  9. data: null, //云图数据存储位置
  10. playId: null, //云图动画任务id
  11. //imgOverlay: null, //云图覆盖物对象
  12. layer: null,
  13. showIndex: null, //正在被显示的云图索引
  14. isHide: false, //是否被隐藏
  15. type: {
  16. ch1: '(红外一)',
  17. ch3: '(水汽)',
  18. ch4: '(可见光)'
  19. },
  20. showType: null,
  21. getCloudData: function () { //获取云图数据
  22. // var dateStr = meteo.c.time.getTime();
  23. var dateStr = new Date();
  24. dateStr = dateStr.getFullYear() + "-" + (dateStr.getMonth() + 1) + "-" + dateStr.getDate()
  25. + " " + dateStr.getHours() + ":00";
  26. // var dateStr = '2018-07-12 20:00';
  27. var params = {
  28. dateStr: dateStr,
  29. ch: cloud.showType
  30. }
  31. meteo.c.http.httpFunction(meteo.c.http.cloud, null, params, function (json) {
  32. cloud.data = json;
  33. cloud.showList();
  34. cloud.loadImage();
  35. }, function () {
  36. ONEMAP.C.publisher.publish({type: 'warning', message: '当前通道云图暂无数据'}, 'noteBar::add');
  37. })
  38. //开启侧栏
  39. var zIndex = ONEMAP.M.sideBar.getZIndex();
  40. $('#meteo-control-cloud').css({zIndex: zIndex});
  41. ONEMAP.D.currentSideBarMod = 'atlas';
  42. ONEMAP.C.publisher.publish('handShow', 'layout::sideBar');
  43. },
  44. showList: function () {
  45. cloud.isHide = false;
  46. var content = '';
  47. for (var i = 0; i < cloud.data.length; i++) {
  48. content += " <li class='meteo-twoLi meteo-lastLi'>" +
  49. "<a href='javascript:;' id='meteo-cloud-item" + i + "' class='meteo-twoBtn meteo-lastBtn meteo-typh-item'"
  50. + " onclick='meteo.f.cloud.clickCloudList(" + i + ")'>";
  51. // content += typhoon.getId(adata.id) + " " + adata.cname + " " + adata.ccc;
  52. // var odate = json[i].odate ? json[i].cname : json[i].ename;
  53. content += cloud.data[i].odate;
  54. content += "</a></li>";
  55. }
  56. $('#meteo-list-cloud').html(content);
  57. cloud.clickCloudList(cloud.data.length - 1);
  58. },
  59. clickCloudList: function (index) {
  60. // if (!cloud.layer || !cloud.layer.imgOverlay) return; //如果当前云图图层隐藏,则不显示
  61. if (cloud.isHide) return;
  62. if (cloud.showIndex == index) return; //已被显示,则不继续显示
  63. if (!cloud.layer) return;
  64. // $("#meteo-bt-cloud-" + cloud.showType).parent().addClass('current');
  65. $('#meteo-cloud-item' + cloud.showIndex).parent().removeClass('current');
  66. $("#meteo-cloud-item" + index).parent().addClass('current'); //
  67. cloud.showIndex = index;
  68. var time = cloud.data[index].odate;
  69. meteo.c.title.updateTitle(cloud.id, meteo.c.process.setCloudTitle(time, cloud.title, cloud.type[cloud.showType]));
  70. cloud.showCloud();
  71. },
  72. showCloud: function (opacity) { //临时使用的云图显示
  73. // var layerid = meteo.f.cloud.layer.tLayer;
  74. // var layer = map2DViewer.groups[layerid];
  75. // var url = meteo.c.http.myUrl + "scripts/meteo/test/cloud/" +
  76. // 'CLOUD_2017122500_ch1_mkt.fy2.png';
  77. // var cloudImageNew = L.imageOverlay(
  78. // json.url,
  79. // L.latLngBounds(L.latLng(json.slat, json.slng), L.latLng(json.elat, json.elng))
  80. // // L.latLngBounds(L.latLng(-9, 85), L.latLng(40, 160))
  81. // ).addTo(layer);
  82. var data = meteo.f.cloud.data[cloud.showIndex].data;
  83. data = JSON.parse(data);
  84. var cloudImageNew = meteo.c.map.addImage(data.url, data.slat, data.slng, data.elat, data.elng, opacity);
  85. if (!cloud.layer || !cloud.layer.tLayer || cloud.isHide) {
  86. meteo.c.map.removeLayer(cloudImageNew);
  87. return;
  88. }
  89. if (cloud.layer.imgOverlay) {
  90. meteo.c.map.removeImage(cloud.layer.imgOverlay);
  91. }
  92. cloud.layer.imgOverlay = cloudImageNew;
  93. },
  94. loadImage: function () {
  95. for (var i = 0; i < cloud.data.length; i++) {
  96. var url = JSON.parse(cloud.data[i].data).url;
  97. var img = $('<img />').attr('src', url);
  98. img = null;
  99. }
  100. },
  101. create: function () {
  102. cloud.layer = {
  103. tLayer: meteo.c.map.createLayer(),
  104. // cLayer: meteo.c.map.createLayer(),
  105. imgOverlay: null,
  106. }
  107. },
  108. remove: function () {
  109. if (cloud.layer) {
  110. meteo.c.map.removeLayer(cloud.layer.tLayer);
  111. cloud.removeImage();
  112. cloud.layer = null;
  113. }
  114. },
  115. removeImage: function () {
  116. if (cloud.layer && cloud.layer.imgOverlay) {
  117. meteo.c.map.removeImage(cloud.layer.imgOverlay);
  118. cloud.layer.imgOverlay = null;
  119. }
  120. },
  121. show: function () {
  122. cloud.isHide = false;
  123. cloud.showCloud();
  124. },
  125. hide: function () {
  126. cloud.isHide = true;
  127. if (cloud.playId) {
  128. cloud.clearPlay();
  129. }
  130. cloud.removeImage();
  131. },
  132. open: function (type) {
  133. if (ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
  134. ONEMAP.C.publisher.publish({type: 'warning', message: '图层数量已达上限'}, 'noteBar::add');
  135. return;
  136. }
  137. //-------------创建图层------------------
  138. if (cloud.layer) {
  139. cloud.close();
  140. }
  141. cloud.create();
  142. //----------------图层管理-------------------
  143. var options = {
  144. action: "add",
  145. // mod: "qixiang",
  146. DOM: {
  147. guid: cloud.layer.tLayer,
  148. type: "group",
  149. name: cloud.title + cloud.type[type],
  150. },
  151. }
  152. var guid = ONEMAP.M.myLayers.myLayerControl(options);
  153. ONEMAP.C.publisher.subscribe(function (option) {
  154. switch (option.action) {
  155. case 'remove':
  156. cloud.close();
  157. break;
  158. case 'opacity':
  159. if (option.options.opacity) {
  160. cloud.show();
  161. } else {
  162. cloud.hide();
  163. }
  164. // cloud.updateOpacity(option.options.opacity);
  165. break;
  166. }
  167. }, guid);
  168. //-------------------------------------
  169. $('#meteo-bt-cloud-ch1').parent().removeClass('current');
  170. $('#meteo-bt-cloud-ch3').parent().removeClass('current');
  171. $('#meteo-bt-cloud-ch4').parent().removeClass('current');
  172. $("#meteo-bt-cloud-" + type).parent().addClass('current');
  173. //------------------------------------------
  174. meteo.c.title.addTitle(cloud.id);
  175. //--------------------------------------
  176. cloud.showType = type;
  177. cloud.getCloudData();
  178. },
  179. close: function () {
  180. if (cloud.playId) {
  181. cloud.clearPlay();
  182. }
  183. var options = {
  184. action: "remove",
  185. DOMid: cloud.layer.tLayer,
  186. }
  187. ONEMAP.M.myLayers.myLayerControl(options);
  188. $("#meteo-bt-cloud-" + cloud.showType).parent().removeClass('current');
  189. meteo.c.title.removeTitle(cloud.id);
  190. $('#meteo-cloud-item' + cloud.showIndex).parent().removeClass('current');
  191. cloud.showIndex = null;
  192. cloud.remove();
  193. $('#meteo-list-cloud').html(''); //关闭时清空列表
  194. },
  195. updateOpacity: function (opacity) { //透明度调整(仅限二维地图
  196. if (!cloud.layer || !cloud.layer.imgOverlay) return;
  197. // cloud.showCloud(opacity);
  198. meteo.c.map.upDateImage(cloud.layer.imgOverlay, opacity);
  199. },
  200. init: function () {
  201. $('#meteo-bt-cloud-ch1').click(function () { //红外一通道
  202. if (cloud.layer && cloud.showType == 'ch1') {
  203. cloud.close();
  204. } else {
  205. cloud.open('ch1');
  206. }
  207. });
  208. $('#meteo-bt-cloud-ch4').click(function () { //可见光
  209. if (cloud.layer && cloud.showType == 'ch4') {
  210. cloud.close();
  211. } else {
  212. cloud.open('ch4');
  213. }
  214. });
  215. $('#meteo-bt-cloud-ch3').click(function () { //水汽通道
  216. if (cloud.layer && cloud.showType == 'ch3') {
  217. cloud.close();
  218. } else {
  219. cloud.open('ch3');
  220. }
  221. });
  222. $('#meteo-bt-cloud-paly').click(function () {
  223. cloud.play();
  224. });
  225. // _myLayerActions.init();
  226. },
  227. play: function () { //云图动画
  228. if (cloud.isHide) return;
  229. if (!cloud.layer) return;
  230. if (cloud.playId) {
  231. cloud.clearPlay();
  232. } else {
  233. cloud.playId = window.setInterval(function () {
  234. var index = cloud.showIndex + 1;
  235. if (index == cloud.data.length) {
  236. index = 0;
  237. }
  238. cloud.clickCloudList(index);
  239. }, 1000);
  240. $('#meteo-bt-cloud-paly').addClass('current');
  241. }
  242. },
  243. clearPlay: function () {
  244. window.clearInterval(cloud.playId);
  245. $('#meteo-bt-cloud-paly').removeClass('current');
  246. cloud.playId = null;
  247. }
  248. }
  249. meteo.f.cloud = cloud;
  250. return meteo.f.cloud;
  251. })
  252. // showCloud: function (type, json) { //根据索引 显示云图
  253. // var data = cloud.data[cloud.showIndex];
  254. // var layerid = meteo.c.map.createLayer();
  255. // var imageO = map2DViewer.groups[layerid];
  256. //
  257. // var cloudImageNew = L.imageOverlay(
  258. // data.url,
  259. // L.latLngBounds(L.latLng(data.slat, data.slng), L.latLng(data.elat, data.elng))
  260. // ).addTo(imageO);
  261. //
  262. // cloudImageNew.on("load", function (e) {
  263. // if (cloud.imgOverlay) {
  264. // meteo.c.map.removeLayer(cloud.imgOverlay);
  265. // }
  266. // cloud.imgOverlay = layerid;
  267. // });
  268. // if (cloud.title) {
  269. // meteo.c.title.removeTitle(cloud.title);
  270. // }
  271. // cloud.title = "云图 " + cloud.data[cloud.showIndex].time;
  272. // meteo.c.title.addTitle(cloud.title);
  273. // },