123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- /**
- * 本地等值线
- * Created by Administrator on 2017/11/9.
- */
- define(['meteoDir/other/smooth'], function (smooth) {
- var tt = {
- id: 'tt',
- title: '气温',
- legend: 'images/meteo/legend/tt.png',
- isInit: false,
- layer: null,
- data: null,
- elems: {
- 'TT': '气温',
- 'T2': '气温',
- },
- elem: 'TT',
- level: null,
- levelName: {
- '9999': '2米',
- '0925': '925hPa',
- '0850': '850hPa',
- '0700': '700hPa',
- '0500': '500hPa'
- },
- buttons: {
- '9999': null,
- '0925': null,
- '0850': null,
- '0700': null,
- '0500': null
- },
- isHide: false,
- getData: function () {
- var dateStr = meteo.c.time.getTime();
- // var dateStr = '2018-01-07 14:00:00';
- var vti = meteo.c.time.getVti();
- var params = {
- dateStr: dateStr,
- vti: vti,
- elem: tt.elem,
- level: tt.level
- }
- meteo.c.http.httpFunction(meteo.c.http.tImage, null, params, function (json) {
- meteo.c.title.updateTitle(tt.id,
- meteo.c.process.setTitleTime(json.odate, json.vti, tt.title, tt.levelName[tt.level]));
-
- $('#meteo-video-query-startDate').val(json.odate);
- json = json.data;
- json = JSON.parse(json);
- tt.data = json;
- tt.showTT(json);
- }, function () {
- // ONEMAP.C.publisher.publish({ type: 'warning', message: '气温暂无当前时次/层次数据' }, 'noteBar::add');
- // meteo.c.title.updateTitle(tt.id,'气温暂无当前时次/层次数据');
- })
- params.vti = parseInt(vti) + 3;
- meteo.c.http.httpFunction(meteo.c.http.tImage, null, params, function (json) {
- json = json.data;
- json = JSON.parse(json);
- tt.loadImage(json);
- }, function () {
- })
- // meteo.c.http.getLocalJson('799/T799_isoline_2017122420_000_T2_9999.json', function (json) {
- // tt.data = json;
- // tt.showTT(json);
- // })
- },
- showTT: function (data) {
- var images = [];
- var latI = (data.elat - data.slat) / data.row;
- var lngI = (data.elng - data.slng) / data.col;
- for (var i = 0; i < data.files.length; i++) {
- var value = data.files[i];
- if (value) {
- var str = value.split("\.")[0]; //去除后缀
- str = str.split("_"); //分割字符串,找出图片对应索引
- var x = str[0]; //lat索引(纬度
- var y = str[1]; //lng索引(经度
- var slat = data.slat + x * latI;
- var slng = data.slng + y * lngI;
- var elat = slat + latI;
- var elng = slng + lngI;
- elat = elat > data.elat ? data.elat : elat;
- elng = elng > data.elng ? data.elat : elng;
- var url = data.url + value + '.mkt';
- // var url = 'http://192.0.0.177/images/799/aa.png';
- images.push(meteo.c.map.addImage(url, slat, slng, elat, elng));
- // L.imageOverlay(
- // // 'http://107.1.170.193:8080/scripts/meteo/test/799/T799_2017122400_054_TR_9999_'
- // // + x + '_' + y +
- // // '.png.mkt',
- // data.url + value + '.mkt',
- // L.latLngBounds(L.latLng(slat, slng), L.latLng(elat, elng))
- // ).addTo(layer);
- }
- }
- if (!tt.layer|| !tt.layer.tLayer || tt.isHide) {
- for (var i = 0; i < images.length; i++) {
- meteo.c.map.removeImage(images[i]);
- }
- } else {
- if (tt.layer.images) {
- tt.removeImage();
- }
- tt.layer.images = images;
- }
- // setTimeout(function () {
- //
- // }, 300);
- },
- loadImage:function (data) { //预先加载图片
- for (var i = 0; i < data.files.length; i++) {
- var value = data.files[i];
- if (value) {
- var url = data.url + value + '.mkt';
- var img = $('<img />').attr('src', url);
- img = null;
- }
- }
- },
- showIsoLine: function (data) {
- var layerId = meteo.c.map.createLayer();
- var layer = map2DViewer.groups[layerId];
- var lines = data.lines;
- for (var index in lines) {
- var line = lines[index];
- // lineColor alpha b g r
- //标高低中心
- if (line.clat && line.clng && line.ctype) {
- var textAttr = tt.getText('TT', line.ctype);
- if (textAttr && textAttr.length == 2) {
- meteo.c.map.addText(textAttr[0], textAttr[0], 16, textAttr[1], 2, line.clat, line.clng, layerId)
- }
- }
- //找每条线的经纬点
- var latlngs = [];
- var isLegal = true;
- for (var i = 0; i < line.pointNum; i++) {
- latlngs.push([line.lng[i], line.lat[i]]);
- // latlngs.push([line.lat[i], line.lng[i]]);
- }
- //线条平滑
- // var smoothLatlngs = latlngs.length > 2 ? smooth(latlngs, 0.1, 0.24) : latlngs;
- // latlngs = (isLegal && smoothLatlngs.length > 1) ? smoothLatlngs : latlngs;
- //画线
- var lineColor = 'black';
- var textColor = 'black';
- if (line.lineColor && (line.lineColor.r == 0 || line.lineColor.r)
- && (line.lineColor.g == 0 || line.lineColor.g)
- && (line.lineColor.b == 0 || line.lineColor.b)) {
- lineColor = Color.rgb(line.lineColor.r, line.lineColor.g, line.lineColor.b, 255);
- textColor = 'rgb(' + line.lineColor.r + ', ' + line.lineColor.g + ', ' + line.lineColor.b + ')';
- }
- var weight = line.lineWidth ? line.lineWidth : 1;
- meteo.c.map.addPolyline('', lineColor, weight, null, latlngs, layerId, true);
- // var li = L.polyline(latlngs, {
- // color: lineColor
- // });
- // li.addTo(layer);
- //标数字
- if (line.val) {
- if (!line.isClose) {
- meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
- latlngs[0][1], latlngs[0][0], layerId, true);
- meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
- latlngs[latlngs.length - 1][1], latlngs[latlngs.length - 1][0], layerId, true);
- } else {
- var index = (latlngs.length * 3 / 4) >> 0;
- meteo.c.map.addText(line.val, line.val, 16, textColor, 2,
- latlngs[index][1], latlngs[index][0], layerId, true);
- }
- }
- }
- // if (!tt.layer || !tt.layer.tLayer || tt.isHide) {
- // meteo.c.map.removeLayer(layerId);
- // return;
- // }
- if (tt.layer.cLayer) {
- meteo.c.map.removeLayer(tt.layer.cLayer);
- }
- tt.layer.cLayer = layerId;
- },
- getText: function (elem, type) {
- var textAttr = [];
- if ("TT" == elem) {
- if ("L" == type) {
- textAttr.push("冷");
- textAttr.push("blue");
- } else if ("H" == type) {
- textAttr.push("暖");
- textAttr.push("red");
- }
- } else if ("HH" == elem || "PR" == elem) {
- if ("L" == type) {
- textAttr.push("低");
- textAttr.push("red");
- } else if ("H" == type) {
- textAttr.push("高");
- textAttr.push("blue");
- }
- }
- return textAttr;
- },
- create: function () {
- tt.layer = {
- tLayer: meteo.c.map.createLayer(),
- // cLayer: null,
- images: null,
- }
- },
- remove: function () {
- if (tt.layer) {
- meteo.c.map.removeLayer(tt.layer.tLayer);
- // meteo.c.map.removeLayer(tt.layer.cLayer);
- tt.removeImage();
- tt.layer = null;
- }
- },
- removeImage: function () {
- if (tt.layer.images) {
- for (var i = 0; i < tt.layer.images.length; i++) {
- meteo.c.map.removeImage(tt.layer.images[i]);
- }
- tt.layer.images = null;
- }
- },
- show: function () {
- tt.isHide = false;
- tt.showTT(tt.data);
- },
- hide: function () {
- tt.isHide = true;
- if (tt.layer) {
- tt.removeImage();
- // meteo.c.map.removeLayer(tt.layer.cLayer);
- // tt.layer.cLayer = null;
- }
- },
- open: function (elem, hpa) {
- if(ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
- ONEMAP.C.publisher.publish({ type: 'warning', message: '图层数量已达上限' }, 'noteBar::add');
- return;
- }
- //-------------创建图层------------------
- if (tt.layer) {
- tt.remove();
- }
- tt.create();
- //----------------图层管理-------------------
- var options = {
- action: "add",
- // mod: "qixiang",
- DOM: {
- guid: tt.layer.tLayer,
- type: "group",
- name: tt.title,
- },
- }
- var guid = ONEMAP.M.myLayers.myLayerControl(options);
- ONEMAP.C.publisher.subscribe(function (option) {
- switch (option.action) {
- case 'remove':
- tt.close();
- break;
- case 'opacity':
- if (option.options.opacity) {
- tt.show();
- } else {
- tt.hide();
- }
- break;
- }
- }, guid);
- //-------------------------------------
- tt.buttons[tt.level].parent().addClass('current');
- meteo.c.title.addTitle(tt.id);
- meteo.c.legend.addLegend(tt.id, tt.legend);
- meteo.c.time.open();
- tt.isHide = false;
- tt.getData(elem, hpa);
- },
- close: function () {
- var options = {
- action: "remove",
- DOMid: tt.layer.tLayer,
- }
- ONEMAP.M.myLayers.myLayerControl(options);
-
- tt.buttons[tt.level].parent().removeClass('current');
- meteo.c.title.removeTitle(tt.id);
- meteo.c.legend.removeLegend(tt.id);
- meteo.c.time.close();
- tt.level = null;
- tt.isHide = false;
- tt.remove();
- },
- update: function () { //用于时间变化时更新数据
- if (!tt.layer || tt.isHide) return;
- // var option = {
- // action: 'update',
- // DOMid: tt.layer.tLayer,
- // DOM: {
- // name: '气温' + meteo.c.time.getTimeOnTitle()
- // }
- // }
- // ONEMAP.M.myLayers.myLayerControl(option);
- tt.getData();
- },
- updateLevel: function () {
- tt.buttons[tt.level].parent().siblings().removeClass('current');
- tt.buttons[tt.level].parent().addClass('current');
- tt.getData();
- },
- click: function (level) {
- if (tt.level && level != tt.level) {
- tt.level = level;
- tt.updateLevel();
- } else {
- tt.level = level;
- if (tt.layer) {
- tt.close();
- } else {
- tt.open();
- }
- }
- },
- init: function () {
- var buttons = $('.meteo-button-799');
- tt.buttons['9999'] = buttons.eq(0);
- tt.buttons['0925'] = buttons.eq(1);
- tt.buttons['0850'] = buttons.eq(2);
- tt.buttons['0700'] = buttons.eq(3);
- tt.buttons['0500'] = buttons.eq(4);
- }
- }
- meteo.f.tt = tt;
- return meteo.f.tt;
- })
|