global.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //国内外5000地面站数据
  2. define([], function () {
  3. var global = {
  4. id: 'global',
  5. title: '全球5000站',
  6. isInit: false,
  7. layer: null,
  8. data: null,
  9. markerData: {},
  10. isLoad: false,
  11. isClose: false,
  12. isHide: false,
  13. getData: function () {
  14. meteo.c.http.httpFunction(meteo.c.http.stationG, null, null, function (json) {
  15. global.data = json;
  16. global.showMarker();
  17. }, function () {
  18. global.isLoad = false;
  19. ONEMAP.C.publisher.publish({type: 'warning', message: '全球5000站无数据'}, 'noteBar::add');
  20. })
  21. },
  22. showMarker: function () {
  23. var latlngs = meteo.c.map.getBounds();
  24. for (var key in latlngs) {
  25. if (!latlngs[key]) {
  26. return;
  27. }
  28. }
  29. var json = global.data;
  30. var layerId = meteo.c.map.createLayer(); //新建图层展示marker
  31. global.markerData = {}; //初始化数据存储对象
  32. var zoom = meteo.c.map.getZoom();
  33. var level = global.getLevel(zoom);
  34. for (var i = 0; i < json.length; i += level) {
  35. if (zoom < 4) break;
  36. if (json[i].lat < latlngs[0] || json[i].lat > latlngs[2]
  37. || json[i].lng < latlngs[1] || json[i].lng > latlngs[3]) {
  38. continue;
  39. }
  40. if (json[i].lat && json[i].lng && (json[i].wth || json[i].wth == 0) && json[i].wth < 99) { //有经纬度和天气状态
  41. var url = json[i].wth < 10 ? "0" + json[i].wth : json[i].wth;
  42. url = meteo.c.http.markerUrl + "weatherImage/cww" + url + ".png";
  43. var markerId = meteo.c.map.addMarker("", url, 26, 0, null, json[i].lat, json[i].lng, layerId);
  44. global.markerData[markerId] = json[i].station + " " + json[i].city; //根据merkerId记录marker所对应数据
  45. //添加点击事件 2D
  46. var marker = map2DViewer.markers[markerId];
  47. marker.on('click', function (e) {
  48. global.showPopup(e.target.guid);
  49. });
  50. }
  51. }
  52. //判断是否有重复图层,有则替换
  53. if (!global.layer || !global.layer.tLayer || global.isHide) {
  54. meteo.c.map.removeLayer(layerId);
  55. return;
  56. }
  57. if (global.layer.cLayer) {
  58. meteo.c.map.removeLayer(global.layer.cLayer);
  59. }
  60. global.layer.cLayer = layerId;
  61. global.isLoad = false;
  62. },
  63. getLevel: function (zoom) { //根据地图缩放等级获取风羽疏密等级
  64. var level =
  65. zoom < 6 ? 10 :
  66. zoom < 7 ? 8 :
  67. zoom < 8 ? 6 :
  68. zoom < 9 ? 4 :
  69. zoom < 10 ? 2 : 1;
  70. return level;
  71. },
  72. showPopup: function (guid) { //固定位置弹窗
  73. var str = global.markerData[guid];
  74. str = str.split(" ");
  75. if (str) {
  76. meteo.c.popup.showPopup(str[0], str[1], 1);
  77. }
  78. },
  79. create: function () {
  80. global.layer = {
  81. tLayer: meteo.c.map.createLayer(),
  82. cLayer: null,
  83. }
  84. },
  85. remove: function () {
  86. if (global.layer) {
  87. meteo.c.map.removeLayer(global.layer.tLayer);
  88. meteo.c.map.removeLayer(global.layer.cLayer);
  89. global.layer = null;
  90. }
  91. },
  92. show: function () {
  93. global.isHide = false;
  94. global.showMarker();
  95. },
  96. hide: function () {
  97. global.isHide = true;
  98. if (global.layer) {
  99. meteo.c.map.removeLayer(global.layer.cLayer);
  100. global.layer.cLayer = null;
  101. meteo.c.popup.hidePopup();
  102. }
  103. },
  104. open: function () {
  105. if (ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
  106. ONEMAP.C.publisher.publish({type: 'warning', message: '图层数量已达上限'}, 'noteBar::add');
  107. return;
  108. }
  109. // global.isLoad = true;
  110. global.isClose = false;
  111. global.isHide = false;
  112. //----------------地图缩放等级小于4时提高到4(暂时使用系列)----------------------
  113. if (meteo.c.map.getZoom() < 4) {
  114. if(map23DData.display.map2D){
  115. map2DViewer.setView({
  116. zoom: 4
  117. })
  118. }else{
  119. map3DViewer.setView({
  120. distance: 5000000
  121. })
  122. }
  123. }
  124. //-------------创建图层------------------
  125. if (global.layer) {
  126. global.remove();
  127. }
  128. global.create();
  129. //----------------图层管理-------------------
  130. var options = {
  131. action: "add",
  132. // mod: "qixiang",
  133. DOM: {
  134. guid: global.layer.tLayer,
  135. type: "group",
  136. name: global.title,
  137. },
  138. }
  139. var guid = ONEMAP.M.myLayers.myLayerControl(options);
  140. ONEMAP.C.publisher.subscribe(function (option) {
  141. switch (option.action) {
  142. case 'remove':
  143. if (global.isLoad) {
  144. global.isClose = true;
  145. return;
  146. }
  147. global.close();
  148. break;
  149. case 'opacity':
  150. if (global.isLoad) {
  151. if (option.options.opacity) {
  152. global.isHide = false;
  153. } else {
  154. global.isHide = true;
  155. }
  156. return;
  157. }
  158. if (option.options.opacity) {
  159. global.show();
  160. } else {
  161. global.hide();
  162. }
  163. break;
  164. }
  165. }, guid);
  166. //-------------------------------------
  167. $("#meteo-bt-global").parent().addClass('current');
  168. global.getData();
  169. if (global.isInit) return;
  170. global.isInit = true;
  171. //添加3D地图marker点击事件监听
  172. PubSub.subscribe('map3D.featureClick', function (msg, option) {
  173. global.showPopup(option.feature.name);
  174. })
  175. //地图移动/缩放监听
  176. // map2DViewer.map.on("moveend", function (e) {
  177. // if (global.layer && global.layer.cLayer) {
  178. // global.showMarker();
  179. // }
  180. // });
  181. },
  182. close: function () {
  183. var options = {
  184. action: "remove",
  185. DOMid: global.layer.tLayer,
  186. }
  187. ONEMAP.M.myLayers.myLayerControl(options);
  188. $("#meteo-bt-global").parent().removeClass('current');
  189. meteo.c.popup.hidePopup();
  190. global.remove();
  191. },
  192. update: function () { //用于时间变化时更新数据
  193. // global.getData()
  194. },
  195. onMove: function () {
  196. if (global.layer && global.layer.cLayer) {
  197. global.showMarker();
  198. }
  199. },
  200. init: function () {
  201. $("#meteo-bt-global").click(function () {
  202. if (global.isLoad) return;
  203. if (global.layer) {
  204. global.close();
  205. } else {
  206. global.open();
  207. }
  208. });
  209. }
  210. }
  211. meteo.f.global = global;
  212. return meteo.f.global;
  213. })