javascript - How to change a Fusion Table layer query based on user input and button? -
google provides great example of updating fusion table layer on map here: https://developers.google.com/fusiontables/docs/samples/change_query
user input captured in html:
<select id="delivery"> <option value="">--select--</option> <option value="yes">yes</option> <option value="no">no</option> </select>
the query updated in javascript:
function updatemap(layer, tableid, locationcolumn) { var delivery = document.getelementbyid('delivery').value; if (delivery) { layer.setoptions({ query: { select: locationcolumn, from: tableid, where: "delivery = '" + delivery + "'" } }); } else { layer.setoptions({ query: { select: locationcolumn, from: tableid } }); }
as can see on link above, query , map layer updates on change. instead of updating on change, have user select value in delivery field, , update query on button click:
<input type="button" id="button" value="update map">
can provide me example or modify updatemap function use button click prompt change?
i tried did not work:
var delivery = document.getelementbyid('button').click(); if (delivery) { ...
thanks in advance help...
the map updates because there event associated select element in sample:
google.maps.event.adddomlistener(document.getelementbyid('delivery'), 'change', function() { updatemap(layer, tableid, locationcolumn); });
the above code associates event - on 'change' of selected value, execute 'updatemap'.
you need remove event , associate event button 'click'.
example:
google.maps.event.adddomlistener(document.getelementbyid('<your button id>'), 'click', function() { updatemap(layer, tableid, locationcolumn); });
having said that, technique of attaching event incorrect. if using javascript, need attach event , add event listener. if using jquery, can use 'bind'/'on' functions attach events.
Comments
Post a Comment