How to download KML on a Google map without changing the center of the map

How to add KML as a layer in google maps (javascript v3) without zooming / scaling the map?

I add KML, which has several events around the world, because of this google maps javascript v3 changes the map scale to a very large enlarged view.

Here is a sample code:

function loadOverlay(inc) 
{
    var overlay = new google.maps.KmlLayer(inc);
    overlay.setMap(map);
    overlayArray.push(overlay);
}

function initialize_gmap()
{
    var Rochester = new google.maps.LatLng(43.1561, -77.607); 
    var myOptions = {
    zoom: 11,
    center: Rochester,
    mapTypeId: google.maps.MapTypeId.TERRAIN
    }

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

//Then i initialize the map here, and load the kml
initialize_gmap();
loadOverlay("linktokml.kml");

After loading kml, it switches to a very large scale to show all locations in kml. How can I either prevent this, or return to the original degree / scale?

Thanks in advance.

+5
source share
1 answer

Just set preserveViewportthe google.maps.KmlLayerOptions option to true:

var overlay = new google.maps.KmlLayer(inc,{preserveViewport:true});
+10
source

All Articles