首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >前端编程-大气模拟计算之周边排放源影响

前端编程-大气模拟计算之周边排放源影响

原创
作者头像
MiaoGIS
发布于 2021-12-16 03:31:19
发布于 2021-12-16 03:31:19
47300
代码可运行
举报
文章被收录于专栏:Python in AI-IOTPython in AI-IOT
运行总次数:0
代码可运行

本文介绍一下某数值模型计算空气监测站周边工业排放源对其某污染因子浓度的影响程度(贡献度)的前端页面设计。

前端html代码如下:

代码语言:html
AI代码解释
复制
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <title></title>
    <!-- CSS only -->
    <link href="/static/lib/bootstrap-5.1.3-dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .tableDiv {

            height: 600px;
            overflow: scroll;
        }

        [data-role="toolbar"] {
            text-align: center;
        }

        #map {
            min-height: 800px;
            
        }
        
        #bar {
            min-height: 450px;
        }

        thead {
            border-width: 1px 1px;
            background: #00BC80;
            /*            background: #BAD3F2;*/
        }

        th,
        td {
            text-align: center;
            vertical-align: middle;

        }
        #contributeDiv{
            max-height: 350px;
        }
        th.name,td.name{
            max-width: 250px;
        }         
        
    </style>
   
    <script type="text/template" id="contributeTableTemplate">
    <table class="table caption-top">
    <caption><%=title%></caption>
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col" class='name'>企业名称</th>
      <th scope="col">方位</th>
      <th scope="col">距离</th>
      <th scope="col">贡献率</th>
    </tr>
  </thead>
  <tbody>
  <%_.each(data,function(item,index){ %>
    <tr>
      <th scope="row"><%=index+1%></th>
      <td><%=item['name']%></td>
      <td><%=item['direction']%></td>
      <td><%=item['distance']%>公里</td>
      <td><%=(item['value']*100).toFixed(1)%>%</td>
    </tr>
    <%});%>
  </tbody>
</table>
    </script>
    
    <script type="text/template" id="optionsTemplate">
        <% _.each(rows,function(item){ %>
         <% var stations=item['stations'] %>
           <optgroup label="<%=item['name']%>">
            <% _.each(stations,function(station){ %>
                       
                        <option value="<%=station['code']%>"><%=station['name']%></option>
             <% }) %>     
               </optgroup>    
                               
          <% }) %>
      </script>
</head>

<body>
    <div class="container-fluid">
        <div class="row g-3" data-role="toolbar" data-menu="aqi-contribute-sources" style="display: none;">
            <div class="col-1 right">
                <label for="option_date" class="form-label">起报时间:</label>
            </div>
            <div class="col-2">
                <input type="date" id="option_date" class="form-control" aria-label="Default select example">

            </div>

            <div class="col-1 right">
                <label for="option_station" class="form-label">站点</label>
            </div>
            <div class="col-2">
                <select id="option_station" class="form-select " aria-label="Default select example">
                 
                </select>
            </div>
             
            <div class="col-1 right">
                <label for="option_factor" class="form-label">污染因子</label>
            </div>
            <div class="col-1">
                <select id="option_factor" class="form-select " aria-label="Default select example">
                     
                    <option value="PM10_24h">PM<sub>10</sub></option>
                    <option value="PM25_24h">PM<sub>2.5</sub></option>
                    <option value="SO2_24h">SO<sub>2</sub></option>
                    <option value="NO2_24h">NO<sub>2</sub></option>
                    <option value="CO_24h">CO</option>
                    <option value="O3_8h">O<sub>3</sub></option>

                </select>
            </div>

            <div class="col-1 right">
                <label for="option_date2" class="form-label">预报时间</label>
            </div>
            <div class="col-2">
                <input id="option_date2" type="date" class="form-control">
            </div>

            <div class="col-1">
                <button type="submit" class="btn btn-primary mb-3" id="option_submit">查询</button>
            </div>
        </div>
        <div class="row justify-content-start">
            <div class="col-7">
                    <div id="map"></div>
            </div>
            <div class="col-5">
                 <div class="row">
                    <div id="bar"></div>
                </div>
                <div class="row">
                    <div id="contributeDiv" class="table-responsive "></div>
                </div>
                 
            </div>

        </div>
         
    </div>
    <script src="/static/lib/jquery/jquery-1.11.3.js"></script>
    <script src="/static/lib/underscore/underscore.js"></script>
    <script src="/static/lib/bootstrap-5.1.3-dist/js/bootstrap.min.js"></script>
    <script src="/static/lib/daterangepicker/daterangepicker.js"></script>
    <script src="/static/lib/moment/moment.min.js"></script>
    <script src="/static/lib/moment/zh-cn.js"></script>
    <script src="/static/lib/chartjs/chart.min.js"></script>
    <script src="/static/lib/echarts/echarts.min.js"></script>
    <script src="/static/lib/d3/d3.v5.min.js"></script>
    <script src='/static/lib/turf/turf.min.js'></script>
    
    <script src="/static/js/base.js"></script>
    <script src="/static/js/aqi-contribute-pollutes.js"></script>
