Google地图缩放级别未注册

时间:2014-11-20 20:16:42

标签: 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 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)
  });

1 个答案:

答案 0 :(得分:0)

preserveViewport的选项ctaLayer设置为true

否则API将设置为地图的视口到包含图层所有特征的区域(在这种情况下强制缩放为9)