Fusion Table 层 Google 地图中的 "WHERE" 个子句被忽略

"WHERE" clauses being ignored in Fusion Table Layer in Google Maps

我正在尝试通过 API 使用 Google Fusion table 作为 Google 地图中的图层。只需使用 FusionTableLayer() 将图层添加到 Google 地图即可。我可以看到地图和所有东西。当我尝试将过滤器(即 "where clause")应用于 select 查询或样式部分时,"fun" 开始。过滤器根本不起作用!它不会抛出任何错误。地图继续工作。但是结果集没有被过滤掉——就好像 where 子句根本不存在一样。 'where' 子句的相同症状用于 Styles 部分。它被完全忽略了。我有三种不同的样式,我想根据过滤条件应用它们。所有这些都被忽略了。奇怪的是,样式块中列出的最后一个样式部分被应用于融合 table 层中的所有特征。我通过切换部分来验证它。我尝试用 "col10" 之类的引用替换实际的字段名称,但这没有任何区别。

我错过了什么?我如何 "enable" 在我的 FusionTableLayer 中使用 WHERE 子句,以便在 Select 查询和样式部分中应用它们?

注意:在下面的代码片段中,为此 post 插入了 (//) 注释。我正在开发的实际 page/code 中不存在这些注释。

  layer = new google.maps.FusionTablesLayer({
  map: map,
  heatmap: { enabled: false },
  query: {
     select: "col11",
     from: "1D6d93-0iT2zUCw8IvkbpDPYDx2-jA0ZAWXi07mQD",
     //the following filter in select query does not work! 
     //I replaced col10 with actual field name (shift_id) but still EVERYTHING from the table is returned
     where: "col10 <= 3" 
  },
        styles: [{
          //this where clause has no effect. I've tried replacing shift_id with col10.
          where: "((shift_id != 1) AND (shift_id != 2))",
          polylineOptions: {
            strokeColor: "#FFFFFF",
            strokeWeight: "3"  }
        }, {
          //this where clause has no effect. I've tried replacing shift_id with col10.
          where: "shift_id == 1",
          polylineOptions: {
            strokeColor: "#FF0000",
            strokeWeight: "3"  }
        }, {
          //this where clause has no effect. I've tried replacing shift_id with col10.
          //whichever of these three blocks is listed last is the one that gets applied to the layer.
          where: "shift_id == 2",
          polylineOptions: {
            strokeColor: "#ffbf00",
            strokeWeight: "3"  }
        }] 
});

两条建议:

  1. 确保您在 select 查询中过滤的列的格式为数字,而不是文本,因为您正在检查 <=;和

  2. 列名称区分大小写 - 您在 Fusion Table、SHIFT_ID.

  3. 中使用了大写
  1. “==”不起作用,使用“=”
  2. 不要在主查询中包含 where
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

代码片段:

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>