【发布时间】:2012-12-06 17:03:50
【问题描述】:
我需要知道点击地图数据链接的时间(见图 1,右下角)。 当地图数据窗口打开时,它被覆盖的元素隐藏(图 2)。所以我必须在收到打开窗口的触发器时隐藏它们,并在关闭时重新显示它们。
我已经尝试捕获如下地图画布下的所有点击事件,但是当我点击“地图数据”时我没有被触发
$("googleMapCanvas a").click(function() {
alert("link under map clicked");
});
有什么想法吗?
图片 1
图片 2
更新
这是克里斯蒂安回答后我的功能代码
<div id="googleMapCanvas">
</div>
<div id="currentLocationBubbleContainer">
...
</div>
<script>
$("#googleMapCanvas").on('click', 'a', function(event) {
var host = event.target.host;
var isGoogleExternalLink = false;
if (host != null && host.search(".google.") != -1 ){
isGoogleExternalLink = true;
}
//It's not enough to check the innerHTML because it's content varies
//depending on the device langage, so in stead I check if it is not
//a click on the google logo, or on the terms of use which are external links
if (event.target.innerHTML == "Map Data" || ! isGoogleExternalLink ){
hideCurrentLocationBubble();
}
});
//Close button of Map Data window
$("#googleMapCanvas").on('click', 'img', function(event) {
if (event.target.src == "https://maps.gstatic.com/mapfiles/transparent.png"){
showCurrentLocationBubble();
}
});
</script>
【问题讨论】:
标签: javascript google-maps google-maps-api-3