【发布时间】:2012-08-18 01:30:45
【问题描述】:
我正在使用 Google Maps API 创建一个包含融合表内容的自定义 InfoWindow。我还想在 InfoWindow 中嵌入来自外部站点的内容,但无法使代码正常工作。来自外部站点的嵌入代码是:
<link type="text/css" rel="stylesheet" media="all" href="http://www.foodsecurityportal.org/sites/all/modules/tic_countries/tic_countries_widget.css" />
<div class="web-widgets-inline" id="web_widgets_inline_country_news_36">
<script src="http://www.foodsecurityportal.org/country/widget/36"></script>
</div>
我正在尝试将其嵌入到我的 InfoWindow 中,如下所示,在我的融合表中引用了外部 URL 和 ID。我的问题是我无法让内联 </script> 元素发挥作用。将其完整包含为</script> 会阻止地图加载,同时尝试将其分解(例如"<"+"/script>"(如下面的sn-p)会阻止嵌入式脚本运行。
有什么想法吗?如果可能的话,请给出完整的解释,因为我是新手。非常感谢。
function initialize() {
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(10, 30),
zoom: 2,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
layer = new google.maps.FusionTablesLayer(tableid);
layer.setQuery("SELECT 'Country Geometry' FROM " + tableid);
layer.setMap(map);
layer2 = new google.maps.FusionTablesLayer(tableid2);
layer2.setQuery("SELECT 'Site Location' FROM " + tableid2);
layer2.setMap(map);
google.maps.event.addListener(layer, 'click', function(e) {
e.infoWindowHtml = "<div class='googft-info-window' style='font-family: sans-serif; width: 500px; height: 300px; overflow: auto;'>"
e.infoWindowHtml += "<b>" + e.row['Site Name'].value + "</b><br />"
e.infoWindowHtml += "<img src=" + e.row['Image URL'].value + "><br />"
e.infoWindowHtml += "<link type=text/css rel=stylesheet media=all href=http://www.foodsecurityportal.org/sites/all/modules/tic_countries/tic_countries_widget.css />"
e.infoWindowHtml += "<div class=" + e.row['IFPRI Ref1'].value + " style='width: 95%; height: 150px; overflow: auto;'>"
e.infoWindowHtml += "<script src=" + e.row['IFPRI Ref2'].value + "type='text/javascript'><"+"/script>"
e.infoWindowHtml += "</div></div>"
});
【问题讨论】:
标签: google-maps-api-3 google-fusion-tables