目前我正在使用Google Maps JavaScript API V3过滤地图结果。我有两个javascript下拉菜单。选择一个下拉选项值后,地图会过滤到该设置。因此,如果我选择业务类型“社会服务”,则地图将仅显示此类业务。第二个过滤器用于不同的主题。因此,如果选择了第二个下拉菜单,它将过滤到此选项值。问题是,当选择第二个或第一个时,它在过滤时忽略另一个。例如,我希望用户能够从第一个菜单中过滤“社交服务”,从第二个菜单中过滤“机会”。这将显示符合这两个标准的位置。现在用户只能选择其中一个。
以下是页面:
以下是代码:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<!DOCTYPE html>
<title>Met Sacramento Internship Map</title>
<!-- Style -->
<style>
body { font-family: Arial, sans-serif; }
#map_canvas { height: 500px; width:600px; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var tableid = 567682;
var layer = new google.maps.FusionTablesLayer(567682);
function initialize() {
var latlng = new google.maps.LatLng(38.59970036588819, -121.541748046875);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
layer.setMap(map);
}
//Change the query based on the user's selection
function interestMap(interest) {
layer.setQuery("SELECT Address, 'Interest Area' FROM " + tableid + " WHERE 'Interest Area' CONTAINS '" + interest + "'");
}
function statusMap(status) {
layer.setQuery("SELECT Address, 'Status' FROM " + tableid + " WHERE 'Status' CONTAINS '" + status + "'");
}
</script>
</script>
</head>
<body onload="initialize();">
Internship Status <select onchange="interestMap(this.value);">
<option value="">Interest Areas</option>
<option value="Aerospace">Aerospace</option>
<option value="Animals">Animals</option>
<option value="Architecture">Architecture</option>
<option value="Art/Music/Theatre">Art/Music/Theatre</option>
<option value="Athletics and Martial Arts">Athletics</option>
<option value="Automotive and Transportation">Automotive</option>
<option value="Business">Business</option>
<option value="Community Development">Community Development</option>
<option value="Computers">Computers</option>
<option value="Cosmetology">Cosmetology</option>
<option value="Culinary">Culinary</option>
<option value="Education">Education</option>
<option value="Government and Politics">Politics</option>
<option value="Health Science">Health Science</option>
<option value="Hospitality/Tourism/Event Planning">Event Planning</option>
<option value="Law and Public Safety">Law and Public Safety</option>
<option value="Marketing">Marketing</option>
<option value="Media and Information Technology">Media</option>
<option value="Photography">Photography</option>
<option value="Science and Technology">Science and Technology
</option>
<option value="Social Services">Social Services</option>
</select>
Status <select onchange="statusMap(this.value);">
<option value="">Status</option>
<option value="BEING PURSUED">Being Pursued</option>
<option value="HAS INTERN">Has Intern</option>
<option value="NOT TAKING">Not Taking</option>
<option value="OPPORTUNITY">Opportunity</option>
<option value="OVER 18">Over 18</option>
<option value="POTENTIAL?">Potential</option>
<option value="SEE NOTES">See Notes</option>
</select>
<div id="map_canvas"></div>
</body>
</html>
非常感谢你的帮助。
答案 0 :(得分:0)
我没有使用2个不同的过滤功能,而是根据下拉列表中的值创建一个过滤器。
这样的事情:
function filterResults(){
var interest = document.getElementById('ddl-interest').value;
var status = document.getElementById('ddl-status').value;
layer.setQuery("SELECT Address, 'Interest Area' FROM " + tableid +
" WHERE 'Interest Area' CONTAINS '" + interest + "' AND 'Status' CONTAINS '" + status + "'");
}
然后你显然需要给你的下拉列表ids'ddl-interest'和'ddl-status'并在onchange事件上调用'filterResults'方法。