radarMap.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * Created by Administrator on 2017/10/31.
  3. * 雷达图类
  4. */
  5. define([], function () {
  6. meteo.f.radar = {
  7. data: null, //雷达图数据存储位置
  8. playId: null, //雷达图动画任务id
  9. imgOverlay: null, //雷达图所用图层id
  10. showIndex: 0, //将要被显示的雷达图索引
  11. title: null,
  12. getData: function () { //获取雷达图数据
  13. meteo.c.http.httpFunciton(meteo.c.http.radarInfo, null, function (json) {
  14. var data = json["data"];
  15. meteo.f.radar.data = new Array(data.length);
  16. for (var i = 0; i < data.length; i++) {
  17. var value = new Object();
  18. value.time = data[i]["date"];
  19. value.slat = data[i]["slat"];
  20. value.slng = data[i]["slng"];
  21. value.elat = data[i]["elat"];
  22. value.elng = data[i]["elng"];
  23. value.url = meteo.c.http.serverUrl + data[i]["url"] + ".mkt";
  24. meteo.f.radar.data[i] = value;
  25. }
  26. meteo.f.radar.show();
  27. }, function () {
  28. })
  29. },
  30. show: function () { //根据索引 显示云图
  31. var data = meteo.f.radar.data[meteo.f.radar.showIndex];
  32. var layerid = meteo.c.map.createLayer();
  33. var imageO = map2DViewer.groups[layerid];
  34. var cloudImageNew = L.imageOverlay(
  35. data.url,
  36. L.latLngBounds(L.latLng(data.slat, data.slng), L.latLng(data.elat, data.elng))
  37. ).addTo(imageO);
  38. cloudImageNew.on("load", function (e) {
  39. if (meteo.f.radar.imgOverlay != null) {
  40. meteo.c.map.removeLayer(meteo.f.radar.imgOverlay);
  41. }
  42. meteo.f.radar.imgOverlay = layerid;
  43. });
  44. if (meteo.f.radar.title) {
  45. meteo.c.title.removeTitle(meteo.f.radar.title);
  46. }
  47. meteo.f.radar.title = '雷达图 ' + meteo.f.radar.data[meteo.f.radar.showIndex].time;
  48. meteo.c.title.addTitle(meteo.f.radar.title);
  49. },
  50. remove: function () {
  51. if (meteo.f.radar.imgOverlay != null) {
  52. meteo.f.radar.imgOverlay.remove();
  53. }
  54. title.removeTitle(meteo.f.radar.title);
  55. meteo.f.radar.imgOverlay = null;
  56. },
  57. play: function () { //云图动画
  58. if (meteo.f.radar.playId) {
  59. window.clearInterval(meteo.f.radar.playId);
  60. meteo.f.radar.playId = null;
  61. } else {
  62. meteo.f.radar.playId = window.setInterval(function () {
  63. meteo.f.radar.showIndex++;
  64. if (meteo.f.radar.showIndex == meteo.f.radar.data.length) {
  65. meteo.f.radar.showIndex = 0;
  66. }
  67. meteo.f.radar.show();
  68. }, 1000);
  69. }
  70. },
  71. init: function (b1, b2) {
  72. $(b1).click(function () {
  73. if (meteo.f.radar.imgOverlay) {
  74. if (meteo.f.radar.playId) {
  75. meteo.f.radar.play();
  76. }
  77. meteo.f.radar.remove();
  78. } else {
  79. meteo.f.radar.getData();
  80. }
  81. });
  82. $(b2).click(function () {
  83. if (meteo.f.radar.imgOverlay) {
  84. meteo.f.radar.play();
  85. }
  86. });
  87. }
  88. }
  89. return meteo.f.radar;
  90. })