PR.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. * 本地等值线
  3. * Created by Administrator on 2017/11/9.
  4. */
  5. define(['meteoDir/other/smooth'], function (smooth) {
  6. var pr = {
  7. id: 'pr',
  8. title: '气压',
  9. title2: '位势高度',
  10. legend: 'images/meteo/legend/pr.png',
  11. isInit: false,
  12. layer: null,
  13. data: null,
  14. elem: 'PR',
  15. elem2:'GH',
  16. level: null,
  17. levelName: {
  18. '9999': '海平面',
  19. '0925': '925hPa',
  20. '0850': '850hPa',
  21. '0700': '700hPa',
  22. '0500': '500hPa'
  23. },
  24. buttons: {
  25. '9999': null,
  26. '0925': null,
  27. '0850': null,
  28. '0700': null,
  29. '0500': null
  30. },
  31. isHide: false,
  32. getData: function () {
  33. var dateStr = meteo.c.time.getTime();
  34. var vti = meteo.c.time.getVti();
  35. var elem = pr.elem;
  36. if (pr.level != '9999') elem = pr.elem2;
  37. var params = {
  38. elem: elem,
  39. level: pr.level,
  40. dateStr: dateStr,
  41. vti: vti,
  42. }
  43. meteo.c.http.httpFunction(meteo.c.http.tIsoLine, null, params, function (json) {
  44. pr.data = json;
  45. var title = pr.title;
  46. if (pr.level != '9999') title = pr.title2;
  47. meteo.c.title.updateTitle(pr.id,
  48. meteo.c.process.setTitleTime(json.odate, json.vti, title, pr.levelName[pr.level]));
  49. $('#meteo-video-query-startDate').val(json.odate);
  50. pr.showPR(json);
  51. }, function () {
  52. // ONEMAP.C.publisher.publish({ type: 'warning', message: '海平面气压暂无当前时次/层次数据' }, 'noteBar::add');
  53. // meteo.c.title.updateTitle(pr.id,'海平面气压暂无当前时次/层次数据');
  54. })
  55. // meteo.c.http.getLocalJson('T799_isoline_2018010900_000_PR_9999.json', function (json) {
  56. // pr.data = json;
  57. // pr.showPR(json);
  58. // })
  59. },
  60. showPR: function (data) {
  61. var layerId = meteo.c.map.createLayer();
  62. var layer = map2DViewer.groups[layerId];
  63. var lines = data.lines;
  64. for (var index in lines) {
  65. var line = lines[index];
  66. // lineColor alpha b g r
  67. //标高低中心
  68. if (line.clat && line.clng && line.ctype) {
  69. var textAttr = pr.getText('PR', line.ctype);
  70. if (textAttr && textAttr.length == 2) {
  71. meteo.c.map.addText(textAttr[0], textAttr[0], 16, textAttr[1], 2,
  72. line.clat, line.clng, layerId, true)
  73. }
  74. }
  75. //找每条线的经纬点
  76. var latlngs = [];
  77. var isLegal = true;
  78. for (var i = 0; i < line.pointNum; i++) {
  79. latlngs.push([line.lng[i], line.lat[i]]);
  80. // latlngs.push([line.lat[i], line.lng[i]]);
  81. }
  82. //线条平滑
  83. // var smoothLatlngs = latlngs.length > 2 ? smooth(latlngs, 0.1, 0.24) : latlngs;
  84. // latlngs = (isLegal && smoothLatlngs.length > 1) ? smoothLatlngs : latlngs;
  85. //画线
  86. var lineColor = 'black';
  87. var textColor = 'black';
  88. if (line.lineColor && (line.lineColor.r == 0 || line.lineColor.r)
  89. && (line.lineColor.g == 0 || line.lineColor.g)
  90. && (line.lineColor.b == 0 || line.lineColor.b)) {
  91. lineColor = Color.rgb(line.lineColor.r, line.lineColor.g, line.lineColor.b, 255);
  92. textColor = 'rgb(' + line.lineColor.r + ', ' + line.lineColor.g + ', ' + line.lineColor.b + ')';
  93. }
  94. var weight = line.lineWidth ? line.lineWidth : 1;
  95. meteo.c.map.addPolyline('', lineColor, weight, null, latlngs, layerId, true);
  96. // var li = L.polyline(latlngs, {
  97. // color: lineColor
  98. // });
  99. // li.addTo(layer);
  100. //标数字
  101. if (line.val) {
  102. if (!line.isClose) {
  103. meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
  104. latlngs[0][1], latlngs[0][0], layerId, true);
  105. meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
  106. latlngs[latlngs.length - 1][1], latlngs[latlngs.length - 1][0], layerId, true);
  107. } else {
  108. var index = (latlngs.length * 3 / 4) >> 0;
  109. meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
  110. latlngs[index][1], latlngs[index][0], layerId, true);
  111. }
  112. }
  113. }
  114. if (!pr.layer || !pr.layer.tLayer || pr.isHide) {
  115. meteo.c.map.removeLayer(layerId);
  116. return;
  117. }
  118. if (pr.layer.cLayer) {
  119. meteo.c.map.removeLayer(pr.layer.cLayer);
  120. }
  121. pr.layer.cLayer = layerId;
  122. },
  123. getText: function (elem, type) {
  124. var textAttr = [];
  125. if ("L" == type) {
  126. textAttr.push("低");
  127. textAttr.push("red");
  128. } else if ("H" == type) {
  129. textAttr.push("高");
  130. textAttr.push("blue");
  131. }
  132. return textAttr;
  133. },
  134. create: function () {
  135. pr.layer = {
  136. tLayer: meteo.c.map.createLayer(),
  137. cLayer: null,
  138. }
  139. },
  140. remove: function () {
  141. if (pr.layer) {
  142. meteo.c.map.removeLayer(pr.layer.tLayer);
  143. meteo.c.map.removeLayer(pr.layer.cLayer);
  144. pr.layer = null;
  145. }
  146. },
  147. show: function () {
  148. pr.isHide = false;
  149. pr.showPR(pr.data);
  150. },
  151. hide: function () {
  152. pr.isHide = true;
  153. if (pr.layer) {
  154. meteo.c.map.removeLayer(pr.layer.cLayer);
  155. pr.layer.cLayer = null;
  156. }
  157. },
  158. open: function () {
  159. if(ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
  160. ONEMAP.C.publisher.publish({ type: 'warning', message: '图层数量已达上限' }, 'noteBar::add');
  161. return;
  162. }
  163. //-------------创建图层------------------
  164. if (pr.layer) {
  165. pr.remove();
  166. }
  167. pr.create();
  168. //----------------图层管理-------------------
  169. var options = {
  170. action: "add",
  171. // mod: "qixiang",
  172. DOM: {
  173. guid: pr.layer.tLayer,
  174. type: "group",
  175. name: pr.title,
  176. },
  177. }
  178. var guid = ONEMAP.M.myLayers.myLayerControl(options);
  179. ONEMAP.C.publisher.subscribe(function (option) {
  180. switch (option.action) {
  181. case 'remove':
  182. pr.close();
  183. break;
  184. case 'opacity':
  185. if (option.options.opacity) {
  186. pr.show();
  187. } else {
  188. pr.hide();
  189. }
  190. break;
  191. }
  192. }, guid);
  193. //-------------------------------------
  194. pr.buttons[pr.level].parent().addClass('current');
  195. meteo.c.title.addTitle(pr.id);
  196. meteo.c.time.open();
  197. pr.getData();
  198. },
  199. close: function () {
  200. var options = {
  201. action: "remove",
  202. DOMid: pr.layer.tLayer,
  203. }
  204. ONEMAP.M.myLayers.myLayerControl(options);
  205. pr.buttons[pr.level].parent().removeClass('current');
  206. meteo.c.title.removeTitle(pr.id);
  207. meteo.c.time.close();
  208. pr.level = null;
  209. pr.remove();
  210. },
  211. update: function () { //用于时间变化时更新数据
  212. if (!pr.layer || pr.isHide) return;
  213. // var option = {
  214. // action: 'update',
  215. // DOMid: pr.layer.tLayer,
  216. // DOM: {
  217. // name: '气压' + meteo.c.time.getTimeOnTitle()
  218. // }
  219. // }
  220. // ONEMAP.M.myLayers.myLayerControl(option);
  221. pr.getData()
  222. },
  223. updateLevel: function () {
  224. pr.buttons[pr.level].parent().siblings().removeClass('current');
  225. pr.buttons[pr.level].parent().addClass('current');
  226. pr.getData()
  227. },
  228. click: function (level) { //点击相关按钮时调用
  229. if (pr.level && level != pr.level) {
  230. pr.level = level;
  231. pr.updateLevel();
  232. } else {
  233. pr.level = level;
  234. if (pr.layer) {
  235. pr.close()
  236. } else {
  237. pr.open();
  238. }
  239. }
  240. },
  241. init: function () {
  242. var buttons = $('.meteo-button-799');
  243. pr.buttons['9999'] = buttons.eq(5);
  244. pr.buttons['0925'] = buttons.eq(6);
  245. pr.buttons['0850'] = buttons.eq(7);
  246. pr.buttons['0700'] = buttons.eq(8);
  247. pr.buttons['0500'] = buttons.eq(9);
  248. }
  249. }
  250. meteo.f.pr = pr;
  251. return meteo.f.pr;
  252. })