我想切换多边形样式
在这里使用FT: https://www.google.com/fusiontables/data?docid=1jgWYtlqGSPzlIa-is8wl1cZkVIWEm_89rWUwqFU
和快速融合表向导 http://fusion-tables-api-samples.googlecode.com/svn/trunk/FusionTablesLayerWizard/src/index.html
我认为它会像(“邮政编码区”是FT中的列标签)
google.maps.event.addListener(layer_0, 'click', function(e) {
layer_0.set("styles", [{
where: "'Postcode district' = " + e.row['Postcode district'].value,
polygonOptions: {
fillColor: "#000000"
}
}]);
});
但这只是将每个多边形设置为黑色。
感谢。
答案 0 :(得分:1)
Postcode disctrict
的值是一个字符串,必须用单引号括起来:
where: "'Postcode district' = '" + e.row['Postcode district'].value + "'",
与其他问题相关(保留多边形的突出显示状态,直到再次单击它):
您必须将点击的多边形的状态存储在某处(例如,在对象或数组中),然后您将能够:
IN()
- 条件样品:
//selected will be populated on layer-cllick with the postcode and
//a boolean (true when the area is highlighted, otherwise false)
selected={};
google.maps.event.addListener(layer_0, 'click', function(e) {
var val=e.row['Postcode district'].value,
vals=[];
//update the selected-object
selected[val]=(!selected[val])?true:false;
//populate the vals-array with the selected postcodes
for(var k in selected){
if(selected[k]){
vals.push(k);
}
}
layer_0.set("styles", [{
where: "'Postcode district' IN('"+vals.join("','")+"')",
polygonOptions: {
fillColor: "#000000"
}
}]);
});