首页 > 解决方案 > 使用循环对 Fusion 层进行排序并更新每个结果

问题描述

一般来说,我对 javascript 和 web 开发很陌生。我一直在试验融合表和谷歌 API,并难住了自己。

我正在寻找遍历 Javascript 对象并突出显示我的融合层中名称与 javascript 对象中的名称匹配的任何多边形。下面的代码:

function fillcolour(match){ // ---- match is an array within the javascript object

var limit = 0; // --- currently limiting the responses to 5. There are 126 in each response array and I know within the first 5 there are 3 matches.

 var options = {
      styles : []
    };
var styles = [];

for (x in match) {    //---- getting each name in match. from alerts and console log I know this returns 5 results, three of which should satisfy the requirements below. 
    if(limit < 5){

        PolygonLayer.setOptions({
                query: {
                    select: "shape",
                    from: mapTable,
                    where: "'name' = '" + x + "'"
                }
            });
      options.styles.push({
        polygonOptions: {
          fillColor: "#FFF000",
        }
      });
        PolygonLayer.setOptions(options);
        limit++;
    }
}
};

所以我看到的当前结果是只有一个多边形变成黄色(数组中的最后一个)。

我想看到的是循环中检查的所有可行多边形都变成黄色。我很确定答案在查询语法中,但我已经搜索了半天,但什么也找不到。

我想要的可能吗?

谢谢阅读!

标签: javascriptgoogle-maps-api-3google-fusion-tablesgoogle-query-language

解决方案


您的函数可能看起来像这样

function fillcolour(match){
    PolygonLayer.setOptions({
        styles: [{
            where: "'name' in ('" + match.join("','") + "')"
            polygonOptions: {
                fillColor: "#FFF000"
            }
        }]          
    })
}

推荐阅读