使用严重的纬度/经度数组对图标进行动画处理-Mapbox js [英] Animate an icon by using serious of Lat/lon Array - Mapbox js

查看:138
本文介绍了使用严重的纬度/经度数组对图标进行动画处理-Mapbox js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改风箱脚本,以了解如何按照纬度/经度数组移动图标,但它总是说诸如此类的错误,但我是以数组的形式提供的

I am modifying bellow script to see how can i move an Icon by following Array of Lat/lon , but it always say error such , but I am providing as an Array

有人可以帮助我了解我做错了什么吗?我很尊敬这个例子 https://www.mapbox.com/mapbox-gl-js/example/animate-marker/

Can any one please help me to understand what i am doing wrong ? I am revering this example https://www.mapbox.com/mapbox-gl-js/example/animate-marker/

Error : 
lng_lat.js:121 Uncaught Error: `LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]
    at Function.yu.convert (lng_lat.js:121)
    at o.setLngLat (marker.js:251)
    at animateMarker (animate.html:33) 

修改后的代码:-

<html>
<head>
    <meta charset='utf-8' />
    <title>Animate a marker</title>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.js'></script>
    <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css' rel='stylesheet' />
    <style>
        body { margin:0; padding:0; }
        #map { position:absolute; top:0; bottom:0; width:100%; }
    </style>
</head>
<body>

<div id='map'></div>
<script>
mapboxgl.accessToken = '';
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v9',
    center: [90.35388165034988, 23.725173272533567],
    zoom: 10
});

var marker = new mapboxgl.Marker();

function animateMarker() {
    var radius = 20;

    // Update the data to a new position based on the animation timestamp. The
    // divisor in the expression `timestamp / 1000` controls the animation speed.
    marker.setLngLat([
	
 [90.35388165034988, 23.725173272533567],
 [90.37379437008741, 23.732873570085644] ,
 [90.38563900508132, 23.72297310398119],
 [90.35388165034988, 23.725173272533567],
 [90.35388165034988, 23.725173272533567]
	 
    ]);

    // Ensure it's added to the map. This is safe to call if it's already added.
    marker.addTo(map);

    // Request the next frame of the animation.
    requestAnimationFrame(animateMarker);
}

// Start the animation.
requestAnimationFrame(animateMarker);
</script>

</body>
</html>

推荐答案

您只能将单个坐标传递给 setLngLat .您不能传递数组.这是一个简单的示例,其中在动画功能内,我们使用时间从点数组中选取一个位置,并将该位置 传递给标记.

You can only pass a single coordinate to setLngLat. You cannot pass an array. Here's a crude example where inside the animation function, we use time to pick a position from the array of points and pass that one position to the marker.

var controlPoints = [
 [90.35388165034988, 23.725173272533567],
 [90.37379437008741, 23.732873570085644] ,
 [90.38563900508132, 23.72297310398119],
 [90.35388165034988, 23.725173272533567],
 [90.35388165034988, 23.725173272533567]
];

function animateMarker(timestamp) {
    // stay at each point for 1 second, then move to the next
    // (lower 1000 to 500 to move 2x as fast)
    var position = Math.floor(timestamp / 1000) % controlPoints.length;
    marker.setLngLat(controlPoints[position])

    // Ensure it's added to the map. This is safe to call if it's already added.
    marker.addTo(map);

    // Request the next frame of the animation.
    requestAnimationFrame(animateMarker);
}

此动画将是原始的.理想情况下,您将获得这些控制点并创建一条折线或线性环,然后您的动画功能将以设定的速度(例如30 km/s)沿折线进行插值.您将得到一个非常漂亮的动画,该动画遵循控制点的路径.

This animation will be crude. Ideally, you'd take those control points and create a polyline or linear ring, then your animation function would interpolate along the polyline at a set speed (like 30 km/s). You would end up with a very nice animation that followed the path of the control points.

这篇关于使用严重的纬度/经度数组对图标进行动画处理-Mapbox js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