Google maps api 3 如何在Fusion Tables图层上切换拾取多边形的颜色
我想切换多边形样式 在这里使用FT: 和快速融合表向导 我想应该是这样的(其中“Postcode district”是FT中的列标签) 但这只是将每个多边形设置为黑色Google maps api 3 如何在Fusion Tables图层上切换拾取多边形的颜色,google-maps-api-3,google-fusion-tables,Google Maps Api 3,Google Fusion Tables,我想切换多边形样式 在这里使用FT: 和快速融合表向导 我想应该是这样的(其中“Postcode district”是FT中的列标签) 但这只是将每个多边形设置为黑色 谢谢。邮政编码District的值是一个字符串,必须用单引号括起来: where: "'Postcode district' = '" + e.row['Postcode district'].value + "'", 与附加问题相关(保留多边形的突出显示状态,直到再次单击): 必须将单击多边形的状态存储在某个位置(例如,
谢谢。邮政编码District的值是一个字符串,必须用单引号括起来:
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"
}
}]);
});
演示:非常感谢-我很惊讶它会将所有其他多边形重置为默认的红色-我希望它可以使单击一次就可以更改所单击多边形的颜色,如果单击另一个多边形,然后两者都是“黑色”——点击一个黑色多边形,它就会回到原来的颜色。非常感谢Dr!我最终使用了一个数组(不确定是否有任何内置方法),但您的代码更整洁!
//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"
}
}]);
});