开发者

Detect click on KML region in Google Maps

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 () {开发者_StackOverflow alert('you clicked k1'); });

Any ideas?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