//地面站数据 define([], function () { var surf = { id: 'surf', title: '地面站', isInit: false, layer: null, data: null, markerData: {}, isLoad: false, isClose: false, isHide: false, getData: function () { meteo.c.http.httpFunction(meteo.c.http.stationInfo, null, null, function (json) { surf.data = json; surf.showMarker(); }, function () { surf.isLoad = false; ONEMAP.C.publisher.publish({ type: 'warning', message: '地面站暂无数据' }, 'noteBar::add'); }) }, showMarker: function () { var latlngs = meteo.c.map.getBounds(); var zoom = meteo.c.map.getZoom(); var layerId = meteo.c.map.createLayer(); //新建图层展示marker surf.markerData = {}; //初始化数据存储对象 var json = surf.data; for (var i = 0; i < json.length; i++) { if (zoom < 4) break; if (zoom < 8 && json[i].level > 1) continue; if (zoom < 9 && json[i].level > 2) continue; if (json[i].lat < latlngs[0] || json[i].lat > latlngs[2] || json[i].lng < latlngs[1] || json[i].lng > latlngs[3]) { continue; } if (json[i].lat && json[i].lng && (json[i].wth || json[i].wth == 0) && json[i].wth < 99) { //有经纬度和天气状态 var url = json[i].wth < 10 ? "0" + json[i].wth : json[i].wth; url = meteo.c.http.markerUrl + "weatherImage/cww" + url + ".png"; var markerId = meteo.c.map.addMarker("", url, 26, 0, null, json[i].lat, json[i].lng, layerId); var name = json[i].cname ? json[i].cname : json[i].ename; surf.markerData[markerId] = json[i].station + " " + name; //根据merkerId记录marker所对应数据 //添加点击事件 2D var marker = map2DViewer.markers[markerId]; marker.on('click', function (e) { surf.showPopup(e.target.guid); }); } } //判断是否有重复图层,有则替换 if (!surf.layer || !surf.layer.tLayer || surf.isHide){ meteo.c.map.removeLayer(layerId); return; } if (surf.layer.cLayer) { meteo.c.map.removeLayer(surf.layer.cLayer); } surf.layer.cLayer = layerId; surf.isLoad = false; }, showPopup: function (guid) { //固定位置弹窗 var str = surf.markerData[guid]; str = str.split(" "); if (str) { meteo.c.popup.showPopup(str[0], str[1], 0); } }, create: function () { surf.layer = { tLayer: meteo.c.map.createLayer(), cLayer: null, } }, remove: function () { if (surf.layer) { meteo.c.map.removeLayer(surf.layer.tLayer); meteo.c.map.removeLayer(surf.layer.cLayer); surf.layer = null; } }, show: function () { surf.isHide = false; surf.showMarker(); }, hide: function () { surf.isHide = true; if (surf.layer) { meteo.c.map.removeLayer(surf.layer.cLayer); surf.layer.cLayer = null; meteo.c.popup.hidePopup(); } }, open: function () { if (ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) { ONEMAP.C.publisher.publish({type: 'warning', message: '图层数量已达上限'}, 'noteBar::add'); return; } // surf.isLoad = true; surf.isClose = false; surf.isHide = false; //----------------地图缩放等级小于4时提高到4(暂时使用系列)---------------------- if (meteo.c.map.getZoom() < 4) { if(map23DData.display.map2D){ map2DViewer.setView({ zoom: 4 }) }else{ map3DViewer.setView({ distance: 5000000 }) } } //-------------创建图层------------------ if (surf.layer) { surf.remove(); } surf.create(); //----------------图层管理------------------- var options = { action: "add", // mod: "qixiang", DOM: { guid: surf.layer.tLayer, type: "group", name: '地面站', }, } var guid = ONEMAP.M.myLayers.myLayerControl(options); ONEMAP.C.publisher.subscribe(function (option) { switch (option.action) { case 'remove': if (surf.isLoad) { surf.isClose = true; return; } surf.close(); break; case 'opacity': if (surf.isLoad) { if (option.options.opacity) { surf.isHide = false; } else { surf.isHide = true; } return; } if (option.options.opacity) { surf.show(); } else { surf.hide(); } break; } }, guid); //------------------------------------- $("#meteo-bt-surf").parent().addClass('current'); $(".tools-toolWheather").addClass('cur'); surf.getData(); if (surf.isInit) return; surf.isInit = true; //添加3D地图marker点击事件监听 PubSub.subscribe('map3D.featureClick', function (msg, option) { surf.showPopup(option.feature.name); }) //地图移动/缩放监听 // map2DViewer.map.on("moveend", function (e) { // if (surf.layer && surf.layer.cLayer) { // surf.showMarker(); // } // }); }, close: function () { var options = { action: "remove", DOMid: surf.layer.tLayer, } ONEMAP.M.myLayers.myLayerControl(options); $("#meteo-bt-surf").parent().removeClass('current'); $(".tools-toolWheather").removeClass('cur'); meteo.c.popup.hidePopup(); surf.remove(); }, update: function () { //用于时间变化时更新数据 // surf.getData() }, onMove: function () { if (surf.layer && surf.layer.cLayer) { surf.showMarker(); } }, init: function () { $("#meteo-bt-surf").click(function () { if (surf.isLoad) return; if (meteo.f.surf.layer) { meteo.f.surf.close(); } else { meteo.f.surf.open(); } }); // $("#meteo-bt-sc-surf").click(function () { // if (meteo.f.surf.layer) { // meteo.f.surf.close(); // } else { // meteo.f.surf.open(); // } // return false; // }); $(".tools-toolWheather").click(function () { if (surf.isLoad) return; if (meteo.f.surf.layer) { meteo.f.surf.close(); } else { meteo.f.surf.open(); } return false; }); } } meteo.f.surf = surf; return meteo.f.surf; })