kmlLayer causing focus to change (google map api v3)
Asked Answered
R

2

2

I'm layering NOAA radar information over a map with a focus of 8. When the page loads, the map initially renders at 8, then immediately redraws itself to show an entire region.

The KML file I'm using contains min/max lat/long coordinates which are used to draw the radar image (in this case over the southeast US area). If I change those coordinates to cover a smaller area, the google map is resized like I want, but radar activity is clipped per the KML file. This is a problem if users zoom out or scroll outside of the default map area.

Example map: http://georgiaoffroad.com/map2.html

Example KML file: http://georgiaoffroad.com/includes/southeastradar.kml

Is there a way to keep the radar image large, but focus the map on a smaller area of the available radar image so users could zoom or scroll around to see weather for surrounding areas?

Rockingham answered 5/1, 2013 at 17:45 Comment(0)
S
4

set the option preserveViewport of the layer to true:

new google.maps
     .KmlLayer({url:'http://georgiaoffroad.com/includes/southeastradar.kml',
                preserveViewport:true});
Snyder answered 5/1, 2013 at 17:59 Comment(4)
Excellent - is there a way to adjust the transparency of the layer?Rockingham
When you mean the radar, you may use css, e.g.: img[src^="http://radar.weather.gov/ridge/Conus/RadarImg/"]{opacity:.5}Snyder
Is there some known limitation for the usage of this option? I am using 3 layers for my map, and when i use this option on any 2 of the 3, it works fine. But if i add it to all of them, the whole map does not even initialize, regardless of whether or not the layers are initially shown.Arlberg
AFAIK there is no limit. Demo with 3 layers: jsfiddle.net/doktormolle/nkH2ZSnyder
P
1

I realize this is a very late answer but I wanted to post the technique that I used that worked best for me. The method posted by Dr. Molle either no longer works or it just didn't work for me.

Adding "ctaLayer.set('preserveViewport', true);" after you set the layer to the map will keep the map from auto focusing to that kmz/kml file.

var ctaLayer = new google.maps.KmlLayer('/kmz/90201.kmz');
          ctaLayer.setMap(map);
          ctaLayer.set('preserveViewport', true);
Prognosticate answered 29/7, 2014 at 18:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.