2013-08-21 147 views
0

我正在用下拉菜單構建FusionTables地圖。我希望地圖上的標記根據用戶在下拉菜單中的選擇進行更改。每個菜單選項都對應於Fusion Table中「可能性」列的三個選項。我使用這些鏈接作爲參考:FusionTables更新查詢不起作用

http://sportstleo12.appspot.com/https://developers.google.com/fusiontables/docs/samples/change_query

我已經複製的代碼,到目前爲止,我可以得到所有的選項來顯示,但它不會根據用戶的結果進行過濾選擇。我相信這很簡單。有任何想法嗎?

這裏是迄今爲止代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html> 

<head> 

<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 

<meta charset="UTF-8"> 

<title>Test Page 18</title> 

<link href="/apis/fusiontables/docs/samples/style/default.css" 

rel="stylesheet" type="text/css"> 


<style> 

body { 
font-family: sans-serif; 
background-image: url(images/squairy_light.png); 
} 

#main-container { 
border: 1px solid; 
border-color: #E0E0E0; 
width:1280px; 
margin: auto; 
border-radius:3px; 
padding-top: 15px; 
background-color: white; 
} 
#map-canvas { 
    width:1250px; 
    height:600px; 
    margin: auto; 
    } 
#drop-down { 
width:1250px; 
margin: auto; 
padding-top: 10px; 
padding-bottom: 10px; 

} 
#title { 
width:1280px; 
margin: auto; 
padding-top: 10px; 
font: sans-serif; 
} 

.layer-wizard-search-label { font-family: sans-serif }; 

</style> 



<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 

<script src="/path/to/fusiontips_compiled.js" type="text/javascript"></script> 

<script type="text/javascript"> 


function initialize() { 

var tableId = '1JEUbXBVguPhTwEPncLV0GkF49Tp3ImCooKGGADQ'; 
var locationColumn = 'Lat/Long'; 

var map = new google.maps.Map(document.getElementById('map-canvas'), { 

center: new google.maps.LatLng(40, 345), 

zoom: 3, 

mapTypeId: google.maps.MapTypeId.ROADMAP 

}); 

var layer = new google.maps.FusionTablesLayer({ 
     query: { 
     select: locationColumn, 
     from: tableId, 
     }, 
     map: map, 
    }); 

google.maps.event.addDomListener(document.getElementById('option-list'), 
     'change', function() { 
      updateMap(layer, tableId, locationColumn); 
    }); 
    } 

    // Update the query sent to the Fusion Table Layer based on 
    // the user selection in the select menu 
    function updateMap(layer, tableId, locationColumn) { 
    var delivery = document.getElementById('option-list').value; 
    if (delivery) { 
     layer.setOptions({ 
     query: { 
      select: locationColumn, 
      from: tableId, 
      where: "option-list = '" + delivery + "'" 
     } 
     }); 
    } else { 
     layer.setOptions({ 
     query: { 
      select: locationColumn, 
      from: tableId 
     } 
     }); 
    } 
    } 

    google.maps.event.addDomListener(window, 'load', initialize); 


</script> 


</head> 

<body> 



<div id="title"><h1>Possibility Options</h1></div> 
<div id="main-container"> 

<div id="map-canvas"></div> 



<div id="drop-down"> 

<label>Possibilities:</label> 

<select id="option-list"> 

<option value="">--All Possibilities--</option> 

<option value="Yes">Yes</option> 

<option value="No">No</option> 

<option value="Maybe">Maybe</option> 


</select> 
</div> 

</div> 



</body> 

</html> 
+0

請發表你的答案爲_answer_不作爲問題的一部分。如果你描述了問題是什麼以及解決了什麼問題,那也是有用的。 – geocodezip

回答

0

我不知道什麼是錯的我之前發佈的代碼。我發現這個鏈接,幫我把它寫不同和solce我的問題:

http://jsfiddle.net/odi86/vw4YC/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html> 

<head> 

<meta name="viewport" content="initial-scale=1.0, user-scalable=no"> 

<meta charset="UTF-8"> 

<title>Test Page 18</title> 

<link href="/apis/fusiontables/docs/samples/style/default.css" 

rel="stylesheet" type="text/css"> 


<style> 

body { 
font-family: sans-serif; 
background-image: url(images/squairy_light.png); 
} 

#main-container { 
border: 1px solid; 
border-color: #E0E0E0; 
width:1280px; 
margin: auto; 
border-radius:3px; 
padding-top: 15px; 
background-color: white; 
} 
#map-canvas { 
    width:1250px; 
    height:600px; 
    margin: auto; 
    } 
#drop-down { 
width:1250px; 
margin: auto; 
padding-top: 10px; 
padding-bottom: 10px; 

} 
#title { 
width:1280px; 
margin: auto; 
padding-top: 10px; 
font: sans-serif; 
} 

.layer-wizard-search-label { font-family: sans-serif }; 

</style> 



<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 

<script src="/path/to/fusiontips_compiled.js" type="text/javascript"></script> 

<script type="text/javascript"> 

var tableId = '1JEUbXBVguPhTwEPncLV0GkF49Tp3ImCooKGGADQ'; 

var layer = new google.maps.FusionTablesLayer({ 
     query: { 
     select: 'Lat/Long', 
     from: tableId, 
     }, 
     styleId: 2, 
     templateId: 2, 
    }); 


function initialize() { 


map = new google.maps.Map(document.getElementById('map-canvas'), { 

center: new google.maps.LatLng(40, 345), 

zoom: 3, 

mapTypeId: google.maps.MapTypeId.ROADMAP 

}); 
layer.setMap(map); 
} 


//Change the query based on the user's selection 
function changeMap() { 
    possibility = document.getElementById('Possibility').value; 
    where = " Possibility LIKE '%" + possibility + "%'"; 

    layer.setOptions({ 
     query: { 
      select: 'Lat/Long', 
      from: tableId, 
      where: where 
     } 
    }); 
} 

    google.maps.event.addDomListener(window, 'load', initialize); 


</script> 


</head> 

<body> 



<div id="title"><h1>Possibility Options</h1></div> 
<div id="main-container"> 

<div id="map-canvas"></div> 



<div id="drop-down"> 

<label for="Possibility">Possibilities:</label> 

<select id="Possibility" onChange="changeMap();"> 

<option value="">--All Possibilities--</option> 

<option value="Yes">Yes</option> 

<option value="No">No</option> 

<option value="Maybe">Maybe</option> 


</select> 
</div> 

</div> 



</body> 

</html>