airport.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /**
  2. * 机场单点数据(暂命名)
  3. * Created by Administrator on 2017/11/7.
  4. */
  5. define([], function () {
  6. var airport = {
  7. isInit: false,
  8. map: null,
  9. layer: null,
  10. data: null,
  11. startZoom: null,
  12. isLoad: false,
  13. isClose: false,
  14. isHide: false,
  15. getData: function () { //获取数据
  16. meteo.c.http.httpFunction(meteo.c.http.airportIndex, null, null, function (json) {
  17. airport.data = json;
  18. airport.drawAllMarkerForLayerZoom();
  19. }, function () {
  20. airport.isLoad = false;
  21. ONEMAP.C.publisher.publish({ type: 'warning', message: '民航报暂无数据' }, 'noteBar::add');
  22. })
  23. },
  24. drawAirportMarker: function (lng, lat, station, cname) { //绘制单个marker点,同时给每个marker加入点击事件
  25. var iconUrl = 'images/meteo/airport_brown.png';
  26. // var iconUrl = airport.getIcon(sigmenttype);
  27. var myIcon = L.icon({
  28. iconUrl: iconUrl,
  29. iconSize: [16, 16],
  30. iconAnchor: [8, 8],
  31. })
  32. return L.marker([lng, lat], {icon: myIcon}).on('click', function (marker) {
  33. meteo.c.http.httpFunction(meteo.c.http.airportInfo, station, null, function (json) {
  34. var content = airport.getPopupContent(json, station, cname);
  35. airport.popup.setLatLng(marker.latlng)
  36. .setContent(content)
  37. .openOn(map2DViewer.map);
  38. })
  39. });
  40. },
  41. getIcon: function (sigmenttype) { //获取icon图片
  42. var url = airport.contains(sigmenttype, "RAIN") ? 'airport_green.png' :
  43. airport.contains(sigmenttype, "SOOT") ? 'airport_brown.png' :
  44. airport.contains(sigmenttype, "THUNDER") ? 'airport_red.png' :
  45. airport.contains(sigmenttype, "SAND") ? 'airport_brown.png' :
  46. airport.contains(sigmenttype, "STORM") ? 'airport_brown.png' :
  47. airport.contains(sigmenttype, "CLOTTED GROUND") ? 'airport_green.png' :
  48. airport.contains(sigmenttype, "PUFF SNOW") ? 'airport_green.png' :
  49. airport.contains(sigmenttype, "FIRN SNOW") ? 'airport_green.png' :
  50. airport.contains(sigmenttype, "SNOW") ? 'airport_green.png' :
  51. airport.contains(sigmenttype, "FOG") ? 'airport_yellow.png' : 'airport_gray.png';
  52. return meteo.c.http.myImageUrlJs + url;
  53. },
  54. getPopupContent: function (data, station, cname) {
  55. var html = "<div class='popup_html'>"
  56. + "<div class='popup-lt'></div>"
  57. + "<div class='popup-lb'></div>"
  58. + "<div class='popup-rt'></div>"
  59. + "<div class='popup-rb'></div>"
  60. + "<div class='popup-ct'>"
  61. + "<div class='meteo-menu-top meteo-menu-top-airport'>"
  62. // + "<h3 class='meteo-title meteo-title-airport'>" + cname + " " + station + "</h3>"
  63. + "<h3 class='meteo-title meteo-title-airport'>" + cname + " " + "</h3>"
  64. + "</div>"
  65. + "</div>"
  66. + "<div class='popup-cb' style='padding-bottom:20px;'>"
  67. + "<div class='meteo-popup-airport-warp content_scroll'>"
  68. + "<ul class='meteo-popup-airportUl'>"
  69. + "<li><h4 class='meteo-popup-airpory-h4'>----机场实况----</h4></li>"
  70. // + "<li class='meteo-popup-airport-li'><span>观测时间:</span><span>" + meteo.c.process.setDate(data.ldate) + "</span></li>"
  71. + "<li class='meteo-popup-airport-li'><span>观测时间:</span><span>" + meteo.c.process.setData(data.ldate, "") + " " + "</span></li>"
  72. + "<li class='meteo-popup-airport-li'><span>天气现象:</span><span>" + meteo.c.process.setWth(data.wth1) + "</span></li>"
  73. + "<li class='meteo-popup-airport-li'><span>气温:</span><span>" + meteo.c.process.setTt(data.tt) + "</span></li>"
  74. + "<li class='meteo-popup-airport-li'><span>气压:</span><span>" + meteo.c.process.setPr(data.pr) + "</span></li>"
  75. + "<li class='meteo-popup-airport-li'><span>露点温度:</span><span>" + meteo.c.process.setTt(data.td) + "</span></li>"
  76. + "<li class='meteo-popup-airport-li'><span>能见度:</span><span>" + meteo.c.process.setVis(data.vis) + "</span></li>"
  77. + "<li class='meteo-popup-airport-li'><span>云:</span><span>" + "--" + "</span></li>"
  78. + "<li class='meteo-popup-airport-li'><span>风:</span><span>" + meteo.c.process.setWsWd(data.ws, data.wd) + "</span></li>"
  79. // + "<li class='meteo-popup-airpory-li'>"
  80. // + "<h4 class='meteo-popup-airpory-h4'>----机场预报----</h4>"
  81. // + "</li>"
  82. // + "<li><span>起止时间:</span><span>--</span> </li>"
  83. // + "<li><span>能见度:</span><span>3500米</span></li>"
  84. // + "<li><span>云:</span><span>疏云/480米</span></li>"
  85. // + "<li><span>天气现象:</span><span>轻雾(水滴冰晶)</span></li>"
  86. // + "<li><span>风:</span><span>150°4米/秒</span></li>"
  87. // + "<li><span>气温:</span><span>9°</span></li>"
  88. // + "<li>"
  89. // + "<p class='meteo-popup-airpory-text'></p>"
  90. // + "</li>"
  91. + "</ul>"
  92. //+"<a href="##" class="meteo-delete"><img src="image/delete.png" height="18" width="16" alt="" /></a>"
  93. + "</div>"
  94. + "</div>"
  95. + "</div>";
  96. return html;
  97. },
  98. drawAllMarkerForLayerZoom: function () {
  99. if (!airport.data) return;
  100. var layerId = meteo.c.map.createLayer();
  101. var layer = map2DViewer.groups[layerId];
  102. var zoom = map2DViewer.map._zoom;
  103. for (var i = 0; i < airport.data.length; i++) {
  104. var data = airport.data[i];
  105. if (zoom < 5 && data.level > 1) {
  106. continue;
  107. }
  108. airport.drawAirportMarker(data.lng, data.lat, data.station, data.cname).addTo(layer);
  109. }
  110. if (!airport.layer || !airport.layer.tLayer || airport.isHide) {
  111. meteo.c.map.removeLayer(layerId);
  112. return;
  113. }
  114. if (airport.layer.cLayer) {
  115. meteo.c.map.removeLayer(airport.layer.cLayer);
  116. }
  117. airport.layer.cLayer = layerId;
  118. airport.isLoad = false;
  119. },
  120. create: function () {
  121. airport.layer = {
  122. tLayer: meteo.c.map.createLayer(),
  123. cLayer: null,
  124. }
  125. },
  126. remove: function () {
  127. if (airport.layer) {
  128. meteo.c.map.removeLayer(airport.layer.tLayer);
  129. meteo.c.map.removeLayer(airport.layer.cLayer);
  130. airport.layer = null;
  131. }
  132. },
  133. show: function () {
  134. airport.isHide = false;
  135. airport.drawAllMarkerForLayerZoom();
  136. },
  137. hide: function () {
  138. airport.isHide = true;
  139. if (airport.layer) {
  140. meteo.c.map.removeLayer(airport.layer.cLayer);
  141. airport.layer.cLayer = null;
  142. airport.popup.remove();//2d弹窗存在时关闭
  143. }
  144. },
  145. open: function () {
  146. if(ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
  147. ONEMAP.C.publisher.publish({ type: 'warning', message: '图层数量已达上限' }, 'noteBar::add');
  148. return;
  149. }
  150. airport.isLoad = true;
  151. airport.isClose = false;
  152. airport.isHide = false;
  153. //-------------创建图层------------------
  154. if (airport.layer) {
  155. airport.remove();
  156. }
  157. airport.create();
  158. //----------------图层管理-------------------
  159. var options = {
  160. action: "add",
  161. // mod: "qixiang",
  162. DOM: {
  163. guid: airport.layer.tLayer,
  164. type: "group",
  165. name: '民航报',
  166. },
  167. }
  168. var guid = ONEMAP.M.myLayers.myLayerControl(options);
  169. ONEMAP.C.publisher.subscribe(function (option) {
  170. switch (option.action) {
  171. case 'remove':
  172. if (airport.isLoad) {
  173. airport.isClose = true;
  174. return;
  175. }
  176. airport.close();
  177. break;
  178. case 'opacity':
  179. if (airport.isLoad) {
  180. if (option.options.opacity) {
  181. airport.isHide = false;
  182. } else {
  183. airport.isHide = true;
  184. }
  185. return;
  186. }
  187. if (option.options.opacity) {
  188. airport.show();
  189. } else {
  190. airport.hide();
  191. }
  192. break;
  193. }
  194. }, guid);
  195. //-------------------------------------
  196. $("#meteo-bt-airport").parent().addClass('current');
  197. airport.getData();
  198. if (airport.isInit) return;
  199. airport.isInit = true;
  200. //--------------------记录层级缩放开始,当变化到4/5级时重新绘制-----------------------
  201. map2DViewer.map.on("zoomstart", function () {
  202. if (!airport.layer) return;
  203. airport.startZoom = map2DViewer.map._zoom;
  204. })
  205. map2DViewer.map.on("zoomend", function () {
  206. if (!airport.layer || !airport.layer.cLayer) return;
  207. if (airport.startZoom >= 5 && map2DViewer.map._zoom <= 4) {
  208. airport.drawAllMarkerForLayerZoom();
  209. }
  210. if (airport.startZoom <= 4 && map2DViewer.map._zoom >= 5) {
  211. airport.drawAllMarkerForLayerZoom();
  212. }
  213. })
  214. },
  215. close: function () {
  216. var options = {
  217. action: "remove",
  218. DOMid: airport.layer.tLayer,
  219. }
  220. ONEMAP.M.myLayers.myLayerControl(options);
  221. airport.popup.remove();//2d弹窗存在时关闭
  222. $("#meteo-bt-airport").parent().removeClass('current');
  223. airport.remove();
  224. },
  225. update: function () { //用于时间变化时更新数据
  226. // airport.getData()
  227. },
  228. init: function () {
  229. $("#meteo-bt-airport").click(function () {
  230. if (airport.isLoad) return;
  231. if (airport.layer) {
  232. airport.close();
  233. } else {
  234. airport.open();
  235. }
  236. });
  237. airport.popup = L.popup();
  238. },
  239. /**
  240. * 判断str是否包含str2
  241. */
  242. contains: function (str, str2) {
  243. if (str.indexOf(str2) >= 0) {
  244. return true;
  245. }
  246. return false;
  247. },
  248. //-----------------------一些显示数据的格式化方法---------------------
  249. showInfoWindowDate: function (data, str) {
  250. if (data != 0 && !data) {
  251. return "-";
  252. }
  253. if (str) {
  254. return ((data * 10) >> 0) / 10 + str;
  255. } else {
  256. return data;
  257. }
  258. },
  259. showCloudData: function (cn1, ch1, cn2, ch2, cn3, ch3, str) {
  260. if (cn1 && ch1) {
  261. cn1 = cn1 + "/" + ch1 + str;
  262. if (cn2 && ch2) {
  263. cn1 = cn1 + "," + cn2 + "/" + ch2 + str;
  264. }
  265. if (cn3 && ch3) {
  266. cn1 = cn1 + "," + cn3 + "/" + ch3 + str;
  267. }
  268. } else {
  269. cn1 = "-"
  270. }
  271. return cn1
  272. },
  273. showWindData: function (wd, ws) {
  274. if ((ws === 0 && wd) || (wd && ws)) {
  275. return wd + "°" + ws + "米/秒"
  276. }
  277. return "";
  278. },
  279. showInfoWindowFactTime: function (odate, timeBg, timeEd) {
  280. var start = timeBg;
  281. if (timeBg == timeEd) {
  282. start = odate;
  283. }
  284. if (!start || !timeEd) {
  285. return "--";
  286. }
  287. return start.substring(8, 10) + "日" + start.substring(11, 13) + "时" + start.substring(14, 16) + "分-"
  288. + timeEd.substring(8, 10) + "日" + timeEd.substring(11, 13) + "时" + timeEd.substring(14, 16) + "分";
  289. }
  290. };
  291. meteo.f.airport = airport;
  292. return meteo.f.airport;
  293. })