Fusion Core APIs: How to Execute an Update Request Correctly?
I am referring to the Fusion Tables API "Refresh Query" example https://developers.google.com/fusiontables/docs/samples/change_query This is a dropdown menu that changes the content of a layer on a map.
I tried to rebuild the whole example on my own site, but I haven't decided yet. I've narrowed down the possible errors and pitfalls for the part where the layer is initialized (with data from my google merge spreadsheet). It looks like google example:
var layer = new google.maps.FusionTablesLayer({
query: {
select: locationColumn,
from: tableId
},
map: map
});
Here is the code that was developed for me in each of my own examples using merge tables except the one above.
var layer = new google.maps.FusionTablesLayer(tableid)
layer.setMap(map);
Here is a link for live code: http://krealeo12.appspot.com/
As I'm new to this whole API and JavaScript, I can't tell the difference why the first example doesn't work and the second does ?! What is the difference, and more importantly, what does it mean?
I am very grateful for every hint and advice! J.
source to share
This issue also confused me when I started using Fusion tables. You will find many examples of using deprecated methods:
var layer = new google.maps.FusionTablesLayer(tableid)
layer.setMap(map);
layers.setQuery("select * from " + tableid + " where ridership > 5000");
The first example you cite is the correct way to do it. The most confusing thing is that you cannot combine the two approaches. For example. last time i checked the following won't work. The original map will render fine, but the query won't work.
var layer = FusionTablesLayer(tableid);
var layer.setOptions{
query: {
select: 'address',
from: '198945',
where: 'ridership > 5000'
}
});
The correct way is described in the docs
source to share
Indeed, another question, so I am adding a new answer. You have a bug in your updateMap () function.
function updateMap(layer, tableid, locationColumn) {
var sportart = document.getElementById('search-string').value;
if (sportart) {
layer.setOptions({
query: {
select: locationColumn,
from: tableid,
where: "sportart = '" + search-string + "'" // ERROR
}
});
} else {
layer.setOptions({
query: {
select: locationColumn,
from: tableid
}
});
}
}
The picklist search value is called "sportart", not "search string".
source to share
Google does not provide error messages from queries, so you may need to trial and error and search for examples to get results. This worked for me. Notice the quotes around the entire line (as you would expect), plus quotes around the date.
layer.setOptions({
query:{
select: "col1",
from: "1Ayaf5aKAanSv6HAtsTLtcAhrnpF94XyuNZ9u_Sk",
where: "Date<'01/01/2011'"
},
styles:[{
markerOptions:{
iconName:'measle_gray'
}
}]
});
A useful but hard-to-find page describes acceptable date formats, among others: https://developers.google.com/fusiontables/docs/v1/sql-reference I don't know why many small dot colors are named "measle_" and not "small _ "
source to share
You can use this,
var fusionOptions = {
query: {
select: "Geometry",
from: "tableId",
where: ""
},
styles: [{
where: 'Available_Impressions < 605173',
polygonOptions: {
fillColor: '#88bad8',
fillOpacity: 0.8
}
}, {
where: 'Available_Impressions > 605173',
polygonOptions: {
fillColor: '#5792c3',
fillOpacity: 0.8
}
}, {
where: 'Available_Impressions > 1210347',
polygonOptions: {
fillColor: '#4572ab',
fillOpacity: 0.8
}
}]
}
source to share