3

就像标题所说的那样。我正在寻找解决方案,但没有找到任何可以引导我找到正确文档或文章的内容。

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

谢谢

4

2 回答 2

4

你可以自己这样做:

  • 用于setInterval设置要定期运行的功能。
  • 该函数将调用panByGoogle 地图对象以“旋转”它一点。

这应该会给你一个简单的动画来做你想做的事。您当然想要调整您给予的时间间隔setInterval以获得感觉平滑的东西。你应该有这样的东西:

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

选择合适的xn价值观取决于你。

于 2011-07-26T07:05:06.367 回答
0

接受的答案是好的,但有点过时了。而不是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()
})
于 2017-02-05T00:27:12.070 回答