javascript – Google地图中的Fusion Table Layer中忽略了“WHERE”子句
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Google地图中的Fusion Table Layer中忽略了“WHERE”子句,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3459字,纯文字阅读大概需要5分钟。
内容图文
![javascript – Google地图中的Fusion Table Layer中忽略了“WHERE”子句](/upload/InfoBanner/zyjiaocheng/703/4be472e7f8994908bff14f0f689f81c4.jpg)
我正在尝试通过API将Google Fusion表格用作Google地图中的图层.只需使用FusionTableLayer()将图层添加到Google地图就行了.我可以看到地图和所有.当我尝试将过滤器(即“where子句”)应用于选择查询或样式部分时,“乐趣”开始.过滤器不起作用!它不会抛出任何错误.地图继续工作.但是结果集不会被过滤掉 – 好像where子句甚至不存在.用于“样式”部分的“where”子句的相同症状.它完全被忽略了.我有三种不同的样式,我想根据过滤条件应用它.所有这些都被忽略了.奇怪的是,样式块中列出的最后一个样式部分将应用于融合表层中的所有要素.我通过切换部分来验证它.我尝试用“col10”之类的引用替换实际的字段名称,但这没有任何区别.
我错过了什么?如何在FusionTableLayer中“启用”WHERE子句的使用,以便它们既可以在Select查询中应用,也可以在Styles部分中应用?
注意:在下面的代码段中,为此帖子插入了(//)注释.我正在开发的实际页面/代码中不存在这些注释.
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" }
}]
});
解决方法:
>“==”不起作用,使用“=”
>不要在主查询中包含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"
}
}]
});
代码段:
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>
内容总结
以上是互联网集市为您收集整理的javascript – Google地图中的Fusion Table Layer中忽略了“WHERE”子句全部内容,希望文章能够帮你解决javascript – Google地图中的Fusion Table Layer中忽略了“WHERE”子句所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。