123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- /**
- * 本地等值线
- * Created by Administrator on 2017/11/9.
- */
- define(['meteoDir/other/smooth'], function (smooth) {
- meteo.f.isoLine = {
- isInit: false,
- layers: {},
- data: {},
- elems: {
- 'PR': '气压',
- 'T2': '温度'
- },
- getData: function (elem , level) {
- var params = {
- elem: elem,
- datastr: '',
- level: level
- }
- meteo.c.http.httpFunction(meteo.c.http.tIsoLine, null, params, function (json) {
- meteo.f.isoLine.data[elem] = json;
- meteo.f.isoLine.showLine(params, json);
- })
- // meteo.c.http.getLocalJson('799/T799_isoline_2017122400_000_T2_9999.json', function (json) {
- // meteo.f.isoLine.showLine(params, json);
- // })
- },
- showLine: function (params, data) {
- // var layerId = meteo.c.map.createLayer();
- var elem = params.elem;
- if (meteo.f.isoLine.layers[elem]) {
- meteo.c.map.clearLayer(meteo.f.isoLine.layers[elem])
- } else {
- meteo.f.isoLine.layers[elem] = meteo.c.map.createLayer();
- }
- var layerId = meteo.f.isoLine.layers[elem];
- 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 = meteo.f.isoLine.getText(elem, line.ctype);
- if (textAttr && textAttr.length == 2) {
- meteo.c.map.addText('', 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 + ')';
- }
- meteo.c.map.addPolyline('', lineColor, 2, null, latlngs, layerId);
- // var li = L.polyline(latlngs, {
- // color: lineColor
- // });
- // li.addTo(layer);
- //标数字
- // if ((line.val - meteo.f.isoLineLocal.data[type].labelBaseVal) % meteo.f.isoLineLocal.data[type].labelInterVal == 0) {
- if (line.val) {
- if (!line.isClose) {
- meteo.c.map.addText('', line.val, 16, textColor, 2, latlngs[0][1], latlngs[0][0], layerId);
- meteo.c.map.addText('', line.val, 16, textColor, 2, latlngs[latlngs.length - 1][1], latlngs[latlngs.length - 1][0], layerId);
- } else {
- var index = (latlngs.length * 3 / 4) >> 0;
- meteo.c.map.addText('', line.val, 16, textColor, 2, latlngs[index][1], latlngs[index][0], layerId);
- }
- }
- }
- // if (meteo.f.isoLine.layers[elem]) { //判断
- // meteo.c.map.removeLayer(meteo.f.isoLine.layers[elem]);
- // }
- // meteo.f.isoLine.layers[elem] = layerId;
- // if (meteo.f.isoLine.titles[elem]) {
- // meteo.f.isoLine.removeTitle(elem);
- // }
- // meteo.f.isoLine.addTitle(elem, hpa);
- //-----------------------------------
- var options = {
- action: "add",
- DOM: {
- guid: meteo.f.isoLine.layers[elem],
- type: "group",
- name: meteo.f.isoLine.elems[elem],
- },
- }
- var guid = ONEMAP.M.myLayers.myLayerControl(options);
- ONEMAP.C.publisher.subscribe(function (option) {
- if (option.action == 'remove') {
- meteo.f.isoLine.removeIsoLine(elem);
- if (elem == 'T2') {
- $("#meteo-bt-tt").parent().removeClass('current');
- } else {
- $("#meteo-bt-pr").parent().removeClass('current');
- }
- }
- }, guid);
- //-------------------------------------
- },
- 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;
- },
- removeIsoLine: function (elem) {
- var options = {
- action: "remove",
- DOMid:meteo.f.isoLine.layers[elem],
- }
- ONEMAP.M.myLayers.myLayerControl(options);
- if (meteo.f.isoLine.layers[elem]) {
- meteo.c.map.removeLayer(meteo.f.isoLine.layers[elem]);
- meteo.f.isoLine.layers[elem] = null;
- }
- // meteo.f.isoLine.removeTitle(elem);
- },
- removeAllIsoLine: function () {
- for (var elem in meteo.f.isoLineLocal.layers) {
- meteo.f.isoLine.removeIsoLine(elem);
- }
- },
- // addTitle: function (elem, hpa) {
- // var ti = elem + " " + hpa;
- // meteo.f.isoLine.titles[elem] = ti;
- // meteo.c.title.addTitle(ti);
- // },
- // removeTitle: function (elem) {
- // meteo.c.title.removeTitle(meteo.f.isoLine.titles[elem]);
- // },
- close: function () {
- meteo.f.isoLine.removeAllIsoLine();
- },
- init: function () {
- $("#meteo-bt-tt").click(function () { //温度
- if (!meteo.f.isoLine.layers['T2']) {
- meteo.f.isoLine.getData('T2', '9999')
- } else {
- meteo.f.isoLine.removeIsoLine('T2')
- }
- });
- $("#meteo-bt-pr").click(function () { //气压
- if (!meteo.f.isoLine.layers['PR']) {
- meteo.f.isoLine.getData("PR", '9999');
- } else {
- meteo.f.isoLine.removeIsoLine('PR')
- }
- });
- // $("#meteo-bt-rh").click(function () { //湿度
- // if (!meteo.f.isoLine.layers['RH']) {
- // meteo.f.isoLine.getData("RH", '0925');
- // } else {
- // meteo.f.isoLine.removeIsoLine('RH')
- // }
- // });
- }
- }
- return meteo.f.isoLine;
- })
|