多层谷歌融合表启用MapTips

时间:2012-11-13 21:10:31

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

我一直在研究下面的代码已经有一段时间了,当鼠标悬停在标记上时,无法设法让MapTips为标记工作。

<html>
<head>
<style>
  #map_canvas { width: 500px; height: 400px; }
</style>
<link href="../stylesheet.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://gmaps-utility-gis.googlecode.com/svn/trunk/fusiontips/src/fusiontips_compiled.js"></script>
<script type="text/javascript">
var map;

var layer;
var tableid = 5463275;

var layer2;
var tableid2 = 5492676;

function initialize() {
  map = new google.maps.Map(document.getElementById('map_canvas'), {
    center: new google.maps.LatLng(51.500000, -0.090000),
    zoom: 9,
    mapTypeControl: false,
    mapTypeId: google.maps.MapTypeId.TERRAIN
  });

  layer = new google.maps.FusionTablesLayer(tableid, {
  suppressInfoWindows: true
});
  layer.setQuery("SELECT 'geometry' FROM " + tableid);
  layer.setMap(map);

  layer2 = new google.maps.FusionTablesLayer(tableid2);
  layer2.setQuery("SELECT 'Full Address' FROM " + tableid2);
  layer2.setMap(map);
  layer2.enableMapTips({
                select: "'Site Name'",
                from: tableid, 
                geometryColumn: 'Full Address', 
                suppressMapTips: false, 
                delay: 100, 
                tolerance: 6 });

  var legendDiv = document.createElement('DIV');
  var legend = new Legend(legendDiv, map);
  legendDiv.index = 1;
  map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(legendDiv);
}


</script>

</head>
<body onLoad="initialize();">

<div id="map_canvas"></div>
</body>
</html>​

地图由两个融合表格层组成 - 我已链接到包含以下标记数据的表格:

Fusion Table for Markers

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

您错过了'Full Address'周围的引号,因此查询未正确编码并引发错误。我放了一个working example on jsFiddle

以下是更正的部分:

layer2.enableMapTips({
    select: "'Site Name'",
    from: tableid, 
    geometryColumn: "'Full Address'", 
    suppressMapTips: false, 
    delay: 100, 
    tolerance: 6 
});

首先,我尝试更新您的代码以使用加密的表ID,但似乎FusionTips script尚不支持。