I don’t know why but the map canvas does not appear on the screen…
I used the Fusion TablesLayer Wizard 2.0 to add a filter(a text-based search). Maybe the problem is the IF… ELSE statement. Or some minor syntax mistake. Please help!
<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas { width:500px; height:400px; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/apijs?sensor=false"> </script>
<script type="text/javascript">
var map;
var layer10;
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(-30.08870187538118, -51.16813659667969),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
layer10 = new google.maps.FusionTablesLayer({
query: {
select: "'ENDERECO_GOOGLE'",
from: 3767057
},
map: map
});
}
//the function to activate filters
function changeMap10() {
var searchString = document.getElementById('search-string-10').value.replace(/'/g, "\\'");
var filter = document.getElementById('filter').value.replace(/'/g, "\\'");
if (filter == "TURNO"){
layer10.setOptions({
query: {
select: "'ENDERECO_GOOGLE'",
from: 3767057,
}
});
}
layer10.setOptions({
query: {
select: "'ENDERECO_GOOGLE'",
from: 3767057,
where: "'TURNO'" = '" + searchString + "'"
}
});
else if (filter == "DIA_SEMANA"){
layer10.setOptions({
query: {
select: "'ENDERECO_GOOGLE'",
from: 3767057,
}
});
}
layer10.setOptions({
query: {
from: 3767057,
where: "'DIA_SEMANA'" = '" + searchString + "'"
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
<div style="margin-top: 10px;">
<label>Choose data!</label><input type="text" id="search-string-10">
<input type="button" onclick="changeMap10()" value="Search">
</div>
</body>
</html>
your if/else statement is a little bit mixed up: you have code between the statements. If I understood your code correct, you want to change the where clause of the query based on the
search-string-10input. I simplified your code:I put your example on jsFiddle and made some modifications like adding the filter select-box or using
contains ignoring caseinstead of=.