我建立了以下代码来在我的站点中呈现地图。在任何区域单击地图时,会弹出一个信息窗口,其中包含一些内容,包括用于打开包含表单的网站的超链接。我想利用fancybox在叠加层中打开这个链接“表单”。我没有成功让 Fancybox 工作(版本 1.3.4),并且读到它不支持从 iframe 中调用该函数。我想知道这是否是问题所在,以及是否有其他方法可以利用fancybox(或其他叠加选项)?也许是一个事件监听器或回调 - 任何提示将不胜感激!
<style>
#map-canvas { width:850px; height:600px; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script src="http://gmaps-utility-gis.googlecode.com/svn/trunk/fusiontips/src/fusiontips.js" type="text/javascript"></script>
<script type="text/javascript">
var map;
var tableid = "1nDFsxuYxr54viD_fuH7fGm1QRZRdcxFKbSwwRjk";
var layer;
var initialLocation;
var browserSupportFlag = new Boolean();
var uscenter = new google.maps.LatLng(37.6970, -91.8096);
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
layer = new google.maps.FusionTablesLayer({
query: {
select: "'Geometry'",
from: tableid
},
map: map
});
//http://gmaps-utility-gis.googlecode.com/svn/trunk/fusiontips/docs/reference.html
layer.enableMapTips({
select: "'Contact Name','Contact Title','Contact Location','Contact Phone'",
from: tableid,
geometryColumn: 'Geometry',
suppressMapTips: false,
delay: 500,
tolerance: 8
});
;
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
//Custom Marker
var pinColor = "A83C0A";
var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + pinColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
new google.maps.Size(40, 37),
new google.maps.Point(0, 0),
new google.maps.Point(12, 35));
new google.maps.Marker({
position: initialLocation,
map: map,
icon: pinImage,
shadow: pinShadow
});
}, function() {
handleNoGeolocation(browserSupportFlag);
});
}
// Browser doesn't support Geolocation
else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function handleNoGeolocation(errorFlag) {
if (errorFlag == true) {
//Geolocation service failed
initialLocation = uscenter;
} else {
//Browser doesn't support geolocation
initialLocation = uscenter;
}
map.setCenter(initialLocation);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
通过升级到 Fancybox 版本 2 解决。