0

我想切换多边形样式

在此处使用 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"
      }
    }]);
});

但这只是将每个多边形都设置为黑色。

谢谢。

4

1 回答 1

1

的值Postcode disctrict是一个字符串,它必须用单引号括起来:

where: "'Postcode district' = '" + e.row['Postcode district'].value + "'",

与附加问题相关(保留多边形的突出显示状态,直到再次单击它):

您必须将单击的多边形的状态存储在某处(例如,在对象或数组中),然后您将能够:

  1. 切换多边形的状态
  2. 创建所有“活动”多边形的集合,并在查询中使用此集合作为IN()-condition

样本:

    //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"
      }
    }]);
  });

演示:http: //jsfiddle.net/doktormolle/ZffgF/

于 2013-09-11T14:05:01.880 回答