0

我不知道为什么,但地图画布没有出现在屏幕上...我使用 Fusion TablesLayer Wizard 2.0 添加过滤器(基于文本的搜索)。也许问题出在 IF...ELSE 语句上。或者一些小的语法错误。请帮忙!

<!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>
4

1 回答 1

0

您的 if/else 语句有点混淆:语句之间有代码。如果我理解您的代码正确,您想根据search-string-10输入更改查询的 where 子句。我简化了你的代码:

function changeMap10() {
    var searchString = document.getElementById('search-string-10').value.replace(/'/g, "\\'");
    var filter = document.getElementById('filter').value.replace(/'/g, "\\'");
    var whereClause = '';
    if (filter == "TURNO") {
        whereClause = "'TURNO' = '" + searchString + "'";
    }
    else if (filter == "DIA_SEMANA") {
        whereClause = "'DIA_SEMANA' = '" + searchString + "'";
    }
    layer10.setOptions({
        query: {
            select: "'ENDERECO_GOOGLE'",
            from: 3767057,
            where: whereClause
        }
    });
}​

我将您的示例放在 jsFiddle 上并进行了一些修改,例如添加过滤器选择框或使用contains ignoring case而不是=.

于 2012-05-10T08:32:42.423 回答