" WHERE"子图在Google地图中的Fusion Table Layer中被忽略 [英] "WHERE" clauses being ignored in Fusion Table Layer in Google Maps

查看:118
本文介绍了" WHERE"子图在Google地图中的Fusion Table Layer中被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过API在Google地图中使用Google Fusion表格作为图层。只需使用FusionTableLayer()将图层添加到Google Map即可正常工作。我可以看到地图和所有。当我尝试对选择查询或样式部分应用过滤器(即where子句)时,fun开始。过滤器不起作用!它不会抛出任何错误。地图不断运作。但是结果集不会被滤除 - 就好像where子句甚至不在那里一样。样式部分使用'where'子句的相同症状。它完全被忽略。我有三种不同的样式,我想根据过滤条件应用。所有这些都被忽略。奇怪的是,样式块中列出的最后一个样式部分应用于融合表层的所有要素。我通过切换周围的部分来验证它。我尝试用像col10这样的引用替换实际的字段名称,但这没有什么区别。



我错过了什么?我如何在我的FusionTableLayer中启用使用WHERE子句,以便它们既可以在Select查询中使用,也可以在Styles部分中使用?



注意:在下面的代码片段,(/)评论插入这篇文章。这些评论不存在于我正在开发的实际页面/代码中。

  layer = new google.maps.FusionTablesLayer({ b $ b map:map,
heatmap:{enabled:false},
query:{
select:col11,
from:1D6d93-0iT2zUCw8IvkbpDPYDx2-jA0ZAWXi07mQD,
//在select查询中的以下过滤器不起作用!
//我用实际字段名称替换col10(shift_id),但仍然从表中返回所有值
其中:col10< = 3
},
styles:[{
// this where clause does not effect。我试过用col10替换shift_id。
where:((shift_id! = 1)AND(shift_id!= 2)),
polylineOptions:{
strokeColor:#FFFFFF,
strokeWeight:3}
},{
// this where子句没有效果我试着用col10替换shift_id
其中:shift_id == 1,
polylineOptions:{
strokeColor:#FF0000,
strokeWeight:3}
},{
//此where子句无效。我试过用col10替换shift_id。
//最后列出的这三个块中的哪一个都是应用于图层的那个块。
其中:shift_id == 2,
polylineOptions:{
strokeColor:#ffbf00,
strokeWeight:3}
}]
});


解决方案


  1. ==不工作,使用=

  2. 不包括主查询中的位置





  layer = new google.maps.FusionTablesLayer({
map:map,
heatmap:{
已启用:false
},
查询:{
select:geometry,
from:1D6d93-0iT2zUCw8IvkbpDPYDx2-jA0ZAWXi07mQD,
},
styles :[{
where:((SHIFT_ID!= 1)AND(SHIFT_ID!= 2)),
polylineOptions:{
strokeColor:#FFFFFF,
strokeWeight :3
}
},{
其中:SHIFT_ID = 1,
polylineOptions:{
strokeColor:#FF0000,
strokeWeight:3
}
},{
其中:SHIFT_ID = 2,
polylineOptions:{
strokeColor:#ffbf00,
strokeWeight:3
}
}]
});

概念证明小提琴



代码段:

  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}},{其中:SHIFT_ID = 1,polylineOptions:{strokeColor: #FF0000,strokeWeight:3}},{其中:SHIFT_ID = 2,polylineOptions:{strokeColor:#ffbf00,strokeWeight:3}}]}); geocoder.geocode({'address':加拿大温尼伯},函数(结果,状态){if(status === google.maps.GeocoderStatus.OK){map.fitBounds(results [0] .geometry.viewport );} else {alert('Geocode由于以下原因不成功:'+ status);}});} google.maps.event.addDomListener(window,load,initialize);    

html,body,#map_canvas {height:100%;宽度:100%; margin:0px; < script src =https://


I am trying to use a Google Fusion table as a layer in Google maps via API. Just adding the layer to the Google Map using FusionTableLayer() works fine. I can see the map and all. The "fun" begins when I try to apply a filter (i.e. a "where clause") to the select query or to the Styles section. The filters just do not work! It does not throw any error. Map keeps on working. But the result set is not filtered down--as if the where clause wasn't even there. The same symptoms for the 'where' clause used for the Styles section. It is completely ignored. I have three different styles, which I want applied based on filter conditions. All of the those are ignored. The strange thing is that the very last style section listed in the Styles block gets applied to ALL features in the fusion table layer. I verified it by switching the sections around. I tried replacing the actual field names by the references like "col10", but that didn't make any difference.

What am I missing? How can I "enable" the use of WHERE clauses in my FusionTableLayer so that they get applied both in the Select query, and also in the Styles sections?

Note: in the code snippet below, the (//) comments were inserted for this post. These comments do not exist in the actual page/code I am developing.

  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. "==" 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>

这篇关于&QUOT; WHERE&QUOT;子图在Google地图中的Fusion Table Layer中被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