stationQuery.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * 站点查询
  3. */
  4. define([
  5. 'html!templates/meteo/currentLocation',
  6. 'modDir/service/addressSearch',
  7. ], function (clhtml, addressSearchF) {
  8. var query = {
  9. city: null,
  10. station: null,
  11. getData: function (station, city) {
  12. if (station) {
  13. query.show();
  14. } else {
  15. query.hide();
  16. }
  17. meteo.c.http.httpFunction(meteo.c.http.stationInfo, station, null, function (json) {
  18. query.station = station;
  19. query.city = city;
  20. query.updateQuery(json);
  21. })
  22. },
  23. updateQuery: function (json) {
  24. var city = meteo.c.process.setCity(query.city);
  25. city = ' <img src="../images/meteo/windDirection/location.png" width="20px" style="vertical-align: middle;" alt=""/>' + city;
  26. $('.meteo-cl-location-p').html(city);
  27. $('.meteo-cl-tt').html(meteo.c.process.setTt(json.tt));
  28. $('.meteo-cl-wth').html(meteo.c.process.setWth(json.wth));
  29. $('.meteo-cl-wind').html(meteo.c.process.setWs(json.ws));
  30. var url = json.wth < 10 ? '0' + json.wth : json.wth;
  31. url = 'url(../../images/meteo/weatherIcon/cww' + url + '.png)';
  32. $('.meteo-cl-wth').css('background-image', url);
  33. var str = json.wd ? json.wd : '--';
  34. if (str == '--') {
  35. $('.meteo-cl-wind').css('background-image', '');
  36. }
  37. str = str > 360 ? str % 360 : str;
  38. str = str < 0 ? (str + 360) : str;
  39. str = (str - 22.5) / 45;
  40. str = str < 0 ? '0' :
  41. str < 1 ? '1' :
  42. str < 2 ? '2' :
  43. str < 3 ? '3' :
  44. str < 4 ? '4' :
  45. str < 5 ? '5' :
  46. str < 6 ? '6' :
  47. str < 7 ? '7' : '0';
  48. str = 'url(../../images/meteo/windDirection/' + str + '.png)';
  49. $('.meteo-cl-wind').css('background-image', str);
  50. },
  51. show: function () {
  52. $('.meteo-cl-popup').show();
  53. // $('.meteo-cl-popup').css('display', '');
  54. },
  55. hide: function () {
  56. $('.meteo-cl-popup').hide();
  57. // $('.meteo-cl-popup').css('display', 'none');
  58. },
  59. getCenterStation: function () {
  60. // var weatherLatlng = [];
  61. // weatherLatlng.push([map23DData.view.center.lng, map23DData.view.center.lat]);
  62. // var addressSearch = new addressSearchF();
  63. // addressSearch.latlngToZDAndName(weatherLatlng, function (json) {
  64. // if (json.code == 1) {
  65. // query.hide();
  66. // } else if (json.code == 0) {
  67. // query.getData(json.data[0].station, json.data[0].chaname);
  68. // }
  69. // })
  70. },
  71. init: function () {
  72. $('.meteo-cl-box').append(clhtml);
  73. $('.meteo-cl-popup').click(function () {
  74. if (!query.station) return;
  75. meteo.c.popup.showPopup(query.station, query.city, 0);
  76. });
  77. query.getCenterStation();
  78. ONEMAP.C.publisher.subscribe(function (zoom) {
  79. if (zoom < 6) {
  80. query.hide();
  81. return;
  82. }
  83. query.getCenterStation();
  84. }, 'mapChange23D');
  85. }
  86. }
  87. query.init();
  88. // window.setTimeout(function () {
  89. // query.getData(54511, '北京');
  90. // window.setTimeout(function () {
  91. // // query.getData(54399, '海淀');
  92. // query.getData('', '海淀');
  93. // }, 2000)
  94. // }, 2000)
  95. meteo.f.query = {
  96. getData: query.getData
  97. }
  98. return meteo.f.query;
  99. })