如何在Fusion Tables图层上切换拾取的多边形的颜色 [英] How to toggle the colour of picked polygons on a Fusion Tables layer
问题描述
我想切换多边形样式
在这里使用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
}
}]);
});
但是,将每个多边形设置为黑色。
谢谢。
其中:''邮编区'='+ e .row ['Postcode district']。value +',
与附加问题相关(保留多边形的突出显示状态,直到它再次被点击):
您必须存储点击的多边形的状态(例如在一个对象或数组中),那么您将能够:
$ b
- 切换多边形状态
- 创建一个包含所有活动多边形的集合,并在查询中使用此集合以获取
IN()
-condition
示例:
//选中的图层将填充到图层上 - 用邮编打开邮件和
//一个布尔值(当区域突出显示时为true,否则为false)
selected = {};
google.maps.event.addListener(layer_0,'click',function(e){
var val = e.row ['Postcode district']。value,
vals = [];
//更新所选对象
selected [val] =(!selected [val])?true:false;
/ /使用选定的邮政编码填充vals数组
for(var k in selected){
if(selected [k]){
vals.push(k);
}
layer_0.set(styles,[{
where:''Postcode district'IN(''+ vals.join(',')+ '),
polygonOptions:{
fillColor:#000000
}
}]);
});
演示: http://jsfiddle.net/doktormolle/ZffgF/
I want to toggle polygon styles
Using the FT here: https://www.google.com/fusiontables/data?docid=1jgWYtlqGSPzlIa-is8wl1cZkVIWEm_89rWUwqFU
and the quick fusion table wizard http://fusion-tables-api-samples.googlecode.com/svn/trunk/FusionTablesLayerWizard/src/index.html
I thought it would be something like (where "Postcode district" is the column label in 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"
}
}]);
});
but that is just setting every single polygon to black.
Thanks.
The value of Postcode disctrict
is a string, it has to be enclosed by single-quotes:
where: "'Postcode district' = '" + e.row['Postcode district'].value + "'",
Related to the additional question(preserve the highlighted status of the polygon until it will be clicked again):
You must store the status of the clicked polygon somewhere(e.g. in an object or array), then you'll be able to :
- toggle the status of a polygon
- create a collection of all "active" polygons and use this collection in the query for a
IN()
-condition
Sample:
//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"
}
}]);
});
Demo: http://jsfiddle.net/doktormolle/ZffgF/
这篇关于如何在Fusion Tables图层上切换拾取的多边形的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!