hope this makes sense. I have merged together two tables one containing information about telephone exchanges and their specific location in the uk and another containing region info for the uk. What I want to do is when I roll over or click on a region I want to be able to list all the exchanges that fall into that area on a panel on my web page. At the moment when I click on a region the last exchange in the table is displayed. I'm guessing this could be something simple that I need to do within my addListeners2() function. Any pointers in the right direction would be greatly appreciated.
var map, layer;
function initialize()
{
map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(54.54658,-4.87793),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
loadPoint();
}
function loadPoint()
{
if (layer != null)
{
layer.setMap(null);
google.maps.event.clearInstanceListeners(layer);
}
var tableid = '3569550';
layer = new google.maps.FusionTablesLayer
({
query:
{
select: 'LATITUDE',
from: tableid
//where: 'latitude is not null'
},
map: map
})
layer.enableMapTips({
select: "'REGION','EXCHANGE','MPF','WLR','SMPF','BB_CONNECT'", // list of columns to query, typially need only one column.
from: tableid, // fusion table name
geometryColumn: 'LATITUDE', // geometry column name
suppressMapTips: true, // optional, whether to show map tips. default false
delay: 100, // milliseconds mouse pause before send a server query. default 300.
tolerance: 8 // tolerance in pixel around mouse. default is 6.
});
addListeners1();
}
function loadRegion()
{
if (layer != null)
{
layer.setMap(null);
google.maps.event.clearInstanceListeners(layer);
}
var tableid = '3569550';
layer = new google.maps.FusionTablesLayer
({
query:
{
select: 'geometry',
from: tableid
},
map: map
})
layer.enableMapTips({
select: "'REGION','EXCHANGE','MPF','WLR','SMPF','BB_CONNECT'",
from: tableid, // fusion table name
geometryColumn: 'geometry', // geometry column name
suppressMapTips: true, // optional, whether to show map tips. default false
delay: 100, // milliseconds mouse pause before send a server query. default 300.
tolerance: 8 // tolerance in pixel around mouse. default is 6.
});
addListeners2();
}
function addListeners1()
{
google.maps.event.addListener(layer, 'mouseover', function(fEvent)
{
var row = fEvent.row;
myHtml = '<TABLE width = "600" cellspacing="0" cellpadding="0"><TR>';
myHtml += '<TD><b>REGION</b></TD>';
myHtml += '<TD><b>EXCHANGE</b></TD>';
myHtml += '<TD><b>MPF</b></TD>';
myHtml += '<TD><b>WLR</b></TD>';
myHtml += '<TD><b>SMPF</b></TD>';
myHtml += '<TD><b>BB_CONNECT</b></TD></TR><TR>';
for (var x in row)
{
if (row.hasOwnProperty(x))
{
myHtml += '<td>' + row[x].value +'</td>';
}
}
myHtml += '</TR></TABLE>';
document.getElementById('info').innerHTML = myHtml;
});
}
function addListeners2()
{
google.maps.event.addListener(layer, 'mouseover', function(fEvent)
{
var row = fEvent.row;
myHtml = '<TABLE width = "600" cellspacing="0" cellpadding="0"><TR>';
myHtml += '<TD><b>REGION</b></TD>';
myHtml += '<TD><b>EXCHANGE</b></TD>';
myHtml += '<TD><b>MPF</b></TD>';
myHtml += '<TD><b>WLR</b></TD>';
myHtml += '<TD><b>SMPF</b></TD>';
myHtml += '<TD><b>BB_CONNECT</b></TD></TR><TR>';
for (var x in row)
{
if (row.hasOwnProperty(x))
{
myHtml += '<td>' + row[x].value +'</td>';
}
}
myHtml += '</TR></TABLE>';
document.getElementById('info').innerHTML = myHtml;
});
}
}
I have found the solution!!!
function loadRegion()
{
if (layer != null)
{
layer.setMap(null);
google.maps.event.clearInstanceListeners(layer);
}
layer = new google.maps.FusionTablesLayer
({
query:
{
select: 'geometry',
from: tableid
},
map: map
})
google.maps.event.addListener(layer, 'click', function(e)
{
if (e && e.row && e.row["REGION"])
{
query4infowindowData(e.row["REGION"].value);
infowindow.setPosition(e.latLng);
}
else
{
alert("no row:"+e.latLng);
}
});
}
function query4infowindowData(term)
{
var queryText = "SELECT 'REGION', 'EXCHANGE', 'MPF', 'WLR', 'BB_CONNECT', 'SMPF' FROM "+tableid+" WHERE 'REGION' = '"+term+"';";
var encodedQuery = encodeURIComponent(queryText);
var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + encodedQuery);
query.send(openInfoWindow);
}
function openInfoWindow(response)
{
if (!response)
{
alert('no response');
return;
}
if (response.isError())
{
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
FTresponse = response;
numRows = response.getDataTable().getNumberOfRows();
numCols = response.getDataTable().getNumberOfColumns();
var dataTable = response.getDataTable();
var contents = "REGION: <u><b>"+dataTable.getValue(0,0)+"</b></u><br><table border='1'><tr><th>#</th><th>EXCHANGE</th><th>MPF</th><th>WLR</th><th>BB_CONNECT</th><th>SMPF</th></tr>";
for(i = 0; i < numRows; i++)
{
contents += "<tr><th>"+i+"</th><td>"+dataTable.getValue(i,1)
+"</td><td>"+dataTable.getValue(i,2)
+"</td><td>"+dataTable.getValue(i,3)
+"</td><td>"+dataTable.getValue(i,4)
+"</td><td>"+dataTable.getValue(i,5)
+"</td></tr>";
}
contents += "</table>";
document.getElementById('info').innerHTML = contents;
}