16.gis车辆轨迹回放之mapbox-gl

该博客介绍了利用JavaScript和ArcGIS实现车辆轨迹展示的方法。包括数据准备,如routeGeoJson轨迹数据等;通过调用特定方法实现车辆出发、暂停等操作;初始化图标并重新获取轨迹点数据;最终完成车辆轨迹及位置的结果展示。

数据准备

routeGeoJson轨迹数据
svgXML道路箭头
newRouteGeoJson根据速度生成新的轨迹点数组
realRouteGeoJson车辆经过后的轨迹线
animatePointGeoJson车辆位置

var svgXML =
        `<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" > 
                <path style="animation: fall 1s linear infinite;" d="M529.6128 512L239.9232 222.4128 384.7168 77.5168 819.2 512 384.7168 946.4832 239.9232 801.5872z" p-id="9085" fill="#ffffff"></path> 
            </svg>
            `
    //给图片对象写入base64编码的svg流
    var svgBase64 = 'data:image/svg+xml;base64,' + window.btoa(unescape(encodeURIComponent(svgXML)));
    var isPlay = false
    var counter = 0
    var steps = 0
    let aLength = 0;
    var newRouteGeoJson;
    var routeGeoJson = {
   
   
        'type': 'FeatureCollection',
        'features': [{
   
   
            'type': 'Feature',
            'geometry': {
   
   
                'type': 'LineString',
                'coordinates': [[108,34],[108,35],[109,35]]
            }
        }]
    }

    var realRouteGeoJson = {
   
   
        'type': 'FeatureCollection',
        'features': [{
   
   
            'type': 'Feature',
            'geometry': {
   
   
                'type': 'LineString',
                'coordinates': []
            }
        }]
    }

    var animatePointGeoJson = {
   
   
        'type': 'FeatureCollection',
        'features': [{
   
   
            'type': 'Feature',
            'properties': {
   
   },
            'geometry': {
   
   
                'type': 'Point',
                'coordinates': []
            }
        }]
    }

调用

通过调用下列方法可实现车辆出发、暂停、继续、返回、清除所有

// 开始
export const startClick=async()=> {
   
   
    isPlay=false
    if (!isPlay) {
   
   
        clearAllLayers()
        await initCarAndLine();
        isPlay = true
        animate()
    }
}
// 暂停
export const pauseClick=()=> {
   
   

    isPlay = false
    animate()
}
// 继续
export const goOnClick=async()=> {
   
   
    if (!isPlay) {
   
   
        isPlay = true
        animate()
    }
}
// 返回
export const stopClick=()=> {
   
   
    isPlay = false
    counter = 0
    animate(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫雪giser

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值