1

EDIT: Solved:

var opt = { minZoom: 6, maxZoom: 9 };
  map.setOptions(opt);

I'm a cut-and-paste coder and while I intend on learning the syntax better, I'm on a deadline for now so I'm asking for help. I have googled extensively and while there are solutions to my problem, I haven't found one that works for me. My KML file is hosted on Google Drive so instead of a file url there is a driveFileId.

If you want to preserveViewport, you normally just add it to the layer object and set it to 'true'. However my KML file won't let me override its default zoom level where the bounds fit the screen no matter how I write it. Can someone help? This is the working object:

var layer = new google.maps.KmlLayer({
driveFileId: "0Bexampleg"});
layer.setMap(map);

EDIT: Here's the whole thing. Perhaps you can see if there are redundancies or contradictions that are causing this.

<!DOCTYPE html>
<html<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?key=Aexamplekey0&sensor=true"></script>
    <style>
        #map {
            width: 310px;
            height: 410px;
        }
    </style>

    <script>
        window.onload = function () {
var latlng = new google.maps.LatLng(53.385873, -1.471471);

var styles = [
  {
    //whatever
  }
]

var myOptions = {
zoom: 15,
            disableDefaultUI: false,
                styles: styles
            },

            map = new google.maps.Map(document.getElementById('map'), myOptions);

var layer = new google.maps.KmlLayer({
    driveFileId: "0Bexampleg"});
layer.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
    </script>

</head>

<body>
<div id="map"></div>
</body>
</html>
Wheelsgr
  • 21
  • 1
  • 4
  • How did you add the preserveViewport option to that code? – geocodezip Jun 21 '13 at 04:04
  • 1
    Like the example shown below by Tony. `(var layer = new google.maps.KmlLayer({ driveFileId: "0Bexampleg", preserveViewport: true}); layer.setMap(map);` When i do, it just renders my map blank but I can still see the map outline - as though the kml layer is just blocking everything. It's different from when the map code isn't working - then the screen is just blank. – Wheelsgr Jun 21 '13 at 20:47

2 Answers2

4

Based on the current release API documentation, you should be able to set the preserveViewport option in the object you instantiate:

var layer = new google.maps.KmlLayer({
    driveFileId: "0Bexampleg",
    preserveViewport: true});
layer.setMap(map);

Without further information, such as a URL to your KML data, information about your map center and zoom, there's not much further that can be said.

Tony Miller
  • 9,059
  • 2
  • 27
  • 46
1

GOT IT!

Here it is:

var opt = { minZoom: 11, maxZoom: 15 };
map.setOptions(opt);

And then in your the myOptions object you set your default zoom. Solution found here: Google Maps v3 - limit viewable area and zoom level thanks to @ChrisV. I don't know why but the KML Layer won't allow any permutation of the original preserveViewport code.

Community
  • 1
  • 1
Wheelsgr
  • 21
  • 1
  • 4