高德地图loca可视化脉冲流动线条

复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>oo</title>
    <style>
        html,
        body,
        #map {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }

        .demo-title {
            position: absolute;
            top: 25px;
            left: 25px;
            z-index: 1;
        }

        h1 {
            font-size: 18px;
            margin: 0;
            color: rgb(180, 180, 190);
        }

        h3 {
            font-size: 12px;
            font-weight: normal;
            margin-top: 5px;
            color: rgb(150, 150, 150);
        }
    </style>
</head>

<body>
    <div class="demo-title">
        <h1>北京公交线路行驶路线分类</h1>
        <h3>北京全市范围内各公交线路运行情况</h3>
    </div>
    <div id="map"></div>
    <script src="https://webapi.amap.com/maps?v=2.0&key=你的key"></script>
    <script src="https://webapi.amap.com/loca?v=2.0.0&key=你的key"></script>
    <script>
        //数据格式

        var pLineData = {
            "type": "FeatureCollection",
            "features": [
                {
                    "type": "Feature", "properties": { "type": 1 },
                    "geometry": {
                        "type": "LineString",
                        "coordinates": [[116.417458, 39.934026],]
                    }
                },
                {
                    "type": "Feature", "properties": { "type": 2 }, "geometry":
                    {
                        "type": "LineString",
                        "coordinates":
                            [[
                                126.128627,
                                41.146943
                            ],
                            [
                                126.12425,
                                41.137959
                            ],
                            [
                                126.113693,
                                41.128908
                            ]]
                    }
                },

            ]
        }
        var map = (new AMap.Map('map', {
            zoom: 11.2,
            center: [126.128627,
                41.146943],
            showLabel: false,

            mapStyle: 'amap://styles/45311ae996a8bea0da10ad5151f72979',
            pitch: 50,
        }));
        //初始化可视化
        var loca = new Loca.Container({
            map,
        });
        window._loca = loca;

        var geo = new Loca.GeoJSONSource({
            data: pLineData //数据格式
        })
//新建一个图层
        var layer = new Loca.PulseLineLayer({
            // loca,
            zIndex: 10,
            opacity: 1,
            visible: true,
            zooms: [2, 22],
        });

//填数据
        layer.setSource(geo);
        //填样式
        layer.setStyle({
            altitude: 0,
            lineWidth: 10,
            // 脉冲头颜色
            headColor: "rgb(255, 0, 0)",
            // 脉冲尾颜色
            trailColor: 'rgba(0, 0, 192, 0.9)',
            // 脉冲长度,0.25 表示一段脉冲占整条路的 1/4
            interval: 0.25,
            // 脉冲线的速度,几秒钟跑完整段路
            duration: 5000,
        });
        //添加图层开始动画
        loca.add(layer);
        loca.animate.start();
//结束



        var headColors = ['#EFBB51', '#7F3CFF', '#4CC19B', '#0B5D74', '#E06AC4', '#223F9B', '#F15C1A', '#7A0FA6'];
        // var headColors = ['#EFBB51', '#7F3CFF', '#4CC19B', '#0B5D74', '#E06AC4', '#223F9B', '#F15C1A', '#7A0FA6'];
        console.log('geo', geo);


        // 图例
        var lengend = new Loca.Legend({
            loca: loca,
            title: {
                label: '公交类型',
                fontColor: 'rgba(255,255,255,0.4)',
                fontSize: '16px'
            },
            style: {
                backgroundColor: 'rgba(255,255,255,0.1)',
                left: '20px',
                bottom: '40px',
                fontSize: '12px'
            },
            dataMap: [
                { label: 'A类型', color: headColors[7] },
                { label: 'B类型', color: headColors[6] },
                { label: 'C类型', color: headColors[5] },
                { label: 'D类型', color: headColors[4] },
                { label: 'E类型', color: headColors[3] },
                { label: 'F类型', color: headColors[2] },
                { label: 'G类型', color: headColors[1] },
                { label: 'H类型', color: headColors[0] },
            ],
        });

        loca.animate.start();
        var dat = new Loca.Dat();
        dat.addLayer(layer, '公交');

    </script>
</body>

</html>
相关推荐
用户059540174463 小时前
LLM对话记忆测试踩坑实录:手工回归30分钟,自动化后2分钟发现3个隐藏Bug
前端·css
Ashley的成长之路4 小时前
前端性能优化实战手册·第2篇:资源加载策略全解
前端·性能优化·资源加载·http/3·性能优化实战·资源加载优化
浅水壁虎4 小时前
vue基础(第二章 )
前端·javascript·vue.js
界面开发小八哥4 小时前
界面控件DevExtreme v26.1新版亮点——支持Angular 22
前端·javascript·angular.js·devexpress·ui开发·devextreme
Getflare4 小时前
前端 + UI 设计 + AI:这不是三个工种,是一个新三角能力模型(附自检清单)
前端·人工智能·ui
oil欧哟4 小时前
我做了一个 Vibe Coding 术语学习站:VibeHub
前端·ai·agent·独立开发·vibe coding
审小匠OpenCPAi5 小时前
银行流水核查怎么自动化?单边匹配、双向勾稽与图聚类异常检测的工程对比
java·前端·人工智能·python·审计
Revolution615 小时前
一个公共表格组件,是怎么一步步失控的
前端·前端工程化
mONESY5 小时前
React useState 核心原理与最佳实践:从异步更新到性能优化全解
javascript