谷歌地图可以设置为缓慢恒定的平移吗? 像全球革命一样?

正如标题所说的那样。 我正在寻找解决方案,但我没有发现任何指导我正确文档或文章的内容。

如果您有任何想法或可以指出我可以使用的可能解决方案,我将不胜感激。

谢谢

你可以这样做:

  • 使用setInterval设置要定期运行的函数。
  • 该函数会调用Google地图对象上的panBy来“旋转”它。

这应该给你一个简单的动画,做你想要的。 您需要调整为setInterval提供的时间间隔,以获得感觉顺畅的内容。 你应该有这样的事情:

 // Create your map and leave it in the "map" variable. setInterval(function() { map.panBy(x, 0); }, n); 

选择合适的xn值取决于您。

接受的答案还可以,但有点过时了。 而不是window.setInterval你应该使用window.requestAnimationFrame 。 这将为您提供更流畅的动画。

一个简单的例子(不是来自我)可以在这里找到,但它的要点看起来像这样:

 var map = new google.maps.Map(document.getElementById('my-map'), mapOptions) function animate () { map.panBy(2.5 / 2, 1.3 / 2) window.requestAnimationFrame(function () { animate() }) } // eslint-disable-next-line google.maps.event.addListenerOnce(map, "tilesLoaded", function () { window.requestAnimationFrame(function () { animate() }) }) window.requestAnimationFrame(function () { animate() })