轨迹回放

程序源代码

共 12667字,需浏览 26分钟

 · 2024-03-20

      
      <!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>轨迹回放</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <style>
        html,
        body,
        #container {
            height100%;
            width100%;
        }

        .input-card .btn {
            margin-right1.2rem;
            width9rem;
        }

        .input-card .btn:last-child {
            margin-right0;
        }
    
</style>
</head>

<body>
    <div id="container"></div>
    <div class="input-card">
        <h4>轨迹回放控制</h4>
        <div class="input-item">
            <input type="button" class="btn" value="开始动画" id="start" onclick="startAnimation()" />
            <input type="button" class="btn" value="暂停动画" id="pause" onclick="pauseAnimation()" />
        </div>
        <div class="input-item">
            <input type="button" class="btn" value="继续动画" id="resume" onclick="resumeAnimation()" />
            <input type="button" class="btn" value="停止动画" id="stop" onclick="stopAnimation()" />
        </div>
    </div>
    // 添加一个2.0的key值即可以使用 1.4.15
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=">
    </script>
    <script>
        // JSAPI2.0 使用覆盖物动画必须先加载动画插件
        AMap.plugin('AMap.MoveAnimation'function () {
            var marker, lineArr = [
                [116.47893539.997761],
                [116.47893939.997825],
                [116.47891239.998549],
                [116.47891239.998549],
                [116.47899839.998555],
                [116.47899839.998555],
                [116.47928239.99856],
                [116.47965839.998528],
                [116.48015139.998453],
                [116.48078439.998302],
                [116.48078439.998302],
                [116.48114939.998184],
                [116.48157339.997997],
                [116.48186339.997846],
                [116.48207239.997718],
                [116.48236239.997718],
                [116.48363339.998935],
                [116.4836739.998968],
                [116.48464839.999861]
            ];

            var map = new AMap.Map("container", {
                resizeEnabletrue,
                center: [116.47912639.998563],
                zoom20,
                pitch55.94919957310569,
                rotation-0.7908261543741522,
                viewMode'3D'//开启3D视图,默认为关闭
                buildingAnimationtrue//楼块出现是否带动画
            });

            window.map = map

            marker = new AMap.Marker({
                map: map,
                position: [116.47893539.997761],
                icon"https://a.amap.com/jsapi_demos/static/demo-center-v2/car.png",
                offsetnew AMap.Pixel(-13-26),
            });

            // 绘制轨迹
            var polyline = new AMap.Polyline({
                map: map,
                path: lineArr,
                showDirtrue,
                strokeColor"#28F"//线颜色
                // strokeOpacity: 1,     //线透明度
                strokeWeight6//线宽
                // strokeStyle: "solid"  //线样式
            });

            var passedPolyline = new AMap.Polyline({
                map: map,
                strokeColor"#AF5"//线颜色
                strokeWeight6//线宽
            });


            marker.on('moving'function (e{
                passedPolyline.setPath(e.passedPath);
                // 设置地图中心点
                map.setCenter(e.target.getPosition())
                // 设置旋转角
                map.setRotation(-e.target.getOrientation())
            });

            map.setFitView();

            window.startAnimation = function startAnimation() {
                marker.moveAlong(lineArr, {
                    // 每一段的时长
                    duration200,
                    // JSAPI2.0 是否延道路自动设置角度在 moveAlong 里设置
                    autoRotationtrue,
                });
            };

            window.pauseAnimation = function () {
                marker.pauseMove();
            };

            window.resumeAnimation = function () {
                marker.resumeMove();
            };

            window.stopAnimation = function () {
                marker.stopMove();
            };

        });
    
</script>
</body>

</html>
浏览 15
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报