使用多层压缩融合表infowindow [英] Suppress fusion table infowindow with multiple layers
问题描述
我有一个包含两个融合表图层的地图,并使用 suppressInfoWindows
,以便当用户从另一个图层上点击标记时,一个图层的infowindow不会打开层。这可以正常使用下面的代码:
I have a map with two fusion tables layers and am using suppressInfoWindows
so that an infowindow from one layer is not left open when a user clicks on a marker from the other layer. This works fine using the below code:
<script type="text/javascript">
var map;
var infowindow;
var layer;
var tableid = MY FUSION TABLE ID;
var layer2;
var tableid2 = MY FUSION TABLE ID;
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
});
infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(map, "click", function() { infoWindow.close(); });
layer = new google.maps.FusionTablesLayer(tableid, {suppressInfoWindows:true});
layer.setQuery("SELECT 'Country Geometry' FROM " + tableid);
layer.setMap(map);
google.maps.event.addListener(layer, "click", openIW);
layer2 = new google.maps.FusionTablesLayer(tableid2, {suppressInfoWindows:true});
layer2.setQuery("SELECT 'Site Location' FROM " + tableid2);
layer2.setMap(map);
google.maps.event.addListener(layer2, "click", openIW);
}
function openIW(FTevent) {
// infoWindow.setContent(FTevent.infoWindowHtml);
// infoWindow.setPosition(FTevent.latLng);
infoWindow.setOptions(
{
content: FTevent.infoWindowHtml,
position: FTevent.latLng,
pixelOffset: FTevent.pixelOffset
});
infoWindow.open(map);
}
</script>
现在如何将自定义html添加到infowindow,而不是依赖Fusion Tables中的infowindow设置?我在添加 suppressInfoWindows
选项之前使用的代码如下,但我不确定如何现在以正确的格式将其添加回来。另外,是否可以在不同的图层上使用不同的html代码,或者两个图层都使用相同的infowindow?谢谢。
How can I now add custom html to the infowindow rather than rely on the infowindow settings from Fusion Tables? The code I was using before adding the suppressInfoWindows
option was as follows, but I'm not sure how to now add this back in, in the right format. Also, is it possible to use different html code for the infowindows on different layers, or must both layers use the same infowindow? Thanks.
e.infoWindowHtml = "<div id='SiteInfo' class='googft-info-window' style='font-family: sans-serif; width: 500px; height: 300px; overflow: auto;'>\
<b>" + e.row['Site Name'].value + "</b><br />\
</div></div>";
推荐答案
=https://stackoverflow.com/questions/12015092/including-script-elements-in-a-custom-infowindow>最后一个问题。
See my example in my answer to your last question on this.
执行:
To implement:
- 禁止两层上的infowindows
- 编写代码以在单击任一图层时打开共享infowindow。
这篇关于使用多层压缩融合表infowindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!