</body></html>

除了引用公共的base.js文件,前端JavaScript代码aqi-contribute-pollutes.js如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$(function () {
    var radios = [0.01, 0.02, 0.05, 0.10, 0.20, 0.30];
    getRegions().then(function () {
        var template = _.template($('#optionsTemplate').html());
        var html = template({
            rows: citys
        });

        $('#option_station').html(html);
    })

    function initMap(data, station) {

        var points = data.map(x => x.position.concat([x.value, x.name]));
        var lines = data.map(x => {
            var colorIndex = _.sortedIndex(radios, x.value);
            var color = levelColors[colorIndex];

            return {
                coords: [x.position, [station.lng, station.lat]],
                lineStyle: {
                    color: color,
                }
            }
        })

        var pointsAll = points.concat([[station.lng, station.lat]]);

        var chartDom = document.getElementById('map');
        var myChart = echarts.init(chartDom);

        option = {
            toolbox: {
                feature: {
                    restore: {},
                    saveAsImage: {}
                }
            },
            //        backgroundColor: '#013954',
            title: {
                top: 20,
                text: `(${station['name']})周边企业影响`,
                subtext: $('#contributeDiv caption').text(),
                x: 'center',
                textStyle: {
                    color: '#fff'
                },
                subtextStyle: {
                    color: '#fff'
                },
            },

            tooltip: {
                trigger: 'item',
                showDelay: 0,
                hideDelay: 0,
                enterable: false,
                transitionDuration: 0,

                formatter: function (params, ticket, callback) {

                    if (params.seriesIndex == 0) {

                        var res = "";
                        var name = params.value[3];
                        var value = params.value[2];
                        res = "<span style='color:#000;'>" + name + "<br/>贡献率:" + (value * 100).toFixed(1) + '%' + "</span>";
                        return res;
                    } else {
                        return false;
                    }

                }
            },

            geo: {
                boundingCoords: [

                    [Math.min(...pointsAll.map(x => x[0])) - 0.05, Math.min(...pointsAll.map(x => x[1])) - 0.05],

                    [Math.max(...pointsAll.map(x => x[0])) + 0.05, Math.max(...pointsAll.map(x => x[1])) + 0.05]
                ],
                map: 'henan',
                aspectScale: 1, //长宽比
                zoom: 1.1,
                //                center: item.position,
                roam: true,
                label: {
                    normal: {
                        show: true,
                        textStyle: {
                            color: '#1DE9B6'
                        }
                    },
                    emphasis: {
                        textStyle: {
                            color: 'rgb(183,185,14)'
                        }
                    }
                },

                itemStyle: {
                    normal: {
                        borderColor: 'rgb(147, 235, 248)',
                        borderWidth: 1,
                        areaColor: {
                            type: 'radial',
                            x: 0.5,
                            y: 0.5,
                            r: 0.8,
                            colorStops: [{
                                offset: 0,
                                color: '#09132c' // 0% 处的颜色
                        }, {
                                offset: 1,
                                color: '#274d68' // 100% 处的颜色
                        }],
                            globalCoord: true // 缺省为 false
                        },
                    },
                    emphasis: {
                        areaColor: '#013954',
                        //    shadowColor: 'rgb(12,25,50)',
                        borderWidth: 0.1
                    }
                },


            },
            series: [{
                    type: 'effectScatter',
                    coordinateSystem: 'geo',
                    showEffectOn: 'render',
                    zlevel: 1,
                    rippleEffect: {
                        period: 15,
                        scale: 4,
                        brushType: 'fill'
                    },
                    hoverAnimation: false,

                    itemStyle: {
                        normal: {
                            color: function (params) {

                                var colorIndex = _.sortedIndex(radios, params.data[2]);
                                return levelColors[colorIndex];
                            },

                            shadowBlur: 10,
                            shadowColor: '#333'
                        }
                    },
                    symbolSize: 12,
                    data: points
            }, //地图线的动画效果
                {
                    type: 'lines',
                    zlevel: 2,
                    effect: {
                        show: true,
                        period: 4, //箭头指向速度,值越小速度越快
                        trailLength: 0.4, //特效尾迹长度[0,1]值越大,尾迹越长重
                        symbol: 'arrow', //箭头图标
                        symbolSize: 7, //图标大小
                    },
                    label: {
                        show: true,
                        position: 'middle',
                        formatter: function (params) {

                            var value = points[params.dataIndex][2];

                            return (value * 100).toFixed(1) + '%';
                        },
                        color: '#fff'
                    },
                    lineStyle: {
                        normal: {
                            color: '#1DE9B6',
                            width: 1, //线条宽度
                            opacity: 0.1, //尾迹线条透明度
                            curveness: .3 //尾迹线条曲直度
                        }
                    },
                    data: lines
            },
                {
                    type: 'scatter',
                    coordinateSystem: 'geo',
                    zlevel: 2,
                    rippleEffect: {
                        period: 4,
                        brushType: 'stroke',
                        scale: 4
                    },
                    label: {
                        normal: {
                            show: true,
                            fontSize: 16,
                            position: 'right',
                            //offset:[5, 0],
                            color: '#0f0',
                            formatter: '{b}',
                            textStyle: {
                                color: "#0f0"
                            }
                        },
                        emphasis: {
                            show: true,
                            color: "#f60"
                        }
                    },
                    symbol: 'pin',
                    symbolSize: 50,
                    color: 'yellow',
                    data: [{
                        name: station.name,
                        value: [station.lng, station.lat],
				}],
			}]

        
        };


        myChart.setOption(option, true);


    }

    function initBar(data, station) {

        // prettier-ignore
        let dataAxis = _.pluck(data, 'name');
        // prettier-ignore
        let xData = _.map(data, x => {

            var colorIndex = _.sortedIndex(radios, x.value);

            return {
                value: +(x.value * 100).toFixed(1),
                itemStyle: {
                    color: levelColors[colorIndex]
                }
            }
        });


        var chartDom = document.getElementById('bar');
        var myChart = echarts.init(chartDom);

        var stationName = $('#option_station option:selected').text();
        option = {
            grid: {

                height: '90%',
                bottom: '0%',
                left: 50,
                containLabel: true
            },
            title: {
                text: `(${station['name']})周边企业影响`,
                subtext: $('#contributeDiv caption').text(),


            },
            xAxis: {
                type: 'category',
                data: dataAxis,
                

                axisLabel: {
                    position: 'outside',
                    color: '#000',
                    interval: 0,
                    rotate: 60,
                    fontSize: 12,
                    fontStyle: 'bold',
                    formatter: function (params) {
                        return params.slice(0, 8);
                    },
                    lineHeight: 100,

                },



            },
            yAxis: {
                show: false
            },

            series: [
                {
                    type: 'bar',


                    label: {
                        show: true,
                        color: '#000',
                        position: 'top',
                        formatter: '{c}%'
                    },

                    data: xData
    }
  ]
        };

        myChart.setOption(option, true);

    }
    getPolygons().then(function () {

        refreshAll();

    });
    $('#option_submit').click(function () {
        refreshAll();
    })

    var angles = [-180, -157.5, -112.5, -67.5, -22.5, 22.5, 67.5, 112.5, 157.5, 180];
    var directions = ['南', '南', '西南', '西', '西北', '北', '东北', '东', '东南', '南']

    function refreshAll() {
        var code = $('#option_station').val();

        var station = _(stations).find({
            'code': code
        });

        $.get('/static/mock/pollutes.json', {
                station: code,
                factor: $('#option_factor').val(),
                runAt: $('#option_date').val(),
                predictAt: $('#option_date2').val(),
            },
            function (data) {

                var points=mockData3(data,station)
                initTable(points,station);
                initMap(points, station);
                initBar(points, station);
            })
    }
    function mockData3(data,station){
        var points = data.map(x => {
                    return {
                        position: [x['lng'], x['lat']],
                        value: +((_.random(100, 2000) / 10000).toFixed(3)),

                        name: x['name']
                    }
                });
                var points_tf = turf.featureCollection(points.map(x => turf.point(x['position'], _.pick(x, ['name', 'value']))));

                var radius = _.random(50, 150);
                var options = {
                    steps: 30,
                    units: 'kilometers',

                };
                var searchWithin = turf.circle([station['lng'], station['lat']], radius, options);

                var points_within = turf.pointsWithinPolygon(points_tf, searchWithin);

                var from = turf.point([station['lng'], station['lat']]);
                points = points_within.features.slice(0, 10).map(x => {


                    var to = turf.point(x.geometry.coordinates);
                    var options = {
                        units: 'kilometers'
                    };

                    var distance = turf.distance(from, to, options);
                    var bearing = turf.bearing(from, to);
                    direction = directions[_.sortedIndex(angles, bearing)];
                    return {
                        position: x.geometry.coordinates,
                        value: x.properties['value'],
                        distance: distance.toFixed(1),
                        direction: direction,
                        name: x.properties['name']
                    }
                })
                points = _.sortBy(points, 'value').reverse();
                return points;
    }

    function initTable(points) {
        var date = moment($('#option_date').val()).format('YYYY年M月D日');
        var date2 = moment($('#option_date2').val()).format('YYYY年M月D日');
        var factor = $('#option_factor').val();

        var title = `(${dictFactor[factor]})(预测日期:${date2})(起报时间:${date})`;
        var template = _.template($('#contributeTableTemplate').html());
        var html = template({
            data: points,
            title: title
        });
        $('#contributeDiv').html(html);
    }

})

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
1 条评论
热度
最新
大佬,文章太深奥了,我还在理解增量迁移的实现原理是什么
大佬,文章太深奥了,我还在理解增量迁移的实现原理是什么
回复回复点赞举报
推荐阅读
为Win10右键菜单中添加 “获取超级管理员权限” 的选项
  在操作某些Windows系统文件/文件夹时,会提示“文件访问被拒绝,你需要权限才能执行此操作/你需要提供管理员权限才能移动此文件”,
