Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7977387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:10:59+00:00 2026-06-04T09:10:59+00:00

I am new at querying, I wanted to change the code below to query

  • 0

I am new at querying, I wanted to change the code below to query my data for the “Date” column, “population”, and “education”. In the continuation of my code, I have 3 checkboxes to filter out the data pertaining to the date, and the selector to select which color coding and data i want to represent. Live example of current code: http://4vec.com/test/2.html

So in a perfect scenario, when I deselect all the checkboxes nothing should appear, and when i select 2006 only the polygons that has 2006 should appear.

     function initialize() {
    var map = new google.maps.Map(document.getElementById('map-canvas'), {
      center: new google.maps.LatLng(30.64804,31.5023868333333),
      zoom: 5,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var layer = new google.maps.FusionTablesLayer({
      query: {
        select: 'geo',
        from: '1c-imTqDv8SfoEG_dkw41TjpquihqELzTIrs9F88'
            }
    });
    layer.setMap(map);

    initSelectmenu();
    for (column in COLUMN_STYLES) {
      break;
    }
    applyStyle(map, layer, column);
    addLegend(map);

    google.maps.event.addDomListener(document.getElementById('selector'),
        'change', function() {
          var selectedColumn = this.value;
          applyStyle(map, layer, selectedColumn);
          updateLegend(selectedColumn);
    });
    google.maps.event.addDomListener(document.getElementById('2006'),
        'click', function() {
          filterMap(layer, tableId, map);
    });

    google.maps.event.addDomListener(document.getElementById('2007'),
        'click', function() {
          filterMap(layer, tableId, map);
    });

    google.maps.event.addDomListener(document.getElementById('2008'),
        'click', function() {
          filterMap(layer, tableId, map);
    });
  }
  // Filter the map based on checkbox selection.
  function filterMap(layer, tableId, map) {
    var where = generateWhere();

    if (where) {
      if (!layer.getMap()) {
        layer.setMap(map);
      }
      layer.setOptions({
        query: {
          select: 'geo',
          from: tableId,
          where: where
        }
      });
    } else {
      layer.setMap(null);
    }
  }

  // Generate a where clause from the checkboxes. If no boxes
  // are checked, return an empty string.
  function generateWhere() {
    var filter = [];
    var stores = document.getElementsByName('store');
    for (var i = 0, store; store = stores[i]; i++) {
      if (store.checked) {
        var storeName = store.value.replace(/'/g, '\\\'');
        filter.push("'" + storeName + "'");
      }
    }
    var where = '';
    if (filter.length) {
      where = "'Date' IN (" + filter.join(',') + ')';
    }
    return where;
  }

  google.maps.event.addDomListener(window, 'load', initialize);

  // Initialize the drop-down menu
  function initSelectmenu() {
    var selectMenu = document.getElementById('selector');
    for (column in COLUMN_STYLES) {
      var option = document.createElement('option');
      option.setAttribute('value', column);
      option.innerHTML = column;
      selectMenu.appendChild(option);
    }
  }

  // Apply the style to the layer & generate corresponding legend
  function applyStyle(map, layer, column) {
    var columnStyle = COLUMN_STYLES[column];
    var styles = [];

    for (var i in columnStyle) {
      var style = columnStyle[i];
      styles.push({
        where: generateWhere(column, style.min, style.max),
        polygonOptions: {
          fillColor: style.color,
          fillOpacity: style.opacity ? style.opacity : 0.8
        }
      });
    }

    layer.set('styles', styles);
  }

  // Create the where clause
  function generateWhere(columnName, low, high) {
    var whereClause = [];
    whereClause.push("'");
    whereClause.push(columnName);
    whereClause.push("' >= ");
    whereClause.push(low);
    whereClause.push(" AND '");
    whereClause.push(columnName);
    whereClause.push("' < ");
    whereClause.push(high);
    return whereClause.join('');
  }

  // Initialize the legend
  function addLegend(map) {
    var legendWrapper = document.createElement('div');
    legendWrapper.id = 'legendWrapper';
    legendWrapper.index = 1;
    map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(
        legendWrapper);
    legendContent(legendWrapper, column);
  }

  // Update the legend content
  function updateLegend(column) {
    var legendWrapper = document.getElementById('legendWrapper');
    var legend = document.getElementById('legend');
    legendWrapper.removeChild(legend);
    legendContent(legendWrapper, column);
  }

  // Generate the content for the legend
  function legendContent(legendWrapper, column) {
    var legend = document.createElement('div');
    legend.id = 'legend';

    var title = document.createElement('p');
    title.innerHTML = column;
    legend.appendChild(title);

    var columnStyle = COLUMN_STYLES[column];
    for (var i in columnStyle) {
      var style = columnStyle[i];

      var legendItem = document.createElement('div');

      var color = document.createElement('span');
      color.setAttribute('class', 'color');
      color.style.backgroundColor = style.color;
      legendItem.appendChild(color);

      var minMax = document.createElement('span');
      minMax.innerHTML = style.min + ' - ' + style.max;
      legendItem.appendChild(minMax);

      legend.appendChild(legendItem);
    }

    legendWrapper.appendChild(legend);
  }

  google.maps.event.addDomListener(window, 'load', initialize);
</script>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:11:00+00:00Added an answer on June 4, 2026 at 9:11 am

    You have several minor problems in your code:

    • You used the variable tableId for the click events, but never set it
    • There are two functions called generateWhere(), I changed the second one to generateStyleConditon()
    • And finally I suggest to let the layer on the map all the time, just make sure that no records are retrieved when the checkboxes are unchecked.

    The updated filterMap() and generateWhere() functions look like that:

    // Filter the map based on checkbox selection.
    function filterMap(layer, tableId, map) {
        var where = generateWhere();
        layer.setOptions({
            query: {
                select: 'geo',
                from: tableId,
                where: where
            },
            map: map
        });
    }
    
    // Generate a where clause from the checkboxes. If no boxes
    // are checked, return an empty string.
    function generateWhere() {
        var yearFilter = [];
        var years = document.getElementsByName('years');
        for (var i = 0, year; year = years[i]; i++) {
            if (year.checked) {
                yearFilter.push("'" + year.value + "'");
            }
        }
        //if where clause is not set, make sure no value is selected
        var where = '';
        var yearStr = yearFilter.join(',');
        if (!yearStr) {
            yearStr = "''";
        }
        where = "'Date' IN (" + yearStr + ")";
        return where;
    }
    

    I put the updated code on jsFiddle: http://jsfiddle.net/odi86/sGMSq/

    If you want to filter with further columns just add these in the generateWhere() function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataServiceContext querying my WCF Data Service: service = new DataServiceContext(new Uri(SvcUrl));
I need to update some AD querying code and want to use the new
I am pretty new to using LINQ and have been trying it out querying
I'm new to database and querying in MySql. I have a table in my
I'm using Linq querying today's date. There is one column in my table called
I'm new to Django and I'm stuck at querying through multiple sets. I have
I am querying information from Active Directory . I have code that works, but
I'm new in using prepared statements for querying data from the database and I'm
I'm querying our Active Directory with the following code: using (DirectorySearcher search = new
I'm new to Java and just getting into querying databases. So far I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.