isoLine.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * 本地等值线
  3. * Created by Administrator on 2017/11/9.
  4. */
  5. define(['meteoDir/other/smooth'], function (smooth) {
  6. meteo.f.isoLine = {
  7. isInit: false,
  8. layers: {},
  9. data: {},
  10. elems: {
  11. 'PR': '气压',
  12. 'T2': '温度'
  13. },
  14. getData: function (elem , level) {
  15. var params = {
  16. elem: elem,
  17. datastr: '',
  18. level: level
  19. }
  20. meteo.c.http.httpFunction(meteo.c.http.tIsoLine, null, params, function (json) {
  21. meteo.f.isoLine.data[elem] = json;
  22. meteo.f.isoLine.showLine(params, json);
  23. })
  24. // meteo.c.http.getLocalJson('799/T799_isoline_2017122400_000_T2_9999.json', function (json) {
  25. // meteo.f.isoLine.showLine(params, json);
  26. // })
  27. },
  28. showLine: function (params, data) {
  29. // var layerId = meteo.c.map.createLayer();
  30. var elem = params.elem;
  31. if (meteo.f.isoLine.layers[elem]) {
  32. meteo.c.map.clearLayer(meteo.f.isoLine.layers[elem])
  33. } else {
  34. meteo.f.isoLine.layers[elem] = meteo.c.map.createLayer();
  35. }
  36. var layerId = meteo.f.isoLine.layers[elem];
  37. var layer = map2DViewer.groups[layerId];
  38. var lines = data.lines;
  39. for (var index in lines) {
  40. var line = lines[index];
  41. // lineColor alpha b g r
  42. //标高低中心
  43. if (line.clat && line.clng && line.ctype) {
  44. var textAttr = meteo.f.isoLine.getText(elem, line.ctype);
  45. if (textAttr && textAttr.length == 2) {
  46. meteo.c.map.addText('', textAttr[0], 16, textAttr[1], 2, line.clat, line.clng, layerId)
  47. }
  48. }
  49. //找每条线的经纬点
  50. var latlngs = [];
  51. var isLegal = true;
  52. for (var i = 0; i < line.pointNum; i++) {
  53. latlngs.push([line.lng[i], line.lat[i]]);
  54. // latlngs.push([line.lat[i], line.lng[i]]);
  55. }
  56. //线条平滑
  57. var smoothLatlngs = latlngs.length > 2 ? smooth(latlngs, 0.1, 0.24) : latlngs;
  58. latlngs = (isLegal && smoothLatlngs.length > 1) ? smoothLatlngs : latlngs;
  59. //画线
  60. var lineColor = 'black';
  61. var textColor = 'black';
  62. if (line.lineColor && (line.lineColor.r == 0 || line.lineColor.r)
  63. && (line.lineColor.g == 0 || line.lineColor.g)
  64. && (line.lineColor.b == 0 || line.lineColor.b)) {
  65. lineColor = Color.rgb(line.lineColor.r, line.lineColor.g, line.lineColor.b, 255);
  66. textColor = 'rgb(' + line.lineColor.r + ', ' + line.lineColor.g + ', ' + line.lineColor.b + ')';
  67. }
  68. meteo.c.map.addPolyline('', lineColor, 2, null, latlngs, layerId);
  69. // var li = L.polyline(latlngs, {
  70. // color: lineColor
  71. // });
  72. // li.addTo(layer);
  73. //标数字
  74. // if ((line.val - meteo.f.isoLineLocal.data[type].labelBaseVal) % meteo.f.isoLineLocal.data[type].labelInterVal == 0) {
  75. if (line.val) {
  76. if (!line.isClose) {
  77. meteo.c.map.addText('', line.val, 16, textColor, 2, latlngs[0][1], latlngs[0][0], layerId);
  78. meteo.c.map.addText('', line.val, 16, textColor, 2, latlngs[latlngs.length - 1][1], latlngs[latlngs.length - 1][0], layerId);
  79. } else {
  80. var index = (latlngs.length * 3 / 4) >> 0;
  81. meteo.c.map.addText('', line.val, 16, textColor, 2, latlngs[index][1], latlngs[index][0], layerId);
  82. }
  83. }
  84. }
  85. // if (meteo.f.isoLine.layers[elem]) { //判断
  86. // meteo.c.map.removeLayer(meteo.f.isoLine.layers[elem]);
  87. // }
  88. // meteo.f.isoLine.layers[elem] = layerId;
  89. // if (meteo.f.isoLine.titles[elem]) {
  90. // meteo.f.isoLine.removeTitle(elem);
  91. // }
  92. // meteo.f.isoLine.addTitle(elem, hpa);
  93. //-----------------------------------
  94. var options = {
  95. action: "add",
  96. DOM: {
  97. guid: meteo.f.isoLine.layers[elem],
  98. type: "group",
  99. name: meteo.f.isoLine.elems[elem],
  100. },
  101. }
  102. var guid = ONEMAP.M.myLayers.myLayerControl(options);
  103. ONEMAP.C.publisher.subscribe(function (option) {
  104. if (option.action == 'remove') {
  105. meteo.f.isoLine.removeIsoLine(elem);
  106. if (elem == 'T2') {
  107. $("#meteo-bt-tt").parent().removeClass('current');
  108. } else {
  109. $("#meteo-bt-pr").parent().removeClass('current');
  110. }
  111. }
  112. }, guid);
  113. //-------------------------------------
  114. },
  115. getText: function (elem, type) {
  116. var textAttr = [];
  117. if ("TT" == elem) {
  118. if ("L" == type) {
  119. textAttr.push("冷");
  120. textAttr.push("blue");
  121. } else if ("H" == type) {
  122. textAttr.push("暖");
  123. textAttr.push("red");
  124. }
  125. } else if ("HH" == elem || "PR" == elem) {
  126. if ("L" == type) {
  127. textAttr.push("低");
  128. textAttr.push("red");
  129. } else if ("H" == type) {
  130. textAttr.push("高");
  131. textAttr.push("blue");
  132. }
  133. }
  134. return textAttr;
  135. },
  136. removeIsoLine: function (elem) {
  137. var options = {
  138. action: "remove",
  139. DOMid:meteo.f.isoLine.layers[elem],
  140. }
  141. ONEMAP.M.myLayers.myLayerControl(options);
  142. if (meteo.f.isoLine.layers[elem]) {
  143. meteo.c.map.removeLayer(meteo.f.isoLine.layers[elem]);
  144. meteo.f.isoLine.layers[elem] = null;
  145. }
  146. // meteo.f.isoLine.removeTitle(elem);
  147. },
  148. removeAllIsoLine: function () {
  149. for (var elem in meteo.f.isoLineLocal.layers) {
  150. meteo.f.isoLine.removeIsoLine(elem);
  151. }
  152. },
  153. // addTitle: function (elem, hpa) {
  154. // var ti = elem + " " + hpa;
  155. // meteo.f.isoLine.titles[elem] = ti;
  156. // meteo.c.title.addTitle(ti);
  157. // },
  158. // removeTitle: function (elem) {
  159. // meteo.c.title.removeTitle(meteo.f.isoLine.titles[elem]);
  160. // },
  161. close: function () {
  162. meteo.f.isoLine.removeAllIsoLine();
  163. },
  164. init: function () {
  165. $("#meteo-bt-tt").click(function () { //温度
  166. if (!meteo.f.isoLine.layers['T2']) {
  167. meteo.f.isoLine.getData('T2', '9999')
  168. } else {
  169. meteo.f.isoLine.removeIsoLine('T2')
  170. }
  171. });
  172. $("#meteo-bt-pr").click(function () { //气压
  173. if (!meteo.f.isoLine.layers['PR']) {
  174. meteo.f.isoLine.getData("PR", '9999');
  175. } else {
  176. meteo.f.isoLine.removeIsoLine('PR')
  177. }
  178. });
  179. // $("#meteo-bt-rh").click(function () { //湿度
  180. // if (!meteo.f.isoLine.layers['RH']) {
  181. // meteo.f.isoLine.getData("RH", '0925');
  182. // } else {
  183. // meteo.f.isoLine.removeIsoLine('RH')
  184. // }
  185. // });
  186. }
  187. }
  188. return meteo.f.isoLine;
  189. })