黑泽君
2018/10/11
13.6K1
为Win10右键菜单中添加 “获取超级管理员权限” 的选项
工作中遇到的小技巧 一(暂停更新)
       如果浏览器的缓存已满,服务速度可能会减慢,您可能无法下载和查看附件。一下是在Internet Explorer中清空浏览器缓存的步骤:
DannyHoo
2022/05/09
8690
工作中遇到的小技巧 一(暂停更新)
win11右键菜单改回win10教程(亲测可用-全流程截图)
依次选择到【HKEY_CURRENT_USER\SOFTWARE\CLASSES\CLSID】文件夹:
红目香薰
2022/11/30
2.9K0
win11右键菜单改回win10教程(亲测可用-全流程截图)
学习中遇到的小技巧 一(暂停更新)
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huyuyang6688/article/details/8976530
DannyHoo
2018/09/13
1K0
学习中遇到的小技巧  一(暂停更新)
Workbook工作簿对象方法(一)
大家好,前面介绍了工作簿对象的属性,本节开始介绍工作簿对象的常用方法。这些常用方法可以实现平时用手工的新建、打开、激活、保存excel表等功能。
无言之月
2019/10/13
6.9K0
Windows Server IIS配置 怎么禁用不安全的SSL2.0和SSL3.0协议?
Windows Server 2008 /2012 中使用IIS 7 /8是默认允许SSL 2.0和SSL 3.0的,如何关闭不安全的SSL 2.0 和SSL3.0 协议?可按如下操作: 单击开始-运行,键入注册表编辑器,然后单击确定。 在注册表编辑器,找到以下注册表项/文件夹:HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSecurityProvidersSchannelProtocols 在SSL 2.0文件夹,右键单击并选择新建,然后单击项(K)。然后
小唐同学.
2022/02/23
3.4K0
VBA实用小程序61: 在文件夹内所有文件中运行宏/在工作簿所有工作表中运行宏
在文件夹中所有文件上运行宏,或者在Excel工作簿中所有工作表上运行宏,这可能是一种非常好的Excel自动化方案。例如处理类似的数据工作簿文件并想要提取数据或转换该工作簿。下面给出了适用这种情况的一些VBA程序,这些程序代码整理自analystcave.com,供有兴趣的朋友参考。
fanjy
2019/12/12
5.5K0
电脑右键找不到【新建Word/PPT/Excel】的解决方法
  本文介绍在Windows电脑中,右键与资源管理器的“新建”选项中,都没有新建Word、PPT或Excel文件的解决方法。
