TT.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /**
  2. * 本地等值线
  3. * Created by Administrator on 2017/11/9.
  4. */
  5. define(['meteoDir/other/smooth'], function (smooth) {
  6. var tt = {
  7. id: 'tt',
  8. title: '气温',
  9. legend: 'images/meteo/legend/tt.png',
  10. isInit: false,
  11. layer: null,
  12. data: null,
  13. elems: {
  14. 'TT': '气温',
  15. 'T2': '气温',
  16. },
  17. elem: 'TT',
  18. level: null,
  19. levelName: {
  20. '9999': '2米',
  21. '0925': '925hPa',
  22. '0850': '850hPa',
  23. '0700': '700hPa',
  24. '0500': '500hPa'
  25. },
  26. buttons: {
  27. '9999': null,
  28. '0925': null,
  29. '0850': null,
  30. '0700': null,
  31. '0500': null
  32. },
  33. isHide: false,
  34. getData: function () {
  35. var dateStr = meteo.c.time.getTime();
  36. // var dateStr = '2018-01-07 14:00:00';
  37. var vti = meteo.c.time.getVti();
  38. var params = {
  39. dateStr: dateStr,
  40. vti: vti,
  41. elem: tt.elem,
  42. level: tt.level
  43. }
  44. meteo.c.http.httpFunction(meteo.c.http.tImage, null, params, function (json) {
  45. meteo.c.title.updateTitle(tt.id,
  46. meteo.c.process.setTitleTime(json.odate, json.vti, tt.title, tt.levelName[tt.level]));
  47. $('#meteo-video-query-startDate').val(json.odate);
  48. json = json.data;
  49. json = JSON.parse(json);
  50. tt.data = json;
  51. tt.showTT(json);
  52. }, function () {
  53. // ONEMAP.C.publisher.publish({ type: 'warning', message: '气温暂无当前时次/层次数据' }, 'noteBar::add');
  54. // meteo.c.title.updateTitle(tt.id,'气温暂无当前时次/层次数据');
  55. })
  56. params.vti = parseInt(vti) + 3;
  57. meteo.c.http.httpFunction(meteo.c.http.tImage, null, params, function (json) {
  58. json = json.data;
  59. json = JSON.parse(json);
  60. tt.loadImage(json);
  61. }, function () {
  62. })
  63. // meteo.c.http.getLocalJson('799/T799_isoline_2017122420_000_T2_9999.json', function (json) {
  64. // tt.data = json;
  65. // tt.showTT(json);
  66. // })
  67. },
  68. showTT: function (data) {
  69. var images = [];
  70. var latI = (data.elat - data.slat) / data.row;
  71. var lngI = (data.elng - data.slng) / data.col;
  72. for (var i = 0; i < data.files.length; i++) {
  73. var value = data.files[i];
  74. if (value) {
  75. var str = value.split("\.")[0]; //去除后缀
  76. str = str.split("_"); //分割字符串,找出图片对应索引
  77. var x = str[0]; //lat索引(纬度
  78. var y = str[1]; //lng索引(经度
  79. var slat = data.slat + x * latI;
  80. var slng = data.slng + y * lngI;
  81. var elat = slat + latI;
  82. var elng = slng + lngI;
  83. elat = elat > data.elat ? data.elat : elat;
  84. elng = elng > data.elng ? data.elat : elng;
  85. var url = data.url + value + '.mkt';
  86. // var url = 'http://192.0.0.177/images/799/aa.png';
  87. images.push(meteo.c.map.addImage(url, slat, slng, elat, elng));
  88. // L.imageOverlay(
  89. // // 'http://107.1.170.193:8080/scripts/meteo/test/799/T799_2017122400_054_TR_9999_'
  90. // // + x + '_' + y +
  91. // // '.png.mkt',
  92. // data.url + value + '.mkt',
  93. // L.latLngBounds(L.latLng(slat, slng), L.latLng(elat, elng))
  94. // ).addTo(layer);
  95. }
  96. }
  97. if (!tt.layer|| !tt.layer.tLayer || tt.isHide) {
  98. for (var i = 0; i < images.length; i++) {
  99. meteo.c.map.removeImage(images[i]);
  100. }
  101. } else {
  102. if (tt.layer.images) {
  103. tt.removeImage();
  104. }
  105. tt.layer.images = images;
  106. }
  107. // setTimeout(function () {
  108. //
  109. // }, 300);
  110. },
  111. loadImage:function (data) { //预先加载图片
  112. for (var i = 0; i < data.files.length; i++) {
  113. var value = data.files[i];
  114. if (value) {
  115. var url = data.url + value + '.mkt';
  116. var img = $('<img />').attr('src', url);
  117. img = null;
  118. }
  119. }
  120. },
  121. showIsoLine: function (data) {
  122. var layerId = meteo.c.map.createLayer();
  123. var layer = map2DViewer.groups[layerId];
  124. var lines = data.lines;
  125. for (var index in lines) {
  126. var line = lines[index];
  127. // lineColor alpha b g r
  128. //标高低中心
  129. if (line.clat && line.clng && line.ctype) {
  130. var textAttr = tt.getText('TT', line.ctype);
  131. if (textAttr && textAttr.length == 2) {
  132. meteo.c.map.addText(textAttr[0], textAttr[0], 16, textAttr[1], 2, line.clat, line.clng, layerId)
  133. }
  134. }
  135. //找每条线的经纬点
  136. var latlngs = [];
  137. var isLegal = true;
  138. for (var i = 0; i < line.pointNum; i++) {
  139. latlngs.push([line.lng[i], line.lat[i]]);
  140. // latlngs.push([line.lat[i], line.lng[i]]);
  141. }
  142. //线条平滑
  143. // var smoothLatlngs = latlngs.length > 2 ? smooth(latlngs, 0.1, 0.24) : latlngs;
  144. // latlngs = (isLegal && smoothLatlngs.length > 1) ? smoothLatlngs : latlngs;
  145. //画线
  146. var lineColor = 'black';
  147. var textColor = 'black';
  148. if (line.lineColor && (line.lineColor.r == 0 || line.lineColor.r)
  149. && (line.lineColor.g == 0 || line.lineColor.g)
  150. && (line.lineColor.b == 0 || line.lineColor.b)) {
  151. lineColor = Color.rgb(line.lineColor.r, line.lineColor.g, line.lineColor.b, 255);
  152. textColor = 'rgb(' + line.lineColor.r + ', ' + line.lineColor.g + ', ' + line.lineColor.b + ')';
  153. }
  154. var weight = line.lineWidth ? line.lineWidth : 1;
  155. meteo.c.map.addPolyline('', lineColor, weight, null, latlngs, layerId, true);
  156. // var li = L.polyline(latlngs, {
  157. // color: lineColor
  158. // });
  159. // li.addTo(layer);
  160. //标数字
  161. if (line.val) {
  162. if (!line.isClose) {
  163. meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
  164. latlngs[0][1], latlngs[0][0], layerId, true);
  165. meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
  166. latlngs[latlngs.length - 1][1], latlngs[latlngs.length - 1][0], layerId, true);
  167. } else {
  168. var index = (latlngs.length * 3 / 4) >> 0;
  169. meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
  170. latlngs[index][1], latlngs[index][0], layerId, true);
  171. }
  172. }
  173. }
  174. // if (!tt.layer || !tt.layer.tLayer || tt.isHide) {
  175. // meteo.c.map.removeLayer(layerId);
  176. // return;
  177. // }
  178. if (tt.layer.cLayer) {
  179. meteo.c.map.removeLayer(tt.layer.cLayer);
  180. }
  181. tt.layer.cLayer = layerId;
  182. },
  183. getText: function (elem, type) {
  184. var textAttr = [];
  185. if ("TT" == elem) {
  186. if ("L" == type) {
  187. textAttr.push("冷");
  188. textAttr.push("blue");
  189. } else if ("H" == type) {
  190. textAttr.push("暖");
  191. textAttr.push("red");
  192. }
  193. } else if ("HH" == elem || "PR" == elem) {
  194. if ("L" == type) {
  195. textAttr.push("低");
  196. textAttr.push("red");
  197. } else if ("H" == type) {
  198. textAttr.push("高");
  199. textAttr.push("blue");
  200. }
  201. }
  202. return textAttr;
  203. },
  204. create: function () {
  205. tt.layer = {
  206. tLayer: meteo.c.map.createLayer(),
  207. // cLayer: null,
  208. images: null,
  209. }
  210. },
  211. remove: function () {
  212. if (tt.layer) {
  213. meteo.c.map.removeLayer(tt.layer.tLayer);
  214. // meteo.c.map.removeLayer(tt.layer.cLayer);
  215. tt.removeImage();
  216. tt.layer = null;
  217. }
  218. },
  219. removeImage: function () {
  220. if (tt.layer.images) {
  221. for (var i = 0; i < tt.layer.images.length; i++) {
  222. meteo.c.map.removeImage(tt.layer.images[i]);
  223. }
  224. tt.layer.images = null;
  225. }
  226. },
  227. show: function () {
  228. tt.isHide = false;
  229. tt.showTT(tt.data);
  230. },
  231. hide: function () {
  232. tt.isHide = true;
  233. if (tt.layer) {
  234. tt.removeImage();
  235. // meteo.c.map.removeLayer(tt.layer.cLayer);
  236. // tt.layer.cLayer = null;
  237. }
  238. },
  239. open: function (elem, hpa) {
  240. if(ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
  241. ONEMAP.C.publisher.publish({ type: 'warning', message: '图层数量已达上限' }, 'noteBar::add');
  242. return;
  243. }
  244. //-------------创建图层------------------
  245. if (tt.layer) {
  246. tt.remove();
  247. }
  248. tt.create();
  249. //----------------图层管理-------------------
  250. var options = {
  251. action: "add",
  252. // mod: "qixiang",
  253. DOM: {
  254. guid: tt.layer.tLayer,
  255. type: "group",
  256. name: tt.title,
  257. },
  258. }
  259. var guid = ONEMAP.M.myLayers.myLayerControl(options);
  260. ONEMAP.C.publisher.subscribe(function (option) {
  261. switch (option.action) {
  262. case 'remove':
  263. tt.close();
  264. break;
  265. case 'opacity':
  266. if (option.options.opacity) {
  267. tt.show();
  268. } else {
  269. tt.hide();
  270. }
  271. break;
  272. }
  273. }, guid);
  274. //-------------------------------------
  275. tt.buttons[tt.level].parent().addClass('current');
  276. meteo.c.title.addTitle(tt.id);
  277. meteo.c.legend.addLegend(tt.id, tt.legend);
  278. meteo.c.time.open();
  279. tt.isHide = false;
  280. tt.getData(elem, hpa);
  281. },
  282. close: function () {
  283. var options = {
  284. action: "remove",
  285. DOMid: tt.layer.tLayer,
  286. }
  287. ONEMAP.M.myLayers.myLayerControl(options);
  288. tt.buttons[tt.level].parent().removeClass('current');
  289. meteo.c.title.removeTitle(tt.id);
  290. meteo.c.legend.removeLegend(tt.id);
  291. meteo.c.time.close();
  292. tt.level = null;
  293. tt.isHide = false;
  294. tt.remove();
  295. },
  296. update: function () { //用于时间变化时更新数据
  297. if (!tt.layer || tt.isHide) return;
  298. // var option = {
  299. // action: 'update',
  300. // DOMid: tt.layer.tLayer,
  301. // DOM: {
  302. // name: '气温' + meteo.c.time.getTimeOnTitle()
  303. // }
  304. // }
  305. // ONEMAP.M.myLayers.myLayerControl(option);
  306. tt.getData();
  307. },
  308. updateLevel: function () {
  309. tt.buttons[tt.level].parent().siblings().removeClass('current');
  310. tt.buttons[tt.level].parent().addClass('current');
  311. tt.getData();
  312. },
  313. click: function (level) {
  314. if (tt.level && level != tt.level) {
  315. tt.level = level;
  316. tt.updateLevel();
  317. } else {
  318. tt.level = level;
  319. if (tt.layer) {
  320. tt.close();
  321. } else {
  322. tt.open();
  323. }
  324. }
  325. },
  326. init: function () {
  327. var buttons = $('.meteo-button-799');
  328. tt.buttons['9999'] = buttons.eq(0);
  329. tt.buttons['0925'] = buttons.eq(1);
  330. tt.buttons['0850'] = buttons.eq(2);
  331. tt.buttons['0700'] = buttons.eq(3);
  332. tt.buttons['0500'] = buttons.eq(4);
  333. }
  334. }
  335. meteo.f.tt = tt;
  336. return meteo.f.tt;
  337. })