Google Fusion Tables API

Fusion Tables Layer Example: IN query


<!DOCTYPE html>
<!--
  Copyright 2011 Google Inc. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">

    <title>Fusion Tables Layer Example: IN query</title>

    <link href="/apis/fusiontables/docs/samples/style/default.css"
        rel="stylesheet" type="text/css">
    <script type="text/javascript"
        src="http://maps.google.com/maps/api/js?sensor=false"></script>

    <script type="text/javascript">
      function initialize() {
        var tableId = '15UY2pgiz8sRkq37p2TaJd64U7M_2HDVqHT3Quw';

        var map = new google.maps.Map(document.getElementById('map-canvas'), {
          center: new google.maps.LatLng(37.5, -122.1),
          zoom: 10,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });

        var layer = new google.maps.FusionTablesLayer();
        filterMap(layer, tableId, map);

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

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

        google.maps.event.addDomListener(document.getElementById('jp-pizzeria'),
            '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: 'Address',
              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 = "'Store Name' IN (" + filter.join(',') + ')';
        }
        return where;
      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map-canvas"></div>

    <div>
      <input type="checkbox" checked="checked" name="store"
          id="johns-pizza" value="John's Pizza">
      <label>John's Pizza</label>
      <input type="checkbox" checked="checked" name="store"
          id="jjs-express" value="JJs Express">
      <label>JJs Express</label>
      <input type="checkbox" checked="checked" name="store"
          id="jp-pizzeria" value="John Paul's Pizzeria">
      <label>John Paul's Pizzeria</label>
    </div>
  </body>
</html>

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.