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