Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图缩放级别未注册_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图缩放级别未注册

Javascript 谷歌地图缩放级别未注册,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我可以让我的谷歌地图响应缩放级别的变化。下面是代码,但当我将缩放设置为其他级别并重新加载时,地图默认为缩放级别9。我找不到其他地方可以设置缩放或在单击标记时更改缩放。我觉得我错过了一些非常明显的东西 // arrays to hold copies of the markers and html used by the side_bar // because the function closure trick doesnt work there var

我可以让我的谷歌地图响应缩放级别的变化。下面是代码,但当我将缩放设置为其他级别并重新加载时,地图默认为缩放级别9。我找不到其他地方可以设置缩放或在单击标记时更改缩放。我觉得我错过了一些非常明显的东西

      // arrays to hold copies of the markers and html used by the side_bar 
      // because the function closure trick doesnt work there 
      var gmarkers = []; 

     // global "map" variable
      var map = null;
// A function to create the marker and set up the event window function 
function createMarker(latlng, name, html) {
    var contentString = html;
    var marker = new MarkerWithLabel({
        position: latlng,
        icon: 'img/marker2_ltblue.png',
        map: map,
        suppressInfoWindows: true,
        zIndex: Math.round(latlng.lat()*-100000)<<5,
        labelContent: name,
        labelAnchor: new google.maps.Point(75, 0),
        labelClass: "labels", // the CSS class for the label
        labelStyle: {opacity: 0.75}
        });

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(contentString); 
        infowindow.open(map,marker);
        });

   google.maps.event.addListener(marker, 'click', function() {

     map.setCenter(marker.getPosition());
     });

}

// This function picks up the click and opens the corresponding info window
function myclick(i) {
  google.maps.event.trigger(gmarkers[i], "click");
}

function initialize() {
  // create the map
  var myOptions = {
    zoom: 7,
    center: new google.maps.LatLng(39.369804, -106.388725),
    mapTypeControl: true,
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
    navigationControl: true,
    mapTypeId: google.maps.MapTypeId.TERRAIN
  }
  map = new google.maps.Map(document.getElementById("map_canvas"),
                                myOptions);

 var ctaLayer = new google.maps.KmlLayer({
    url: 'http://www.huts.org/Gmaps/gpsTracks/10thsystemTrailsWinter.kml'
  });
  ctaLayer.setMap(map);

  google.maps.event.addListener(map, 'click', function() {
        infowindow.close();
        });
      // Read the data from example.xml
      downloadUrl("gMapsHuts.xml", function(doc) {
        var xmlDoc = xmlParse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          // obtain the attribues of each marker
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new google.maps.LatLng(lat,lng);
          var name = markers[i].getAttribute("label");
          var html = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);
          var category = markers[i].getAttribute("category");
          var season = markers[i].getAttribute("season");
          // create the marker
          var marker = createMarker(point,name,html,category);
        }

      });
    }

 // the important function... routes[id].xxxxx refers back to the top 



var infowindow = new google.maps.InfoWindow(
  { 
    size: new google.maps.Size(175,175)
  });
//用于保存侧栏使用的标记和html副本的数组
//因为函数闭包技巧在那里不起作用
var gmarkers=[];
//全局“映射”变量
var-map=null;
//创建标记和设置事件窗口功能的函数
函数createMarker(latlng、name、html){
var contentString=html;
变量标记=新标记WithLabel({
位置:latlng,
图标:“img/marker2ltblue.png”,
地图:地图,
suppressInfoWindows:对,

zIndex:Math.round(latlng.lat()*-100000)将
ctaLayer
preserveViewport
选项设置为
true


否则,API会将地图的视口设置为包含图层所有特征的区域(在本例中强制9倍缩放)

您是否尝试过
map.setZoom(number)
?在我看来,您似乎将其设置为7[缩放:7],不知道为什么会是9。请提供一个例子来说明问题。确实如此,Molle博士。我一开始想到了,但没有意识到kml图层有默认的缩放级别。非常感谢。他们没有默认的缩放级别,缩放级别将取决于地图的大小和特定图层中特征的边界。