javascriptgoogle-maps-api-3google-fusion-tablesgoogle-query-language

sorting through a Fusion layer using a loop and updating each result


I'm quite new to javascript and web development in general. I've been experimenting with fusion tables and the google API and have stumped myself.

I'm looking to loop through a Javascript object and highlight any polygons in my fusion layer which have names matching those in the javascript object. Code below:

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++;
    }
}
};

so the current result I see is that only one polygon turns yellow (the last one in the array).

What i WANT to see is all the viable polygons checked in the loop turn to yellow. I'm quite sure the answer lies within the query syntax but I've been searching for half the day and I can't find anything.

Is what i want possible?

Thanks for reading!


Solution

  • Your function could simply look something like this

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