amsu.js 7.1 KB

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