In case it ever helps anyone:
I'm using a KML file and a GGeoXML object to set up points on my map.
Rather than manually setting a zoom level, I'm calling
GGeoXML::gotoDefaultViewport(). It all works beautifully, except that
the zoom level is a little bit too 'zoomed in'. I thought that I could
ask the map for the current zoom level, and then set the level to
'unzoom' a bit, but map.getZoom() tells me that the zoom level is 1,
although I can see from the zoom slider on the map that the level is
3.
The problem was that I was checking the zoom level before GGeoXML was
finished. The solution is to create an event listener for the GGeoXML
'load' event and fiddle with the zoom there. Here's some code:
function load() {
if (GBrowserIsCompatible()) {
var url_end = "?nocache=" + (new Date()).valueOf();
var myKML = "http://www.mysite.com/myxmlfile.xml' + url_end;
map = new GMap2(document.getElementById("map"));
// The API reference says that this must be done at the
beginning;
// I'm not convinced that it's absolutely necessary when using
KML.
map.setCenter(new GLatLng(0, 0));
map.setZoom(1);
// Add controls
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
geoxml = new GGeoXml(myKML);
GEvent.addListener(geoxml, "load", handleGeoXMLLoad);
map.addOverlay(geoxml);
geoxml.gotoDefaultViewport(map);
}
}
function handleGeoXMLLoad() {
// We have to set the zoom level after the GGeoXML object is finished
with
// all of its work. Otherwise, we're checking the zoom level before
that
// object even has a chance to set it.
var zoomLevel = map.getZoom();
map.setZoom(zoomLevel - 1);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---