surf.js 8.3 KB

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