函数更新地图谷歌地图 API
function updateMap for Google Maps API
我在谷歌地图API中的updateMap功能上遇到了问题...特别是使用多个"else if"语句来查询数据。我的代码如下。第一个"如果"有效,第一个"else if"有效,最后一个"else"用于更新我的地图,第二个"else if"不会更新我的地图。用户通过下拉菜单传递"类型"和"Visibilit2"的值。
有什么建议可以解决这个问题吗?地图需要根据来自其中之一、两者或两者都不是的用户值进行更新,方法是将下拉菜单设置为空白(这是最后一个 else 的考虑(。理想情况下,我想将其扩展为包括三个或四个额外的查询选项。数据存储在融合表中。
google.maps.event.addDomListener(document.getElementById('Type'), 'change', function(){updateMap(layer, tableID, locationColumn);});
google.maps.event.addDomListener(document.getElementById('Visibilit2'), 'change', function(){updateMap(layer, tableID, locationColumn);});
function updateMap(layer, tableID, locationColumn){
var Type = document.getElementById('Type').value;
var Visibilit2 = document.getElementById('Visibilit2').value
if (Type, Visibilit2){
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Type = '" + Type + "' AND Visibilit2 = '" + Visibilit2 + "'"
}
});
} else if (Type){
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Type = '" + Type + "'"
}
});
} else if (Visibilit2){
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Visibilit2 = '" + Visibilit2 + "'"
}
});
}
else {
layer.setOptions({
query: {
select: locationColumn,
from: tableID
}
});
}
}
好的,所以我在发布后几乎立即解决了它。但!我不确定这是最有效的方法,如果我添加更多变量,我认为它不会解决问题。代码如下,我非常欢迎任何更好的方法的建议。我只是在第一个 if 中嵌套了一个 if,我仍然对为什么多个"else if"不起作用感到困惑......
谢谢!
function updateMap(layer, tableID, locationColumn){
var Type = document.getElementById('Type').value;
var Visibilit2 = document.getElementById('Visibilit2').value
if (Type){
if (Visibilit2){
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Type = '" + Type + "' AND Visibilit2 = '" + Visibilit2 + "'"
}
});
} else {
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Type = '" + Type + "'"
}
});
}
} else if (Visibilit2){
layer.setOptions({
query: {
select: locationColumn,
from: tableID,
where: "Visibilit2 = '" + Visibilit2 + "'"
}
});
}
else {
layer.setOptions({
query: {
select: locationColumn,
from: tableID
}
});
}
}
相关文章:
- 谷歌地图API v3不适用于移动浏览器或PhoneGap
- 谷歌地图JS API+JSON-多个标记没有显示
- 标记的实时更新,无需加载页面谷歌地图API V3
- 覆盖在赢得'不允许点击下面的标记,谷歌地图api v3
- 谷歌地图Api和JS代码不工作
- 谷歌地图API-InfoBubble赢得't关闭-关闭()不会'不起作用
- 如何在多承诺链中处理谷歌地图API V3事件
- 地理定位api和谷歌地图出错
- 谷歌地图api和gMapsLatLonPicker
- 谷歌地图地点API地图未显示
- 当我使用高度百分比时,谷歌地图javascript api不会显示
- 谷歌地图API-“;toGeoJson”;返回几何体为null的对象
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- 为什么谷歌地图API's方法未从RequireJS中正确调用
- 使用谷歌地图api计算距离并将其设置在表格中<td>
- 使用谷歌地图API和phonegap显示当前位置+方向
- 使用谷歌地图api v3自动完成字段(法国大道、邮编、城市)
- 关于关键的API谷歌地图
- mark.setDragable(false)在API谷歌地图的main.js中抛出异常
- 隐藏标记出现后缩放- API谷歌地图V3