On Jul 9, 3:46 pm, Joseph Elfelt <
josephelf...@gmail.com> wrote:
> Alas, I have not been able to figure out how to do these two things
> with KML files:
>
> A. When the map first appears on the user's screen, then display a
> KML file and let the API automatically set the map center and zoom
This seems to work for one kml file:
google.maps.event.addListener(ctaLayer, "metadata_changed" ,
function() {
map.fitBounds(ctaLayer.getDefaultViewport());
});
Since you haven't provided a link to your map, I don't know if it will
work for your code structure and I don't know that the
"metadata_changed" event is the best way to tell that the kmllayer has
loaded, I don't see a complete list of the available events in the
documentation. Maybe one of the google engineers can shed some light
on where those would be documented.
> B. As the user toggles the KML on/off, preserve the viewport
>
> Below is Google's KML demo map to which I added
> preserveViewport:true
> Adding this setting is the key to doing item 'B'.
>
> However, the initial appearance of the map (item 'A') uses the zoom
> setting in the options and as a result only part of the KML data is on
> the map. When I tried deleting the zoom setting in the options, then
> I got a blank map.
I believe the initial zoom is needed to "initialize" the map.
Although the documentation isn't very clear about what is required to
initialize the map.
-- Larry