• LeaFlet结合leaflet-dvf实现数据可视化


    前言:说起来GIS我觉得侧重于分析,渲染展示,做出来一些直观的专题图让人一眼就能了解数据的含义,今天结合的leaflet的插件实现数据的可视化,该插件可以做很多的功能,下面是一些地址:

    api插件地址:https://github.com/humangeo/leaflet-dvf/wiki/6.-Markers#lstarmarker

    在线引用地址:https://cdnjs.com/libraries/leaflet-dvf

    关于一些饼状图、直方图demo展示:http://humangeo.github.io/leaflet-dvf/examples/html/markers.html

    放张图:

    一、关于js和css设置(我是在线引用的)

        <link href="../script/leaflet/leaflet.css" rel="stylesheet" />
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.3.1/css/dvf.css" integrity="sha256-Nd2GYmWjQVljoYgRUP2AWWniAYagCg1k7QhXa9N1kLg=" crossorigin="anonymous" />
        <script src="../script/leaflet/leaflet.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.3.1/leaflet-dvf.js"></script>
      
        <style>
            #map {
                 100%;
                height: 1000px;
            }
        </style>

    二、关于饼状图、直方图使用(这里只解释直方图,其他类似)

           //直方图
            var colorValue = Math.random() * 360;
            //设置直方图的样式
            var options = {
                color: '#000',
                weight: 1,
                fillColor: 'hsl(' + colorValue + ',100%,50%)',
                radius: 20,
                fillOpacity: 0.7,
                rotation: 0.0,
                position: {
                    x: 0,
                    y: 0
                },
                offset: 0,
                 8
              
            };
            //设置每个直方的数据
            options.data = {
                'dataPoint1': Math.random() * 20,
                'dataPoint2': Math.random() * 20,
                'dataPoint3': Math.random() * 20,
                'dataPoint4': Math.random() * 20
            };
           //设置每个直方的样式等
            options.chartOptions = {
                'dataPoint1': {
                    fillColor: '#F2F0F7',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 30,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint2': {
                    fillColor: '#CBC9E2',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 30,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint3': {
                    fillColor: '#9E9AC8',
                    minValue: -40,
                    maxValue: 20,
                    maxHeight: 30,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint4': {
                    fillColor: '#6A51A3',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 30,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                }
            };
            //声明一个直方图类对象
            var barChart = new L.BarChartMarker(new L.LatLng(41.92, 116.46), options);
            map.addLayer(barChart);

    三、完整的demo

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>leaflet数据显示</title>
        <link href="../script/leaflet/leaflet.css" rel="stylesheet" />
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.3.1/css/dvf.css" integrity="sha256-Nd2GYmWjQVljoYgRUP2AWWniAYagCg1k7QhXa9N1kLg=" crossorigin="anonymous" />
        <script src="../script/leaflet/leaflet.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-dvf/0.3.1/leaflet-dvf.js"></script>
      
        <style>
            #map {
                 100%;
                height: 1000px;
            }
        </style>
    </head>
    <body>
        <div id="map"></div>
        <script>
            var map = new L.Map('map', { center: [39.92, 116.46], zoom: 10, CRS: L.CRS.EPSG4326 });
    
            L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                attribution: 'Map data &copy; <a href="http://www.osm.org">OpenStreetMap</a>'
            }).addTo(map);
    
            //饼状图显示
            var colorValue = Math.random() * 360;
            var options = {
                color: '#000',
                weight: 1,
                fillColor: 'hsl(' + colorValue + ',100%,50%)',
                radius: 40,
                fillOpacity: 0.7,
                rotation: 0.0,
                position: {
                    x: 0,
                    y: 0
                },
                offset: 0,
                numberOfSides: 50,
                barThickness: 10
            };
    
            options.data = {
                '猪肉': Math.random() * 20,
                '羊肉': Math.random() * 20,
                '牛肉': Math.random() * 20,
                '鸡肉': Math.random() * 20
            };
    
            options.chartOptions = {
                '猪肉': {
                    fillColor: '#F1EEF6',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 20,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                '羊肉': {
                    fillColor: '#BDC9E1',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 20,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                '牛肉': {
                    fillColor: '#74A9CF',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 20,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                '鸡肉': {
                    fillColor: '#0570B0',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 20,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                }
            };
    
            var pieChartMarker = new L.PieChartMarker(new L.LatLng(39.92, 116.46), options);
            map.addLayer(pieChartMarker);
            //Coxcom图
            var colorValue = Math.random() * 360;
            var options = {
                color: '#000',
                weight: 1,
                fillColor: 'hsl(' + colorValue + ',100%,50%)',
                radius: 30,
                fillOpacity: 0.7,
                rotation: 0.0,
                position: {
                    x: 0,
                    y: 0
                },
                offset: 0,
                numberOfSides: 50,
                 10
            };
    
            options.data = {
                'dataPoint1': Math.random() * 20,
                'dataPoint2': Math.random() * 20,
                'dataPoint3': Math.random() * 20,
                'dataPoint4': Math.random() * 20
            };
    
            options.chartOptions = {
                'dataPoint1': {
                    fillColor: '#EDF8FB',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 20,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint2': {
                    fillColor: '#B2E2E2',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 20,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint3': {
                    fillColor: '#66C2A4',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 20,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint4': {
                    fillColor: '#238B45',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 20,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                }
            };
            var CoxcombChartMarker = new L.CoxcombChartMarker(new L.LatLng(37.92, 116.46), options);
            map.addLayer(CoxcombChartMarker);        
           //直方图
            var colorValue = Math.random() * 360;
            var options = {
                color: '#000',
                weight: 1,
                fillColor: 'hsl(' + colorValue + ',100%,50%)',
                radius: 20,
                fillOpacity: 0.7,
                rotation: 0.0,
                position: {
                    x: 0,
                    y: 0
                },
                offset: 0,
                 8
            };
    
            options.data = {
                'dataPoint1': Math.random() * 20,
                'dataPoint2': Math.random() * 20,
                'dataPoint3': Math.random() * 20,
                'dataPoint4': Math.random() * 20
            };
    
            options.chartOptions = {
                'dataPoint1': {
                    fillColor: '#F2F0F7',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 30,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint2': {
                    fillColor: '#CBC9E2',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 30,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint3': {
                    fillColor: '#9E9AC8',
                    minValue: -40,
                    maxValue: 20,
                    maxHeight: 30,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                },
                'dataPoint4': {
                    fillColor: '#6A51A3',
                    minValue: 0,
                    maxValue: 20,
                    maxHeight: 30,
                    displayText: function (value) {
                        return value.toFixed(2);
                    }
                }
            };
    
            var barChart = new L.BarChartMarker(new L.LatLng(41.92, 116.46), options);
            map.addLayer(barChart);  
        </script>
    </body>
    </html>

    四、总结

    api插件本身不难,今天浪费了很多时间在这个插件显示上,后来才发现我下载的插件并不对,api本身都有错,该做引用官方的api在线地址,这才解决问题,真坑。

  • 相关阅读:
    题目1202:排序------注意每个数字的后面都有空格
    题目1178:复数集合------------结构体的的比较,cmp()函数的错误让我WA了多次
    题目1041:Simple Sorting-------注意最后一个数字的处理
    题目1034:寻找大富翁---用了sort()函数,注意头文件;
    题目1415:不一样的循环队列------注意细节小地方循环队列注意%M;还有为什么M要加一!!!!!!!!!!!!!
    题目1342:寻找最长合法括号序列II---注意:不要求就近匹配,只要求( 在 )前面的任一个位置即可
    题目1398:移动次数-----最少移动的次数,那么相同的最大值越靠后越好,相同的最小值越靠前越好
    题目1375:陈博的完美主义(25分)----------------题目中对输入数字的长度有要求,所以输入字符串,用atoi()转换函数
    题目1363:欢乐斗地主------用数组计数的应用,注意1和2得排在最后,表示最大
    题目1174:查找第K小数-------qsort()可以直接对数组用;还有用unique(a,a+n);的,服!
  • 原文地址:https://www.cnblogs.com/tuboshu/p/10752321.html
Copyright © 2020-2023  润新知