gpt4 book ai didi

javascript - 当目的地很远时如何获得平滑的谷歌地图 panTo()

转载 作者:行者123 更新时间:2023-12-05 01:14:29 26 4
gpt4 key购买 nike

我在谷歌地图上有两个点,我想使用流畅的动画在它们之间进行转换。使用 map.panTo() 方法我可以平移它们,但动画仅在第二个点小于 map 的宽度/高度时才有效。

所以我想出的想法是将过渡分解为:

 var destination = next point 
get center

check if the destination is in bounds
if so
panTo it
else
get the midpoint between center and point
if midpoint in bounds pan
else get midpoint etc....

所以这里的旅行被分解成尽可能小的步骤。问题是,我不知道如何在代码中实现它(即递归中点检查)任何帮助都会很棒。

我遇到这个问题的页面是 http://amishh4cker.com/geocaching.html

最佳答案

if ( end - start ) > width and ( end - start ) < maxpandistance then  midpoint = start + ( end - start ) * .5  while midpoint is not on screen    midpoint = start + ( midpoint - start ) * .5  loop  panto midpointelse  panto end

类似的东西,虽然我可以看到相当大的距离导致减速,尤其是当窗口变小时。

关于javascript - 当目的地很远时如何获得平滑的谷歌地图 panTo(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4024570/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com