leaflet marker 动态移动

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/leaflet/1.9.3/leaflet-src.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/leaflet/1.9.3/leaflet.css" rel="stylesheet">
    <style>
        body {
            padding: 0;
            margin: 0;
        }

        #map {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <script>
        var map = window.map = L.map('map', {
            crs: L.CRS.EPSG4326
        }).setView([39.96, 116.39], 13);
        const url = 'https://t0.tianditu.gov.cn/';

        L.tileLayer(
            url +
            "vec_c/wmts?layer=vec&style=default&tilematrixset=c&Service=WMTS&Request=GetTile&Version=1.0.0&Format=tiles&TileMatrix={z}&TileCol={x}&TileRow={y}&tk=0b018552994f71a9467d24461a8f8238", {
                maxZoom: 20,
                tileSize: 256,
                zoomOffset: 1,
            }
        ).addTo(map);

        var myIcon = L.icon({
            iconUrl: 'https://www-test04.eqfleetcmder.com/static/img/dkz.a6be4265.png',
            iconSize: [38, 95],
            iconAnchor: [22, 94],
            popupAnchor: [-3, -76],
            shadowSize: [68, 95],
            shadowAnchor: [22, 94]
        });

        const myPositionMarker = L.marker([39.96, 116.39], {
            icon: myIcon
        }).addTo(map);
        
        var pos = map.latLngToLayerPoint(myPositionMarker.getLatLng());
        var fx = new L.PosAnimation();
        fx.run(myPositionMarker._icon, pos, 0.3);
        let x = 116.39;
        let y = 39.96;
        
        // setInterval(() => {
        //     x += 0.002;
        //     y += 0.002;
        //     let pos = map.latLngToLayerPoint({lng: x, lat: y});
        //     fx.run(myPositionMarker._icon, pos, 1, (0, 0, 1, 1));
        // }, 1000);
        
        fx.on('end', () => {
            console.log('1111111111');
            myPositionMarker.setLatLng(L.latLng(y, x));
            x += 0.002;
            y += 0.002;
            let pos = map.latLngToLayerPoint({lng: x, lat: y});
            fx.run(myPositionMarker._icon, pos, 1, (0, 0, 1, 1));
        });
    </script>
</body>

</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值