kmlLayer causing focus to change (google map api v3)

自作多情 提交于 2019-12-24 00:56:27

问题


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?


回答1:


set the option preserveViewport of the layer to true:

new google.maps
     .KmlLayer({url:'http://georgiaoffroad.com/includes/southeastradar.kml',
                preserveViewport:true});



回答2:


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);


来源:https://stackoverflow.com/questions/14174552/kmllayer-causing-focus-to-change-google-map-api-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!