123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- /**
- * 本地等值线
- * Created by Administrator on 2017/11/9.
- */
- define(['meteoDir/other/smooth'], function (smooth) {
- var pr = {
- id: 'pr',
- title: '气压',
- title2: '位势高度',
- legend: 'images/meteo/legend/pr.png',
- isInit: false,
- layer: null,
- data: null,
- elem: 'PR',
- elem2:'GH',
- level: null,
- levelName: {
- '9999': '海平面',
- '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 vti = meteo.c.time.getVti();
- var elem = pr.elem;
- if (pr.level != '9999') elem = pr.elem2;
- var params = {
- elem: elem,
- level: pr.level,
- dateStr: dateStr,
- vti: vti,
- }
- meteo.c.http.httpFunction(meteo.c.http.tIsoLine, null, params, function (json) {
- pr.data = json;
- var title = pr.title;
- if (pr.level != '9999') title = pr.title2;
- meteo.c.title.updateTitle(pr.id,
- meteo.c.process.setTitleTime(json.odate, json.vti, title, pr.levelName[pr.level]));
- $('#meteo-video-query-startDate').val(json.odate);
- pr.showPR(json);
- }, function () {
- // ONEMAP.C.publisher.publish({ type: 'warning', message: '海平面气压暂无当前时次/层次数据' }, 'noteBar::add');
- // meteo.c.title.updateTitle(pr.id,'海平面气压暂无当前时次/层次数据');
- })
- // meteo.c.http.getLocalJson('T799_isoline_2018010900_000_PR_9999.json', function (json) {
- // pr.data = json;
- // pr.showPR(json);
- // })
- },
- showPR: 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 = pr.getText('PR', line.ctype);
- if (textAttr && textAttr.length == 2) {
- meteo.c.map.addText(textAttr[0], textAttr[0], 16, textAttr[1], 2,
- line.clat, line.clng, layerId, true)
- }
- }
- //找每条线的经纬点
- 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 (!pr.layer || !pr.layer.tLayer || pr.isHide) {
- meteo.c.map.removeLayer(layerId);
- return;
- }
- if (pr.layer.cLayer) {
- meteo.c.map.removeLayer(pr.layer.cLayer);
- }
- pr.layer.cLayer = layerId;
- },
- getText: function (elem, type) {
- var textAttr = [];
- if ("L" == type) {
- textAttr.push("低");
- textAttr.push("red");
- } else if ("H" == type) {
- textAttr.push("高");
- textAttr.push("blue");
- }
- return textAttr;
- },
- create: function () {
- pr.layer = {
- tLayer: meteo.c.map.createLayer(),
- cLayer: null,
- }
- },
- remove: function () {
- if (pr.layer) {
- meteo.c.map.removeLayer(pr.layer.tLayer);
- meteo.c.map.removeLayer(pr.layer.cLayer);
- pr.layer = null;
- }
- },
- show: function () {
- pr.isHide = false;
- pr.showPR(pr.data);
- },
- hide: function () {
- pr.isHide = true;
- if (pr.layer) {
- meteo.c.map.removeLayer(pr.layer.cLayer);
- pr.layer.cLayer = null;
- }
- },
- open: function () {
- if(ONEMAP.M.myLayers.checkLength() >= map23DConfig.layerMaxLength) {
- ONEMAP.C.publisher.publish({ type: 'warning', message: '图层数量已达上限' }, 'noteBar::add');
- return;
- }
- //-------------创建图层------------------
- if (pr.layer) {
- pr.remove();
- }
- pr.create();
- //----------------图层管理-------------------
- var options = {
- action: "add",
- // mod: "qixiang",
- DOM: {
- guid: pr.layer.tLayer,
- type: "group",
- name: pr.title,
- },
- }
- var guid = ONEMAP.M.myLayers.myLayerControl(options);
- ONEMAP.C.publisher.subscribe(function (option) {
- switch (option.action) {
- case 'remove':
- pr.close();
- break;
- case 'opacity':
- if (option.options.opacity) {
- pr.show();
- } else {
- pr.hide();
- }
- break;
- }
- }, guid);
- //-------------------------------------
- pr.buttons[pr.level].parent().addClass('current');
- meteo.c.title.addTitle(pr.id);
- meteo.c.time.open();
- pr.getData();
- },
- close: function () {
- var options = {
- action: "remove",
- DOMid: pr.layer.tLayer,
- }
- ONEMAP.M.myLayers.myLayerControl(options);
- pr.buttons[pr.level].parent().removeClass('current');
- meteo.c.title.removeTitle(pr.id);
- meteo.c.time.close();
- pr.level = null;
- pr.remove();
- },
- update: function () { //用于时间变化时更新数据
- if (!pr.layer || pr.isHide) return;
- // var option = {
- // action: 'update',
- // DOMid: pr.layer.tLayer,
- // DOM: {
- // name: '气压' + meteo.c.time.getTimeOnTitle()
- // }
- // }
- // ONEMAP.M.myLayers.myLayerControl(option);
- pr.getData()
- },
- updateLevel: function () {
- pr.buttons[pr.level].parent().siblings().removeClass('current');
- pr.buttons[pr.level].parent().addClass('current');
- pr.getData()
- },
- click: function (level) { //点击相关按钮时调用
- if (pr.level && level != pr.level) {
- pr.level = level;
- pr.updateLevel();
- } else {
- pr.level = level;
- if (pr.layer) {
- pr.close()
- } else {
- pr.open();
- }
- }
- },
- init: function () {
- var buttons = $('.meteo-button-799');
- pr.buttons['9999'] = buttons.eq(5);
- pr.buttons['0925'] = buttons.eq(6);
- pr.buttons['0850'] = buttons.eq(7);
- pr.buttons['0700'] = buttons.eq(8);
- pr.buttons['0500'] = buttons.eq(9);
- }
- }
- meteo.f.pr = pr;
- return meteo.f.pr;
- })
|