谷歌地图Kml图层缩放

时间:2015-07-31 15:39:15

标签: api zoom kml layer

我正在使用我的地图初始化。我想让我的地图进入我的地图容器"放大更多(可能是16变焦)。我在哪里可以添加此缩放参数?这可能吗?

    function initialize() {
var map = new google.maps.Map(document.getElementById('map-container'), {

}),

myMapsId = 'zpR-Rs8swcrY.kxIipB_folRg&usp';
  new google.maps
    .KmlLayer({
      map: map,
      url: 'https://www.google.com/maps/d/kml?mid=' + myMapsId
    });
}
google.maps.event.addDomListener(window, 'load', initialize); 

1 个答案:

答案 0 :(得分:0)

You add the zoom parameter (and the center parameter, you need both) in the MapOptions.

In order to prevent the KmlLayer from zooming and centering the map on the KML content, you need to set the preserveViewport option of the KmlLayer to true.

code snippet:

function initialize() {
  var map = new google.maps.Map(document.getElementById('map-container'), {
      zoom: 16,
      center: {
        lat: 56.620599,
        lng: -6.076408
      }

    }),

    myMapsId = 'zpR-Rs8swcrY.kxIipB_folRg&usp';
  new google.maps
    .KmlLayer({
      map: map,
      url: 'https://www.google.com/maps/d/kml?mid=' + myMapsId,
      preserveViewport: true
    });
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map-container {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map-container" style="border: 2px solid #3872ac;"></div>

相关问题