//国内外5000地面站数据 define([], function () { var global = { id: 'global', title: '全球5000站', isInit: false, layer: null, data: null, markerData: {}, isLoad: false, isClose: false, isHide: false, getData: function () { meteo.c.http.httpFunction(meteo.c.http.stationG, null, null, function (json) { global.data = json; global.showMarker(); }, function () { global.isLoad = false; ONEMAP.C.publisher.publish({type: 'warning', message: '全球5000站无数据'}, 'noteBar::add'); }) }, showMarker: function () { var latlngs = meteo.c.map.getBounds(); for (var key in latlngs) { if (!latlngs[key]) { return; } } var json = global.data; var layerId = meteo.c.map.createLayer(); //新建图层展示marker global.markerData = {}; //初始化数据存储对象 var zoom = meteo.c.map.getZoom(); var level = global.getLevel(zoom); for (var i = 0; i < json.length; i += level) { if (zoom < 4) break; 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); global.markerData[markerId] = json[i].station + " " + json[i].city; //根据merkerId记录marker所对应数据 //添加点击事件 2D var marker = map2DViewer.markers[markerId]; marker.on('click', function (e) { global.showPopup(e.target.guid); }); } } //判断是否有重复图层,有则替换 if (!global.layer || !global.layer.tLayer || global.isHide) { meteo.c.map.removeLayer(layerId); return; } if (global.layer.cLayer) { meteo.c.map.removeLayer(global.layer.cLayer); } global.layer.cLayer = layerId; global.isLoad = false; }, getLevel: function (zoom) { //根据地图缩放等级获取风羽疏密等级 var level = zoom < 6 ? 10 : zoom < 7 ? 8 : zoom < 8 ? 6 : zoom < 9 ? 4 : zoom < 10 ? 2 : 1; return level; }, showPopup: function (guid) { //固定位置弹窗 var str = global.markerData[guid]; str = str.split(" "); if (str) { meteo.c.popup.showPopup(str[0], str[1], 1); } }, create: function () { global.layer = { tLayer: meteo.c.map.createLayer(), cLayer: null, } }, remove: function () { if (global.layer) { meteo.c.map.removeLayer(global.layer.tLayer); meteo.c.map.removeLayer(global.layer.cLayer); global.layer = null; } }, show: function () { global.isHide = false; global.showMarker(); }, hide: function () { global.isHide = true; if (global.layer) { meteo.c.map.removeLayer(global.layer.cLayer); global.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; } // global.isLoad = true; global.isClose = false; global.isHide = false; //----------------地图缩放等级小于4时提高到4(暂时使用系列)---------------------- if (meteo.c.map.getZoom() < 4) { if(map23DData.display.map2D){ map2DViewer.setView({ zoom: 4 }) }else{ map3DViewer.setView({ distance: 5000000 }) } } //-------------创建图层------------------ if (global.layer) { global.remove(); } global.create(); //----------------图层管理------------------- var options = { action: "add", // mod: "qixiang", DOM: { guid: global.layer.tLayer, type: "group", name: global.title, }, } var guid = ONEMAP.M.myLayers.myLayerControl(options); ONEMAP.C.publisher.subscribe(function (option) { switch (option.action) { case 'remove': if (global.isLoad) { global.isClose = true; return; } global.close(); break; case 'opacity': if (global.isLoad) { if (option.options.opacity) { global.isHide = false; } else { global.isHide = true; } return; } if (option.options.opacity) { global.show(); } else { global.hide(); } break; } }, guid); //------------------------------------- $("#meteo-bt-global").parent().addClass('current'); global.getData(); if (global.isInit) return; global.isInit = true; //添加3D地图marker点击事件监听 PubSub.subscribe('map3D.featureClick', function (msg, option) { global.showPopup(option.feature.name); }) //地图移动/缩放监听 // map2DViewer.map.on("moveend", function (e) { // if (global.layer && global.layer.cLayer) { // global.showMarker(); // } // }); }, close: function () { var options = { action: "remove", DOMid: global.layer.tLayer, } ONEMAP.M.myLayers.myLayerControl(options); $("#meteo-bt-global").parent().removeClass('current'); meteo.c.popup.hidePopup(); global.remove(); }, update: function () { //用于时间变化时更新数据 // global.getData() }, onMove: function () { if (global.layer && global.layer.cLayer) { global.showMarker(); } }, init: function () { $("#meteo-bt-global").click(function () { if (global.isLoad) return; if (global.layer) { global.close(); } else { global.open(); } }); } } meteo.f.global = global; return meteo.f.global; })