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