Saturday 22 July 2017

Pan & Change Zoom to show Fusion Tables Query Results in Google Maps JavaScript API V3


I've created this map -- https://s3.amazonaws.com/pdb.files/lookup_auto2.html -- using Google Fusion Tables and Google Maps API. I'm attempting to modify the code so that the map will pan and zoom after executing the query. It seems that I need to use either the fitBounds function to display the bounds of the results, or something simpler like this:



// Change the center and zoom of the map
map.setCenter(results[0].geometry.location);
map.setZoom(10);

I'd prefer the second option so that I can set a consistent zoom level for each query. Any pointers or references for completing this are much appreciated.



Answer



Add a spatial search to your code:


FUSION TABLES allows ST_INTERSECT to be performed full reference: http://code.google.com/apis/fusiontables/docs/developers_reference.html#Select (see )


      // OPTIONAL: find the new map bounds, and run a spatial query to return
// Fusion Tables results within those bounds.

sw = map.getBounds().getSouthWest();
ne = map.getBounds().getNorthEast();
layer.setOptions({
query: {
select: 'lat',
from: tableid,
where: "ST_INTERSECTS(lat, RECTANGLE(LATLNG(" + sw.lat() + "," + sw.lng() + "), LATLNG(" + ne.lat() + "," + ne.lng() + ")))"
}
});


Full code: http://gmaps-samples.googlecode.com/svn/trunk/fusiontables/search_and_zoom.html (view source)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...