Javascript 图层中每个多边形的信息窗口
通常,对于层,我们可以在onclick事件引发时生成InfoWindow。但是在这里,我在一个图层中有许多多边形。因此,正如查询中的where条件一样,我们可以获得每个条件,并使它们的样式不同。 但这里我需要的是,对于层的每个多边形,必须为onclick事件生成一个InfoWndow 下面是我为图层中的每个多边形设置样式的代码Javascript 图层中每个多边形的信息窗口,javascript,google-maps,google-fusion-tables,Javascript,Google Maps,Google Fusion Tables,通常,对于层,我们可以在onclick事件引发时生成InfoWindow。但是在这里,我在一个图层中有许多多边形。因此,正如查询中的where条件一样,我们可以获得每个条件,并使它们的样式不同。 但这里我需要的是,对于层的每个多边形,必须为onclick事件生成一个InfoWndow 下面是我为图层中的每个多边形设置样式的代码 var layer = new google.maps.FusionTablesLayer(
var layer = new google.maps.FusionTablesLayer(
{
query: {
select: 'geometry',
from: 'myTableId'
},
styles: [
{
where: "Dist_id in ('0101001') and Insert_date='25/08/2012'",
polygonOptions: { strokeColor:"#0071bc",fillColor:"#0000FF",fillOpacity:0.2,strokeWeight:2,clickable:false }
},
{
where: "Dist_id in ('0101002') and Insert_date='25/08/2012'",
polygonOptions: { strokeColor:"#0071bc",fillColor:"#FF0000",fillOpacity:0.2,strokeWeight:2,clickable:false }
},
{
where: "Dist_id in ('0101003') and Insert_date='25/08/2012'",
polygonOptions: { strokeColor:"#0071bc",fillColor:"#00FF00",fillOpacity:0.2,strokeWeight:2,clickable:false }
},
{
where: "Dist_id in ('0101004') and Insert_date='25/08/2012'",
polygonOptions: { strokeColor:"#0071bc",fillColor:"#FF00FF",fillOpacity:0.2,strokeWeight:2,clickable:false }
},
{
where: "Dist_id in ('0101005') and Insert_date='25/08/2012'",
polygonOptions: { strokeColor:"#0071bc",fillColor:"#00FFFF",fillOpacity:0.2,strokeWeight:2,clickable:false }
}
],
map:map
});
现在,如何为层的每个多边形生成信息窗口。如果希望多边形可以单击,请从选项中删除“可单击:false”
另一个选项(失去了基于FusionTablesLayer平铺渲染的优势)类似于使用Fusion Tables API v1.0查询表并将多边形渲染为本机Google Maps API v3多边形。这里我需要通过为层中的每个多边形添加“单击”事件侦听器来生成信息窗口。唯一的方法是使其可单击。也不能使用FusionTables(将单击侦听器添加到单个多边形),需要将单击侦听器添加到层中,并使用单击事件中的信息检测多边形。