如何将鼠标悬停事件添加到 Google 地图 v3 中的路线?
我有一个谷歌地图,其中有几条路线是用 DirectionsRenderer 绘制的。我想通过鼠标悬停事件更改路线样式,但我不知道如何操作,可能吗? 谢谢
I have a Google maps with several routes painted with DirectionsRenderer. I want change the route style with the mouseover event, but I don't find how, is posible?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,没有办法将事件直接附加到由
DirectionsRenderer
绘制的折线。要实现此目的,您需要在顶部绘制自己的折线(因此是zIndex
),然后将mouseover
/mouseout
事件附加到该折线。下面是一个示例,说明如何完成此操作,假设您只有一条路线:
既然您说您有多个路线,那么您可能需要循环遍历
routes[]
数组并为每个路线执行一些操作。另外,我认为您无法设置特定路线的样式,因此您可能需要将每条路线保留在单独的DirectionsRenderer
中。As far as I know there's no way to attach events directly to the polyline drawn by the
DirectionsRenderer
. To accomplish this you'll instead need to draw your own polyline on top (hence thezIndex
) and then attachmouseover
/mouseout
events to that.Here's an example of how it's done, assuming you only have one route:
Since you say you have multiple routes, you may need to loop through the
routes[]
array and do something for each route. Also, I don't think you can style a specific route, so you may need to keep each route in a separateDirectionsRenderer
.