aws.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //自动站数据
  2. define([], function () {
  3. var aws = {
  4. id: 'aws',
  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.aws, null, null, function (json) {
  15. aws.data = json;
  16. aws.showMarker();
  17. }, function () {
  18. aws.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. for (var key in latlngs) {
  25. if (!latlngs[key]) {
  26. return;
  27. }
  28. }
  29. var layerId = meteo.c.map.createLayer(); //新建图层展示marker
  30. aws.markerData = {}; //初始化数据存储对象
  31. var json = aws.data;
  32. var zoom = meteo.c.map.getZoom();
  33. var level = aws.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. var url = meteo.c.http.markerUrl + "airport_green.png";
  41. var content = null;
  42. var markerId = meteo.c.map.addMarker("", url, 16, 0, content, json[i].lat, json[i].lng, layerId);
  43. var name = json[i].cname ? json[i].cname : json[i].ename;
  44. aws.markerData[markerId] = json[i].station + " " + name; //根据merkerId记录marker所对应数据
  45. //添加点击事件 2D
  46. var marker = map2DViewer.markers[markerId];
  47. marker.on('click', function (e) {
  48. aws.showPopup(e.target.guid);
  49. });
  50. }
  51. //判断是否有重复图层,有则替换
  52. if (!aws.layer || !aws.layer.tLayer || aws.isHide) {
  53. meteo.c.map.removeLayer(layerId);
  54. return;
  55. }
  56. if (aws.layer.cLayer) {
  57. meteo.c.map.removeLayer(aws.layer.cLayer);
  58. }
  59. aws.layer.cLayer = layerId;
  60. aws.isLoad = false;
  61. },
  62. getLevel: function (zoom) { //根据地图缩放等级获取疏密等级
  63. var level = zoom < 5 ? 1000 :
  64. zoom < 6 ? 500 :
  65. zoom < 7 ? 250 :
  66. zoom < 8 ? 80 :
  67. zoom < 9 ? 40 :
  68. zoom < 10 ? 10 :
  69. zoom < 11 ? 2 : 1;
  70. return level;
  71. },
  72. showPopup: function (guid) { //固定位置弹窗
  73. var str = aws.markerData[guid];
  74. str = str.split(" ");
  75. if (str) {
  76. meteo.c.popup.showPopup(str[0], str[1], 3);
  77. }
  78. },
  79. create: function () {
  80. aws.layer = {
  81. tLayer: meteo.c.map.createLayer(),
  82. cLayer: null,
  83. }
  84. },
  85. remove: function () {
  86. if (aws.layer) {
  87. meteo.c.map.removeLayer(aws.layer.tLayer);
  88. meteo.c.map.removeLayer(aws.layer.cLayer);
  89. aws.layer = null;
  90. }
  91. },
  92. show: function () {
  93. aws.isHide = false;
  94. aws.showMarker();
  95. },
  96. hide: function () {
  97. aws.isHide = true;
  98. if (aws.layer) {
  99. meteo.c.map.removeLayer(aws.layer.cLayer);
  100. aws.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. // aws.isLoad = true;
  110. aws.isClose = false;
  111. aws.isHide = false;
  112. //----------------地图缩放等级小于5时提高到5(暂时使用系列)----------------------
  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 (aws.layer) {
  126. aws.remove();
  127. }
  128. aws.create();
  129. //----------------图层管理-------------------
  130. var options = {
  131. action: "add",
  132. // mod: "qixiang",
  133. DOM: {
  134. guid: aws.layer.tLayer,
  135. type: "group",
  136. name: '自动站',
  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 (aws.isLoad) {
  144. aws.isClose = true;
  145. return;
  146. }
  147. aws.close();
  148. break;
  149. case 'opacity':
  150. if (aws.isLoad) {
  151. if (option.options.opacity) {
  152. aws.isHide = false;
  153. } else {
  154. aws.isHide = true;
  155. }
  156. return;
  157. }
  158. if (option.options.opacity) {
  159. aws.show();
  160. } else {
  161. aws.hide();
  162. }
  163. break;
  164. }
  165. }, guid);
  166. //-------------------------------------
  167. $("#meteo-bt-aws").parent().addClass('current');
  168. aws.getData();
  169. if (aws.isInit) return;
  170. aws.isInit = true;
  171. //添加3D地图marker点击事件监听
  172. PubSub.subscribe('map3D.featureClick', function (msg, option) {
  173. aws.showPopup(option.feature.name);
  174. })
  175. //地图移动/缩放监听
  176. map2DViewer.map.on("moveend", function (e) {
  177. if (aws.layer && aws.layer.cLayer) {
  178. aws.showMarker();
  179. }
  180. });
  181. },
  182. close: function () {
  183. var options = {
  184. action: "remove",
  185. DOMid: aws.layer.tLayer,
  186. }
  187. ONEMAP.M.myLayers.myLayerControl(options);
  188. $("#meteo-bt-aws").parent().removeClass('current');
  189. meteo.c.popup.hidePopup();
  190. aws.remove();
  191. },
  192. update: function () { //用于时间变化时更新数据
  193. // aws.getData()
  194. },
  195. init: function () {
  196. $("#meteo-bt-aws").click(function () {
  197. if (aws.isLoad) return;
  198. if (aws.layer) {
  199. aws.close();
  200. } else {
  201. aws.open();
  202. }
  203. });
  204. }
  205. }
  206. meteo.f.aws = aws;
  207. return meteo.f.aws;
  208. })