ship.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. //船舶报数据
  2. define([], function () {
  3. var ship = {
  4. id: 'ship',
  5. title: '船舶报',
  6. popupTo2d: null,
  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.ship, null, null, function (json) {
  16. ship.data = json;
  17. ship.showMarker();
  18. }, function () {
  19. ship.isLoad = false;
  20. ONEMAP.C.publisher.publish({ type: 'warning', message: '船舶报暂无数据' }, 'noteBar::add');
  21. })
  22. },
  23. showMarker: function () {
  24. var layerId = meteo.c.map.createLayer(); //新建图层展示marker
  25. ship.markerData = {}; //初始化数据存储对象
  26. var json = ship.data;
  27. var latlngs = meteo.c.map.getBounds();
  28. var zoom = meteo.c.map.getZoom();
  29. var level = ship.getLevel(zoom);
  30. for (var i = 0; i < json.length; i += level) {
  31. if (zoom < 4) break;
  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 == 0 || json[i].wth) && 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 content = null;
  40. var markerId = meteo.c.map.addMarker("", url, 26, 0, content, json[i].lat, json[i].lng, layerId);
  41. map23DData.markers[markerId].station = json[i].station;
  42. ship.markerData[markerId] = json[i].station; //根据merkerId记录marker所对应数据
  43. //添加点击事件 2D
  44. var marker = map2DViewer.markers[markerId];
  45. marker.on('click', function (e) {
  46. ship.showPopup(e);
  47. });
  48. }
  49. }
  50. //判断是否有重复图层,有则替换
  51. if (!ship.layer || !ship.layer.tLayer || ship.isHide) {
  52. meteo.c.map.removeLayer(layerId);
  53. }
  54. if (ship.layer.cLayer) {
  55. meteo.c.map.removeLayer(ship.layer.cLayer);
  56. }
  57. ship.layer.cLayer = layerId;
  58. ship.isLoad = false;
  59. },
  60. getLevel: function (zoom) { //根据地图缩放等级获取风羽疏密等级
  61. var level = zoom < 3 ? 5 :
  62. zoom < 5 ? 3 :
  63. zoom < 6 ? 2 : 1;
  64. return level;
  65. },
  66. getPopup : function () {
  67. },
  68. showPopup: function (e) { //固定位置弹窗
  69. var station = ship.markerData[e.target.guid];
  70. if (station) {
  71. meteo.c.http.httpFunction(meteo.c.http.shipInfo, station, null, function (json) {
  72. var content = "<div class='popup_html'>"
  73. + "<div class='popup-lt'></div>"
  74. + "<div class='popup-lb'></div>"
  75. + "<div class='popup-rt'></div>"
  76. + "<div class='popup-rb'></div>"
  77. + "<div class='popup-ct'>"
  78. + "<div class='meteo-menu-top meteo-menu-top-airport'>"
  79. + "<h3 class='meteo-title meteo-title-airport'>" + station + "</h3>"
  80. + "</div>"
  81. + "</div>"
  82. + "<div class='popup-cb' style='padding-bottom:20px;'>"
  83. + "<div class='meteo-popup-airport-warp content_scroll'>"
  84. + "<ul class='meteo-popup-airportUl'>"
  85. + "<li><h4 class='meteo-popup-airpory-h4'>----天气实况----</h4></li>"
  86. // + "<li class='meteo-popup-airport-li'><span>观测时间:</span><span>" + meteo.c.process.setDate(json.ldate, "") + "</span></li>"
  87. + "<li class='meteo-popup-airport-li'><span>观测时间:</span><span>" + meteo.c.process.setData(json.ldate, "") + "</span></li>"
  88. + "<li class='meteo-popup-airport-li'><span>天气现象:</span><span>" + meteo.c.process.setWth(json.wth) + "</span></li>"
  89. + "<li class='meteo-popup-airport-li'><span>气温:</span><span>" + meteo.c.process.setTt(json.tt) + "</span></li>"
  90. + "<li class='meteo-popup-airport-li'><span>气压:</span><span>" + meteo.c.process.setPr(json.pr) + "</span></li>"
  91. + "<li class='meteo-popup-airport-li'><span>能见度:</span><span>" + meteo.c.process.setVis(json.vis) + "</span></li>"
  92. + "<li class='meteo-popup-airport-li'><span>云:</span><span>" + "--" + "</span></li>"
  93. + "<li class='meteo-popup-airport-li'><span>风:</span><span>" + meteo.c.process.setWd(json.wd) + " " +
  94. meteo.c.process.setWs(json.ws) + "</span></li>"
  95. + "</ul>"
  96. + "</div>";
  97. + "</div>";
  98. ship.popupTo2d = L.popup().setLatLng(e.latlng)
  99. .setContent(content)
  100. .openOn(map2DViewer.map)
  101. })
  102. }
  103. },
  104. showPopup3d: function (options) { //固定位置弹窗
  105. var marker = map23DData.markers[options.feature.name];
  106. var station = marker.station;
  107. if (station) {
  108. meteo.c.http.httpFunction(meteo.c.http.shipInfo, station, null, function (json) {
  109. var content = "<div class='popup_html TD'>"
  110. + "<div class='popup-lt'></div>"
  111. + "<div class='popup-lb'></div>"
  112. + "<div class='popup-rt'></div>"
  113. + "<div class='popup-rb'></div>"
  114. + "<div class='popup-ct'>"
  115. + "<div class='meteo-menu-top meteo-menu-top-airport'>"
  116. + "<h3 class='meteo-title meteo-title-airport'>" + station + "</h3>"
  117. + "</div>"
  118. + "</div>"
  119. + "<div class='popup-cb' style='padding-bottom:20px;'>"
  120. + "<div class='meteo-popup-airport-warp content_scroll'>"
  121. + "<ul class='meteo-popup-airportUl'>"
  122. + "<li><h4 class='meteo-popup-airpory-h4'>----天气实况----</h4></li>"
  123. // + "<li class='meteo-popup-airport-li'><span>观测时间:</span><span>" + meteo.c.process.setDate(json.ldate, "") + "</span></li>"
  124. + "<li class='meteo-popup-airport-li'><span>观测时间:</span><span>" + meteo.c.process.setData(json.ldate, "") + "</span></li>"
  125. + "<li class='meteo-popup-airport-li'><span>天气现象:</span><span>" + meteo.c.process.setWth(json.wth) + "</span></li>"
  126. + "<li class='meteo-popup-airport-li'><span>气温:</span><span>" + meteo.c.process.setTt(json.tt) + "</span></li>"
  127. + "<li class='meteo-popup-airport-li'><span>气压:</span><span>" + meteo.c.process.setPr(json.pr) + "</span></li>"
  128. + "<li class='meteo-popup-airport-li'><span>能见度:</span><span>" + meteo.c.process.setVis(json.vis) + "</span></li>"
  129. + "<li class='meteo-popup-airport-li'><span>云:</span><span>" + "--" + "</span></li>"
  130. + "<li class='meteo-popup-airport-li'><span>风:</span><span>" + meteo.c.process.setWd(json.wd) + " " +
  131. meteo.c.process.setWs(json.ws) + "</span></li>"
  132. + "</ul>"
  133. + "</div>";
  134. + "</div>";
  135. map3DViewer.showPopup({
  136. x: options.evt.X,
  137. y: options.evt.Y,
  138. width: 150,//容器宽
  139. height: 200,//容器高
  140. content: content //冒泡窗内容
  141. })
  142. })
  143. }
  144. },
  145. create: function () {
  146. ship.layer = {
  147. tLayer: meteo.c.map.createLayer(),
  148. cLayer: null,
  149. }
  150. },
  151. remove: function () {
  152. if (ship.layer) {
  153. meteo.c.map.removeLayer(ship.layer.tLayer);
  154. meteo.c.map.removeLayer(ship.layer.cLayer);
  155. ship.layer = null;
  156. }
  157. },
  158. show: function () {
  159. ship.isHide = false;
  160. ship.showMarker();
  161. },
  162. hide: function () {
  163. ship.isHide = true;
  164. if (ship.layer) {
  165. meteo.c.map.removeLayer(ship.layer.cLayer);
  166. ship.layer.cLayer = null;
  167. if (ship.popupTo2d) { //2d弹窗存在时关闭
  168. ship.popupTo2d.remove();
  169. }
  170. }
  171. },
  172. open: function () {
  173. if(ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
  174. ONEMAP.C.publisher.publish({ type: 'warning', message: '图层数量已达上限' }, 'noteBar::add');
  175. return;
  176. }
  177. // ship.isLoad = true;
  178. ship.isClose = false;
  179. ship.isHide = false;
  180. //----------------地图缩放等级小于4时提高到4(暂时使用系列)----------------------
  181. if (meteo.c.map.getZoom() < 4) {
  182. if(map23DData.display.map2D){
  183. map2DViewer.setView({
  184. zoom: 4
  185. })
  186. }else{
  187. map3DViewer.setView({
  188. distance: 5000000
  189. })
  190. }
  191. }
  192. //-------------创建图层------------------
  193. if (ship.layer) {
  194. ship.remove();
  195. }
  196. ship.create();
  197. //----------------图层管理-------------------
  198. var options = {
  199. action: "add",
  200. // mod: "qixiang",
  201. DOM: {
  202. guid: ship.layer.tLayer,
  203. type: "group",
  204. name: '船舶报',
  205. },
  206. }
  207. var guid = ONEMAP.M.myLayers.myLayerControl(options);
  208. ONEMAP.C.publisher.subscribe(function (option) {
  209. switch (option.action) {
  210. case 'remove':
  211. if (ship.isLoad) {
  212. ship.isClose = true;
  213. return;
  214. }
  215. ship.close();
  216. break;
  217. case 'opacity':
  218. if (ship.isLoad) {
  219. if (option.options.opacity) {
  220. ship.isHide = false;
  221. } else {
  222. ship.isHide = true;
  223. }
  224. return;
  225. }
  226. if (option.options.opacity) {
  227. ship.show();
  228. } else {
  229. ship.hide();
  230. }
  231. break;
  232. }
  233. }, guid);
  234. //-------------------------------------
  235. $("#meteo-bt-ship").parent().addClass('current');
  236. ship.getData();
  237. if (ship.isInit) return;
  238. ship.isInit = true;
  239. //添加3D地图marker点击事件监听
  240. // PubSub.subscribe('map3D.featureClick', function (msg, option) {
  241. // ship.showPopup(option.feature.name);
  242. // })
  243. //地图移动/缩放监听
  244. map2DViewer.map.on("moveend", function (e) {
  245. if (ship.layer && ship.layer.cLayer) {
  246. ship.showMarker();
  247. }
  248. });
  249. },
  250. close: function () {
  251. var options = {
  252. action: "remove",
  253. DOMid: ship.layer.tLayer,
  254. }
  255. ONEMAP.M.myLayers.myLayerControl(options);
  256. if (ship.popupTo2d) { //2d弹窗存在时关闭
  257. ship.popupTo2d.remove();
  258. }
  259. $("#meteo-bt-ship").parent().removeClass('current');
  260. ship.remove();
  261. },
  262. update: function () { //用于时间变化时更新数据
  263. // ship.getData()
  264. },
  265. init: function () {
  266. $("#meteo-bt-ship").click(function () {
  267. if (ship.isLoad) return;
  268. if (ship.layer) {
  269. ship.close();
  270. } else {
  271. ship.open();
  272. }
  273. });
  274. //添加3D地图marker点击事件监听
  275. PubSub.subscribe('map3D.featureClick', function (msg, option) {
  276. ship.showPopup3d(option);
  277. })
  278. }
  279. }
  280. meteo.f.ship = ship;
  281. return meteo.f.ship;
  282. })