所有Google Maps v3标记的常见事件处理程序 [英] Common event handler for all Google Maps v3 markers

查看:92
本文介绍了所有Google Maps v3标记的常见事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张地图,显示500个标记,并在用户滚动地图时重绘。每个标记都非常复杂 - 它们被编号并且具有附加的点击,鼠标悬停和鼠标移动(以动画)事件。这会导致一些性能问题,因为删除和添加这些标记需要很长时间。我一直在想,如果我可以为整个地图添加一个单击,鼠标悬停和鼠标悬停事件处理程序,并捕获那里的标记冒出的事件。这可能吗?它会提高性能吗?

I have a map that shows 500 markers and they are redrawn when the user scrolls the map. Each of the markers is quite complicated - they're numbered and have click, mouseover and mouseout (to animate them) events attached. This causes some performance issues because removing and adding these markers takes a lot of time. I've been wondering if I could attach a single click, mouseover and mouseout event handlers for the whole map and catch the event that bubbles up from the markers there. Is this possible? Would it improve the performance?

我发现这个 -

I've found this - How do I make a single event handler for all markers in Google Maps V3? - it's better, but it still requires attaching the handler to each of the markers separately.

我还发现Google地图数据层 - https://developers.google.com/maps/documentation/javascript/datalayer#add_event_handlers - 看起来只有一个事件附加在整个图层上,但我不确定它是否不会将其附加到每个内部标记。我还不确定是否额外的抽象层次不会减慢速度。

I've also found Google Maps Data Layers - https://developers.google.com/maps/documentation/javascript/datalayer#add_event_handlers - it looks like there's only one event attached for the whole layer, but I'm not sure if it doesn't attach it to each of the markers internally anyway. I'm also not sure if the additional level of abstraction won't slow the things down.

是否有其他解决方案?

Are there any other solutions?

推荐答案

我们通过启用标记上的优化标记来解决所有问题。然后标记在地图画布上呈现,并且它们在DOM中不可见,这也意味着没有直接附加到它们的事件处理程序。我们通过在标记悬停时快速创建div元素来实现交互性。现在一切都很顺利。

We resolved all our problems by enabling the "optimized" flag on our markers. Then the markers are rendered on the map canvas and they aren't visible in the DOM, which also means that there are no event handlers attached to them directly. We implemented interactivity by creating div elements on the fly when a marker is hovered. Everything is much smoother now.

这篇关于所有Google Maps v3标记的常见事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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