用多层抑制融合表infowindow

时间:2012-08-20 16:54:22

标签: google-maps-api-3 google-fusion-tables

我有一个包含两个融合表图层的地图,并使用suppressInfoWindows,这样当用户点击其他图层中的标记时,一个图层的信息窗口不会保持打开状态。使用以下代码可以正常工作:

<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>

我现在如何向infowindow添加自定义html而不是依赖Fusion Tables中的infowindow设置?我在添加suppressInfoWindows选项之前使用的代码如下,但我不知道如何以正确的格式重新添加此代码。此外,是否可以在不同的图层上为infowindows使用不同的html代码,或者两个图层是否必须使用相同的infowindow?感谢。

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>";

1 个答案:

答案 0 :(得分:0)

在我对last question的回答中查看我的示例。

Example of your map with 2 layers, 1 infowindow

实施:

  1. 抑制两个层上的infowindows
  2. 编写代码以在单击任一图层时打开共享信息窗。