疯狂学习GIS
2024/09/26
7370
电脑右键找不到【新建Word/PPT/Excel】的解决方法
win10下用户名、登陆账户、用户主目录的修改
以管理员权限进入命令提示符,执行net user administrator /active:yes启用Administrator账户。
似水的流年
2021/01/14
3.2K0
Win10删除右键菜单中的百度网盘以及资源管理器中3D对象/视频/图片等快捷方式
相信大家都有这种经历,装了百度网盘客户端后,会自动在Windows的右键菜单中添加“上传到百度网盘”选项,但该选项在百度网盘客户端设置中是没法去掉的。本文章演示如何通过修改注册表项,来删除右键菜单中的这个选项。
浩Coding
2021/01/16
12.7K0
Win10删除右键菜单中的百度网盘以及资源管理器中3D对象/视频/图片等快捷方式
添加/删除 Win10系统右键关闭显示器菜单方法
在Windows 10系统桌面右键菜单中如果添加一个【关闭显示器】菜单,当我们要离开计算机时,关闭显示器的操作就简便多了。
壬辰龙99
2020/05/25
3.4K1
Workbook工作簿对象方法(二)
大家好,上节介绍过部分工作簿对象的常用方法-创建和打开,本节将继续介绍工作簿对象的激活、保存和关闭方法。
无言之月
2019/10/13
5.2K0
win10系统不支持的16位应用程序该怎么办?
win10系统不支持的16位应用程序该怎么办?最近使用win10系统的用户反应系统中无法正常安装程序的现象,提示不支持的16位应用程序”的错误提示,该如何解决呢?win10系统不支持的16位应用程序的现象一般是因为系统默认现状导致的,针对这一问题大家可以通过本文中winwin7小编介绍的操作方法来进行操作修复!## win10系统不支持的16位应用程序的解决方法一 组策略
田小檬
2023/09/06
9.1K0
win10系统不支持的16位应用程序该怎么办?
给鼠标右键添加选项
版权声明:本文为博主原创文章,欢迎转载,转载请注明出处。 https://blog.csdn.net/FE_dev/article/details/71423907
FEWY
2019/05/26
2.2K0
Windows 配置添加右键菜单 —— 在VSCode中打开
在Windows上面安装Visual Studio Code代码编辑器时,常常会因为安装的时候忘记勾选相关选项等原因,没有将“Open with Code”(右键快捷方式)添加到鼠标右键菜单里,所以需要手动将VSCode相关快捷打开添加至鼠标右键菜单之中。。 简介 我们经常需要在 Windows 用 VS Code 打开各各地方的文件夹、文件,但之前苦于不知道简便的方法直接打开 VS Code,需要 打开文件夹 -> 复制路径 就很麻烦 事实上 VS Code 支持右键快捷菜单 可以在安装时
为为为什么
2022/08/10
25.6K0
Windows 配置添加右键菜单 —— 在VSCode中打开
文科生也能学会的Excel VBA 宏编程入门(三)——合并文件
在日常工作中,我们经常会遇到需要汇总多个表格的数据,将它们合并到一个表格里的情况。虽然复制粘贴大法好,但如果让你汇总几十人填报的个人信息并做成汇总表格,估计你也膜不动了。因此,这一次我们就通过VBA程序完成这个任务,从此妈妈再也不担心我数数到头秃。
全栈程序员站长
2022/09/02
4.3K0
怎么把软件添加到右键菜单
很多朋友下载了绿色版本的文本编辑器/播放器等,想将其添加到右侧菜单中,方便以后使用,但使用了很多软件都无效。接下来我以notepad为例教你如何操作。
共饮一杯无
2022/11/24
2K0
怎么把软件添加到右键菜单
[1243]win11右键显示更多选项怎么关闭
注册表编辑器是Windows系统内置的一个功能非常强的实用程序,我们可以通过它来查看和更改系统注册表程序设置,也能帮助我们轻松解决Win11右键显示更多选项怎么关问题,另外请注意,修改注册表编辑器存在一些风险,请仔细阅读以下流程并逐步操作,或者也可以提前对系统备份,以防意外情况发生。
周小董
2023/12/10
4930
[1243]win11右键显示更多选项怎么关闭
Excel实战技巧:创建带有自定义功能区的Excel加载宏
创建的这个带有自定义功能区的Excel加载宏将可以有任意工作簿中使用,下面我们详细讲解其创建过程。
fanjy
2022/11/16
4K0
Excel实战技巧:创建带有自定义功能区的Excel加载宏
一键添加鼠标右键菜单重启资源管理器,让电脑进程更流畅!
前面其实给大家写过这个了,这里的话在写一遍,而且也把整个过程写为了批处理,不需要你去做任何动作,只需要运行批处理点击执行就好!当然如果你对这个批处理有兴趣或者有疑问的话,可以在菜单栏进入留言即可!
FreeRonin
2021/01/13
2.9K0
推荐阅读
相关推荐
为Win10右键菜单中添加 “获取超级管理员权限” 的选项
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档