一次一个标记动画 Google Maps Api 3
我正在开发地图应用程序,但一次无法使标记动画化。我希望拥有它,以便当单击新标记时,另一个标记的动画将被删除。我是一个 js 菜鸟,一直在绞尽脑汁。截至目前,我将标记放在一个数组中,以便我可以删除动画..但是在为另一个标记设置动画时如何删除每个其他标记的动画?..下面是我一直在播放的代码和
for (i in markersArray) {
if (markersArray[i].getAnimation() != null) {
markersArray[i].setAnimation(null);
}
if (marker[i].getAnimation() != null) {
marker[i].setAnimation(null);
} else {
marker[i].setAnimation(google.maps.Animation.BOUNCE);
}
}
I'm working on a Map app and I'm having trouble getting marker animated at a time. I'd like to have it so that when a new marker is clicked, the other's animation is removed. I'm a js noob and have been wracking my head. As of now, I have the markers in an array so that I can remove the animation ..but how can I remove the animation of every other marker when setting the animation for another one?..below is the code I've been playing with
for (i in markersArray) {
if (markersArray[i].getAnimation() != null) {
markersArray[i].setAnimation(null);
}
if (marker[i].getAnimation() != null) {
marker[i].setAnimation(null);
} else {
marker[i].setAnimation(google.maps.Animation.BOUNCE);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您发布的代码看起来不错,如果它适合您,那就太好了。但是,如果您一次只想对一个标记进行动画处理,那么仅保留最后一个动画标记的变量可能会更高效、更简单。例如,在点击事件中或添加标记时,您可以执行以下操作:
The code that you posted seems fine and if it works for you, great. However, if you only want one marker animated at a time, then it might be more efficient, and easier, to just keep a variable of the last animated marker. For example, in your click event or when you add a marker, you could do something like this:
在为每个标记分配一个唯一的 id 后,我最终想出了以下代码......工作起来就像一个魅力
I ended up coming up with the following code after assigning a unique id to each marker...worked like a charm
我更喜欢@Nick Canzoneri 风格。稍微修改了一下
i prefer @Nick Canzoneri style. Modified it a bit
这就是我所做的工作,我将标记放在全局变量中。这使得我的标记可以随时访问。
This is what that i got working, I have my markers in a global variable. Which keeps my markers accessible at all time.