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 8575847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:47:16+00:00 2026-06-11T19:47:16+00:00

I’m trying to create a map using Google Fusion Tables with two layers, one

  • 0

I’m trying to create a map using Google Fusion Tables with two layers, one of which I want to add a style to. I also have multiple columns, and I want to switch between these columns using a drop-down menu. So far I managed to do the latter, but I’m stuck trying to add a second layer.

The map I have now shows the ratio of girls:boys in schools in the 170 districts in Ghana. With the drop down menu I can switch between primary school and junior high. Now I want to add a layer with the regional borders.

In the documentation I saw this:

You can use the Maps API to add up to five Fusion Tables layers to a
map, one of which can be styled with up to five styling rules.

Which is pretty much exactly what I want, but I also keep the drop-down menu. I’ve recently started using Fusion Tables and was hoping someone could help me.

The ID of the layer I want to add: 1_0rcifQnnNpLV1VjTPyzDZSF3LHp-7rowzrXM78

And the code of the working map:

PS: I’m a total newbie and used this map made by the Guardian as a basis. I got rid of everything I didn’t think I needed, but there might be some unnecessary stuff left in the code.

    <!DOCTYPE html>
<html lang="en" itemscope itemtype="http://schema.org/Article">

<head>

                <title>Gender Parity Index | Education | 2011</title>
        <meta charset="utf-8" />

                            <style type="text/css">
  body { font-family: Arial, sans-serif; }
  #map_canvas { height: 600px; width:575px; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript" id="script">

var center = new google.maps.LatLng(7.972198, -0.716284);
var zoom = 7;
var legend_width = '150px';
var tableid = '12GLQaH4wvwByxBk4W7UHkJTr99vsxymCTYHmkXs';
var location_column = 'geometry';
var colors = ['#CA0020','#F4A582','#F7F7F7','#92C5DE','#0571B0']; 
var columns = {
  'Gender parity index at primary education': [
    {
      'min': 0.6,
      'max': 0.8,
      'color': '#CA0020'
    },
    {
      'min': 0.8,
      'max': 0.95,
      'color': '#F4A582'
    },
    {
      'min': 0.95,
      'max': 1.05,
      'color': '#F7F7F7'
    },
    {
      'min': 1.05,
      'max': 1.2,
      'color': '#92C5DE'
    }
  ],
  'Gender parity index at junior high school education': [
     {
      'min': 0.6,
      'max': 0.8,
      'color': '#CA0020'
    },
    {
      'min': 0.8,
      'max': 0.95,
      'color': '#F4A582'
    },
    {
      'min': 0.95,
      'max': 1.05,
      'color': '#F7F7F7'
    },
    {
      'min': 1.05,
      'max': 1.2,
      'color': '#92C5DE'
    },
    {
      'min': 1.2,
      'max': 1.6,
      'color': '#0571B0'
    }

  ]
}

var map, layer, geocoder;

function initialize() {

  map = new google.maps.Map(document.getElementById('map_canvas'), {
    center: center,
    zoom: zoom,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  var style = [ { stylers: [ { invert_lightness: true } ] },{ featureType: "road.highway", stylers: [ { hue: "#00e5ff" } ] },{ featureType: "poi.park", stylers: [ { visibility: "off" } ] },{ featureType: "landscape.natural", stylers: [ { visibility: "on" } ] },{ featureType: "water", stylers: [ { color: "#080808" } ] },{ featureType: "landscape.natural", stylers: [ { color: "#202020" } ] },{ featureType: "administrative.province", elementType: "labels", stylers: [ { visibility: "on" } ] },{ featureType: "administrative.locality", elementType: "labels", stylers: [ { visibility: "on" } ] },{ featureType: "administrative.country", elementType: "labels", stylers: [ { visibility: "off" } ] },{
  featureType: 'road',
  elementType: 'all',
  stylers: [
  { saturation: -99 }
  ]
  } ];

  geocoder = new google.maps.Geocoder();

  var styledMapType = new google.maps.StyledMapType(style, {
    map: map,
    name: 'Styled Map'
  });

  map.mapTypes.set('map-style', styledMapType);
  map.setMapTypeId('map-style');


  layer = new google.maps.FusionTablesLayer({
    query: {
      select: location_column,
      from: tableid
    }
  });
  layer.setMap(map);

  init_selectmenu();
  addStyle(getKey());


}



function getKey() {
  for(key in columns) {
    return key;
  }
}

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

function addStyle(column) {
  var defined_styles = columns[column];
  var styles = new Array();

  for(defined_style in defined_styles) {
    var style = defined_styles[defined_style];
    styles.push({
      where: generateWhere(column, style.min, style.max),
      polygonOptions: {
        fillColor: style.color,
        fillOpacity: 0.9,
        strokeOpacity: 0.50,
        strokeColor: "#f3f3f3"
      }
    });

  }

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

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

// Create the legend with the corresponding colors
function updateLegend(column) {
  var legendDiv = document.createElement('div');
  var legend = new Legend(legendDiv, column);
  legendDiv.index = 1;
  map.controls[google.maps.ControlPosition.RIGHT_TOP].pop();
  map.controls[google.maps.ControlPosition.RIGHT_TOP].push(legendDiv);
}

// Generate the content for the legend
function Legend(controlDiv, column) {
  controlDiv.style.padding = '10px';
  var controlUI = document.createElement('div');
  controlUI.style.backgroundColor = 'white';
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '1px';
  controlUI.style.width = legend_width;
  controlUI.title = 'Legend';
  controlDiv.appendChild(controlUI);
  var controlText = document.createElement('div');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.fontSize = '12px';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';

  controlText.innerHTML = legendContent(column);
  controlUI.appendChild(controlText);
}

function legendContent(column) {
  var defined_styles = columns[column];

  // Generate the content for the legend using colors from object
  var controlTextList = new Array();
  controlTextList.push('<p><b>');
  controlTextList.push(column);
  controlTextList.push('</b></p>');
  for(defined_style in defined_styles) {
    var style = defined_styles[defined_style];
    controlTextList.push('<div style="background-color: ');
    controlTextList.push(style.color);
    controlTextList.push('; height: 20px; width: 20px; margin: 3px; float: left;"></div>');
    controlTextList.push(style.min);
    controlTextList.push(' to ');
    controlTextList.push(style.max);
    controlTextList.push('<br style="clear: both;"/>');
  }

  controlTextList.push('<br />');
  return controlTextList.join('');
}

</script>
</head>

<body onload="initialize();">

<select onchange="addStyle(this.value);" id="selector" style="font-size: 16px"></select>

<div id="map_canvas"></div>

                        </div>
    <script>
        // send the query string to the iFrame
        (function() {
            var interactive = jQ('#interactive iframe');
            if (interactive.length > 0) {
                var qs = window.location.search;
                interactive[0].src = interactive[0].src + qs;
            }
        })();
    </script>
</div>
            <div id="related">

</script>

</script>

</body>
</html>
  • 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-11T19:47:18+00:00Added an answer on June 11, 2026 at 7:47 pm

    Just add the second layer at the end of your initialize() method like that:

    function initialize() {
        // ... all the other stuff ...
    
        borderLayer = new google.maps.FusionTablesLayer({
            query: {
                select: 'geometry',
                from: '1_0rcifQnnNpLV1VjTPyzDZSF3LHp-7rowzrXM78'
            }
        });
        borderLayer.setMap(map);
    }
    

    See the working example of your code with the second layer on jsFiddle.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I'm trying to select an H1 element which is the second-child in its group
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.