“WHERE” clauses being ignored in Fusion Table Layer in Google Maps

ⅰ亾dé卋堺 提交于 2019-11-29 16:22:57
  1. "==" doesn't work, use "="
  2. don't include the where in the main query
layer = new google.maps.FusionTablesLayer({
    map: map,
    heatmap: {
        enabled: false
    },
    query: {
        select: "geometry",
        from: "1D6d93-0iT2zUCw8IvkbpDPYDx2-jA0ZAWXi07mQD",
    },
    styles: [{
        where: "((SHIFT_ID != 1) AND (SHIFT_ID != 2))",
        polylineOptions: {
            strokeColor: "#FFFFFF",
            strokeWeight: "3"
        }
    }, {
        where: "SHIFT_ID = 1",
        polylineOptions: {
            strokeColor: "#FF0000",
            strokeWeight: "3"
        }
    }, {
        where: "SHIFT_ID = 2",
        polylineOptions: {
            strokeColor: "#ffbf00",
            strokeWeight: "3"
        }
    }]
});

proof of concept fiddle

code snippet:

var geocoder = new google.maps.Geocoder();
var map;

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  layer = new google.maps.FusionTablesLayer({
    map: map,
    heatmap: {
      enabled: false
    },
    query: {
      select: "geometry",
      from: "1D6d93-0iT2zUCw8IvkbpDPYDx2-jA0ZAWXi07mQD",
    },
    styles: [{
      where: "((SHIFT_ID != 1) AND (SHIFT_ID != 2))",
      polylineOptions: {
        strokeColor: "#FFFFFF",
        strokeWeight: "3"
      }
    }, {
      where: "SHIFT_ID = 1",
      polylineOptions: {
        strokeColor: "#FF0000",
        strokeWeight: "3"
      }
    }, {
      where: "SHIFT_ID = 2",
      polylineOptions: {
        strokeColor: "#ffbf00",
        strokeWeight: "3"
      }
    }]
  });
  geocoder.geocode({
    'address': "Winnipeg, Canada"
  }, function(results, status) {
    if (status === google.maps.GeocoderStatus.OK) {
      map.fitBounds(results[0].geometry.viewport);
    } else {
      alert('Geocode was not successful for the following reason: ' + status);
    }
  });
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>

Two suggestions:

  1. Make sure the column you're filtering on in the select query is formatted as a number, not text, since you're checking <=; and

  2. The column names are case sensitive - you have used upper case in the Fusion Table, SHIFT_ID.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!