2012-04-09 52 views
0

我想根据融合表中的列为标记创建多个过滤器。我希望过滤器能够并行工作,而不是单独过滤。这里是我到目前为止,我根据它的答案,我发现这里由ERIC的代码,但它并没有为我工作:使用Google Fusion创建的标记的多个过滤器

<!DOCTYPE html> 
<html> 
    <head> 
<style> 
#map-canvas { width:500px; height:400px; } 
    </style> 
<script src="http://code.jquery.com/jquery.min.js"></script> 
<script src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js"></script> 
<script src="eq_jsonp.js"></script> 
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 
<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false">   </script> 
<script type="text/javascript"> 
var map; 
var layerl0; 
var tableid = 3470746; 
var locationCol = 'Latitude'; 
    function initialize() { 
    map = new google.maps.Map(document.getElementById('map-canvas'), { 
    center: new google.maps.LatLng(28.2798935535169, -81.3486099243164), 
    zoom: 13, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

layerl0 = new google.maps.FusionTablesLayer({ 
    query: { 
     select: "'latitude'", 
     from: 3470746 
    }, 
    map: map 
    }); 
} 
google.maps.event.addDomListener(window, 'load', initialize); 

function doQuery(){ 

// collect WHERE conditions here for each search-string value 

var query = []; 

var searchString = ''; 

// I'd name my select id's something more descriptive, e.g. "damage_level" vs search-  string1, etc. 

searchString = document.getElementById('classification').value; 

if(searchString){ 

query.push(" 'Roadway Classification:' = '" + searchString + "'"); 

} 

searchString = document.getElementById('name').value; 

if(searchString){ 

query.push("'Roadway Name:' = '" + searchString + "'"); 

} 

// Date Filter 

searchString = dateFilter(); 

if(searchString){ 

query.push(searchString); 

} 

// Now build the WHERE clause by joining with ' AND ' all the conditions. 

// Note: if nothing is in the where Fusion Tables will not object 

var where = query.join(' AND '); 
//alert(where); 

var qryOpts = { 

query: { 

    select: "'latitude'", 

    from: 3470746, 


    } 

}; 

layer.setOptions(qryOpts); 
return; 

} 

// set all form inputs to null and call doQuery again. 

function resetQuery(){ 

$('#classification').val(''); 
$('#name').val(''); 
doQuery(); 
} 

</script> 
</head> 
<body> 
<div id="map-canvas"></div> 
<form> 
<div style="margin-top: 10px;"> 
    <label>Roadway Classification</label> 
    <select id="classification" onchange="doQuery;" title="Select Roadway by Classification"> 
    <option value="">--Roadway Type--</option> 
    <option value="Collector">Collector</option> 
    <option value="Highway">Highway</option> 
    <option value="Minor Arterial">Minor Arterial</option> 
    </select> 
</div> 
<div style="margin-top: 10px;"> 
    <label>Roadway Name</label> 
    <select id="name" onchange="doQuery;" title="Select Roadway by Name"> 
    <option value="">--Roadway Name--</option> 
    <option value="Neptune Rd">Neptune Rd</option> 
    <option value="Partin Settlement Rd">Partin Settlement Rd</option> 
    <option value="Shady Ln">Shady Ln</option> 
    </select> 
    <br> 
    <input type="button" onclick="doQuery();" value="Search" /> 

    <input type="button" onclick="resetQuery();" value="Reset" /> 
    </form> 
</div> 
</body> 
</html>' 

回答

0

table 3470746看了看,列名没有冒号的在他们之后。尝试:

query.push("'Roadway Name' = '" + searchString + "'"); 

query.push(" 'Roadway Classification' = '" + searchString + "'"); 

还您不添加where子句您qryOpts:

var where = query.join(' AND '); 


var qryOpts = { 

query: { 

    select: "'latitude'", 

    from: 3470746, 
    // WHERE clause was missing 
    where: where 

    } 

}; 
+0

埃里克,你的快速反应表示感谢。好的渔获,我已根据您的意见修复了代码。但是,仍然当我点击“搜索”过滤器不起作用,标记不会相应地改变。我不确定我出错的地方! – haguib 2012-04-09 16:14:51

+0

再次感谢Eric,你可以进一步解释在where子句中写什么?应该在哪里:“道路分类”和“道路名称”? – haguib 2012-04-10 12:57:55

+0

我对表格和脚本做了一些修改,我删除了列名中的空格,并将列名保存为小写。但是,搜索按钮仍然无法正确启动!可能是什么问题? – haguib 2012-04-10 14:49:00

相关问题