检测 Google 地图中 KML 区域的点击

发布于 2024-10-08 07:08:02 字数 208 浏览 0 评论 0原文

我在地图上显示 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦明 2024-10-15 07:08:02

我假设您正在使用 V2 Maps API。

通过检查文档,GGeoXml 类没有不引发“点击”事件及其实现的接口,GOverlay 也不公开该事件。因此,尽管理论上您绑定到该事件,但它永远不会被触发。

您将侦听器绑定到不存在的事件 - GOverlay 不会引发任何事件。

快速浏览一下,只有 GMap2 会引发鼠标事件(也许还有其他类)。您是否尝试过向其添加侦听器,然后在事件触发时检查源对象?

  var k1 = new GGeoXml(url);
  map.addOverlay(k1);
  GEvent.addListener(map, 'click', callback);

  function (overlay, latlng) callback
  {
    if (overlay == k1) alert('you clicked on k1');
  }

(请参阅 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?

  var k1 = new GGeoXml(url);
  map.addOverlay(k1);
  GEvent.addListener(map, 'click', callback);

  function (overlay, latlng) callback
  {
    if (overlay == k1) alert('you clicked on k1');
  }

(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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文