/**
* 机场单点数据(暂命名)
* Created by Administrator on 2017/11/7.
*/
define([], function () {
var airport = {
isInit: false,
map: null,
layer: null,
data: null,
startZoom: null,
isLoad: false,
isClose: false,
isHide: false,
getData: function () { //获取数据
meteo.c.http.httpFunction(meteo.c.http.airportIndex, null, null, function (json) {
airport.data = json;
airport.drawAllMarkerForLayerZoom();
}, function () {
airport.isLoad = false;
ONEMAP.C.publisher.publish({ type: 'warning', message: '民航报暂无数据' }, 'noteBar::add');
})
},
drawAirportMarker: function (lng, lat, station, cname) { //绘制单个marker点,同时给每个marker加入点击事件
var iconUrl = 'images/meteo/airport_brown.png';
// var iconUrl = airport.getIcon(sigmenttype);
var myIcon = L.icon({
iconUrl: iconUrl,
iconSize: [16, 16],
iconAnchor: [8, 8],
})
return L.marker([lng, lat], {icon: myIcon}).on('click', function (marker) {
meteo.c.http.httpFunction(meteo.c.http.airportInfo, station, null, function (json) {
var content = airport.getPopupContent(json, station, cname);
airport.popup.setLatLng(marker.latlng)
.setContent(content)
.openOn(map2DViewer.map);
})
});
},
getIcon: function (sigmenttype) { //获取icon图片
var url = airport.contains(sigmenttype, "RAIN") ? 'airport_green.png' :
airport.contains(sigmenttype, "SOOT") ? 'airport_brown.png' :
airport.contains(sigmenttype, "THUNDER") ? 'airport_red.png' :
airport.contains(sigmenttype, "SAND") ? 'airport_brown.png' :
airport.contains(sigmenttype, "STORM") ? 'airport_brown.png' :
airport.contains(sigmenttype, "CLOTTED GROUND") ? 'airport_green.png' :
airport.contains(sigmenttype, "PUFF SNOW") ? 'airport_green.png' :
airport.contains(sigmenttype, "FIRN SNOW") ? 'airport_green.png' :
airport.contains(sigmenttype, "SNOW") ? 'airport_green.png' :
airport.contains(sigmenttype, "FOG") ? 'airport_yellow.png' : 'airport_gray.png';
return meteo.c.http.myImageUrlJs + url;
},
getPopupContent: function (data, station, cname) {
var html = "
";
return html;
},
drawAllMarkerForLayerZoom: function () {
if (!airport.data) return;
var layerId = meteo.c.map.createLayer();
var layer = map2DViewer.groups[layerId];
var zoom = map2DViewer.map._zoom;
for (var i = 0; i < airport.data.length; i++) {
var data = airport.data[i];
if (zoom < 5 && data.level > 1) {
continue;
}
airport.drawAirportMarker(data.lng, data.lat, data.station, data.cname).addTo(layer);
}
if (!airport.layer || !airport.layer.tLayer || airport.isHide) {
meteo.c.map.removeLayer(layerId);
return;
}
if (airport.layer.cLayer) {
meteo.c.map.removeLayer(airport.layer.cLayer);
}
airport.layer.cLayer = layerId;
airport.isLoad = false;
},
create: function () {
airport.layer = {
tLayer: meteo.c.map.createLayer(),
cLayer: null,
}
},
remove: function () {
if (airport.layer) {
meteo.c.map.removeLayer(airport.layer.tLayer);
meteo.c.map.removeLayer(airport.layer.cLayer);
airport.layer = null;
}
},
show: function () {
airport.isHide = false;
airport.drawAllMarkerForLayerZoom();
},
hide: function () {
airport.isHide = true;
if (airport.layer) {
meteo.c.map.removeLayer(airport.layer.cLayer);
airport.layer.cLayer = null;
airport.popup.remove();//2d弹窗存在时关闭
}
},
open: function () {
if(ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
ONEMAP.C.publisher.publish({ type: 'warning', message: '图层数量已达上限' }, 'noteBar::add');
return;
}
airport.isLoad = true;
airport.isClose = false;
airport.isHide = false;
//-------------创建图层------------------
if (airport.layer) {
airport.remove();
}
airport.create();
//----------------图层管理-------------------
var options = {
action: "add",
// mod: "qixiang",
DOM: {
guid: airport.layer.tLayer,
type: "group",
name: '民航报',
},
}
var guid = ONEMAP.M.myLayers.myLayerControl(options);
ONEMAP.C.publisher.subscribe(function (option) {
switch (option.action) {
case 'remove':
if (airport.isLoad) {
airport.isClose = true;
return;
}
airport.close();
break;
case 'opacity':
if (airport.isLoad) {
if (option.options.opacity) {
airport.isHide = false;
} else {
airport.isHide = true;
}
return;
}
if (option.options.opacity) {
airport.show();
} else {
airport.hide();
}
break;
}
}, guid);
//-------------------------------------
$("#meteo-bt-airport").parent().addClass('current');
airport.getData();
if (airport.isInit) return;
airport.isInit = true;
//--------------------记录层级缩放开始,当变化到4/5级时重新绘制-----------------------
map2DViewer.map.on("zoomstart", function () {
if (!airport.layer) return;
airport.startZoom = map2DViewer.map._zoom;
})
map2DViewer.map.on("zoomend", function () {
if (!airport.layer || !airport.layer.cLayer) return;
if (airport.startZoom >= 5 && map2DViewer.map._zoom <= 4) {
airport.drawAllMarkerForLayerZoom();
}
if (airport.startZoom <= 4 && map2DViewer.map._zoom >= 5) {
airport.drawAllMarkerForLayerZoom();
}
})
},
close: function () {
var options = {
action: "remove",
DOMid: airport.layer.tLayer,
}
ONEMAP.M.myLayers.myLayerControl(options);
airport.popup.remove();//2d弹窗存在时关闭
$("#meteo-bt-airport").parent().removeClass('current');
airport.remove();
},
update: function () { //用于时间变化时更新数据
// airport.getData()
},
init: function () {
$("#meteo-bt-airport").click(function () {
if (airport.isLoad) return;
if (airport.layer) {
airport.close();
} else {
airport.open();
}
});
airport.popup = L.popup();
},
/**
* 判断str是否包含str2
*/
contains: function (str, str2) {
if (str.indexOf(str2) >= 0) {
return true;
}
return false;
},
//-----------------------一些显示数据的格式化方法---------------------
showInfoWindowDate: function (data, str) {
if (data != 0 && !data) {
return "-";
}
if (str) {
return ((data * 10) >> 0) / 10 + str;
} else {
return data;
}
},
showCloudData: function (cn1, ch1, cn2, ch2, cn3, ch3, str) {
if (cn1 && ch1) {
cn1 = cn1 + "/" + ch1 + str;
if (cn2 && ch2) {
cn1 = cn1 + "," + cn2 + "/" + ch2 + str;
}
if (cn3 && ch3) {
cn1 = cn1 + "," + cn3 + "/" + ch3 + str;
}
} else {
cn1 = "-"
}
return cn1
},
showWindData: function (wd, ws) {
if ((ws === 0 && wd) || (wd && ws)) {
return wd + "°" + ws + "米/秒"
}
return "";
},
showInfoWindowFactTime: function (odate, timeBg, timeEd) {
var start = timeBg;
if (timeBg == timeEd) {
start = odate;
}
if (!start || !timeEd) {
return "--";
}
return start.substring(8, 10) + "日" + start.substring(11, 13) + "时" + start.substring(14, 16) + "分-"
+ timeEd.substring(8, 10) + "日" + timeEd.substring(11, 13) + "时" + timeEd.substring(14, 16) + "分";
}
};
meteo.f.airport = airport;
return meteo.f.airport;
})