检测 Google 地图中 KML 区域的点击
我在地图上显示 KML 叠加层:
var k1 = new GGeoXml(url); map.addOverlay( k1 );
我想检测该区域何时被点击。这不起作用:
GEvent.addListener(k1, 'click', function () {alert('you clicked k1'); });
有什么想法吗?
I'm displaying a KML overlay on a map:
var k1 = new GGeoXml(url);
map.addOverlay( k1 );
I want to detect when that region has been clicked. This does not work:
GEvent.addListener(k1, 'click', function () { alert('you clicked k1'); });
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在使用 V2 Maps API。
通过检查文档,GGeoXml 类没有不引发“点击”事件及其实现的接口,GOverlay 也不公开该事件。因此,尽管理论上您绑定到该事件,但它永远不会被触发。
您将侦听器绑定到不存在的事件 - GOverlay 不会引发任何事件。
快速浏览一下,只有 GMap2 会引发鼠标事件(也许还有其他类)。您是否尝试过向其添加侦听器,然后在事件触发时检查源对象?
(请参阅 EventListener 文档)
Google Maps API不太灵活;请记住,KML 叠加层的灵活性更差,当您单击叠加层时您想做什么?
I'm assuming you're using the V2 Maps API.
Checking through the documentation, the GGeoXml class doesn't raise a 'click' event, and the interface it implements, GOverlay doesn't expose that event either. So, although you're theoretically binding to that event, it will never be triggered.
You're binding a listener to an event that doesn't exist- the GOverlay doesn't raise any events.
On a quick view, only the GMap2 raises mouse events (perhaps other classes too). Have you tried adding a listener to this and then checking the source object when the event fires?
(See EventListener docs)
The Google Maps APIs aren't very flexible; bear in mind that KML overlays are even less flexible, what do you want to do when you've clicked on the overlay?