百度地图MapVGL的点热力图

百度地图MapVGL的点热力图

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>MapVGL</title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <style>
    html,
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
    }
    #map_container {
        width: 100%;
        height: 100%;
        margin: 0;
    }
    </style>
    <script src="//api.map.baidu.com/api?v=1.0&type=webgl&ak=1XjLLEhZhQNUzd93EjU5nOGQ"></script>
    <script src="static/mapv.min.js"></script>
    <script src="static/common.js"></script>
    <script src="https://code.bdstatic.com/npm/mapvgl@1.0.0-beta.100/dist/mapvgl.min.js"></script>
    <script src="https://code.bdstatic.com/npm/mapvgl@1.0.0-beta.100/dist/mapvgl.threelayers.min.js"></script>
</head>
<body>
    <div id="map_container"></div>
    <script>
    /* global BMapGL */

    /* global mapv */

    /* global mapvgl */

    /* global initMap */

    var map = initMap({
        tilt: 0
    });

    var point = new BMapGL.Point(116.404000,39.915221);
    map.centerAndZoom(point, 11);

    var view = new mapvgl.View({
        effects: [
            new mapvgl.BloomEffect({
                threshold: 0.2,
                blurSize: 2.0
            }),
        ],
        map: map
    });

    var result = [];
    fetch('./static/bj_grid20181212.csv').then(function (rs) {
        return rs.text();
    }).then(function (rs) {
        rs = rs.split('\n');
        for (var i = 0; i < rs.length; i++) {
            var line = rs[i].split(',');
            result.push(line);
        }
        draw();
    });

    function draw() {
        var data = [];
        for (var i = 0; i < result.length - 1; i++) {
            var line = result[i];
            data.push({
                geometry: {
                    type: 'POINT',
                    coordinates: [line[1], line[2]]
                },
                properties: {
                    count: line[3]
                }
            });
        }

        var whiteLayer = new mapvgl.HeatPointLayer({
            blend: 'lighter',
            style: 'grid',
            shape: 'square',
            size: 1,
            min: 0,
            max: 1000,
            gradient: {
                0: 'rgb(200, 200, 200, 0)',
                0.2: 'rgb(200, 200, 200, 0.5)',
                0.5: 'rgb(200, 200, 200, 0.8)',
                0.51: 'rgb(200, 200, 200, 0)',
                1: 'rgb(200, 200, 200, 0)'
            }
        });
        var yellowLayer = new mapvgl.HeatPointLayer({
            blend: 'lighter',
            style: 'grid',
            size: 4,
            min: 0,
            max: 1000,
            gradient: {
                0: 'rgb(200, 200, 200, 0)',
                0.2: 'rgb(200, 200, 200, 0)',
                0.5: 'rgb(226, 95, 0, 0.9)',
                1: 'rgb(239, 209, 19, 0.9)'
            }

            /*
            gradient: {
                0.0: 'rgb(88, 54, 100, 0.0)',
                0.2: 'rgb(174, 81, 174, 0.0)',
                0.5: 'rgb(225, 108, 30, 0.8)',
                1.0: 'rgb(241, 247, 14, 1.0)',
            }
            */
        });
        view.addLayer(yellowLayer);
        view.addLayer(whiteLayer);
        whiteLayer.setData(data);
        yellowLayer.setData(data);
    }
    </script>
</body>
</html>