2015-02-06 13 views
0

我已經使用geoxml3加載並設置了樣式。現在我想更新僅改變中心點和縮放級別的地圖。我怎麼能做到這一點。geoxml3上的更新中心點

var latlng = new google.maps.LatLng(29.722601, -11.681680); 
    var myOptions = { 
      zoom : 1, 
      //minZoom:2, 
      maxZoom:10, 
      center : latlng, 
      //disableDefaultUI: true, 
      streetViewControl: false, 
      mapTypeControl: false, 
      panControl: true, 
      zoomControl: true, 
      suppressInfoWindows : true, 
      preserveViewport : true, 
      scrollwheel: false, 
      styles:style 
     }; 

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

    var geoXml = new geoXML3.parser({ 
     map: map, 
     singleInfoWindow: false, 
     afterParse: useTheData, 
     suppressInfoWindows : true, 
     zoom : false 
    }); 
    geoXml.parse(url_kml+'basins.kml'); 

一旦上面載入我想要使用onclick chnages。我的onclick運行以下js功能

function updatekmmap(region){ 
    console.log(region); 
    console.log(map); 
    var latlng = new google.maps.LatLng(29.722601, -11.681680); 
    // 
    switch(region){ 
    case "north": 
     latlng = new google.maps.LatLng(56.065192, -104.814452); 
     break; 
    } 
    gMap = new google.maps.Map(document.getElementById('map_canvas')); 
    gMap.setZoom(10);  // This will trigger a zoom_changed on the map 
    gMap.setCenter(latlng); 

} 

這不保留原有的風格等。

+0

你爲什麼要重新創建地圖對象? – MrUpsidown 2015-02-06 12:55:18

+0

即時通訊設法在'geoXml'上設置縮放和中心位置。我不知道該怎麼做。 – shorif2000 2015-02-06 13:42:18

回答

0

我現在的工作。我正在重新創建地圖對象。

function updatekmmap(region){ 
    console.log(region); 
    console.log(map); 
    var latlng = new google.maps.LatLng(29.722601, -11.681680); 
    // 
    switch(region){ 
     case "north": 
      latlng = new google.maps.LatLng(31.137854, -90.256931); 
      break; 
     case "south": 
      latlng = new google.maps.LatLng(31.137854, -90.256931); 
      break; 
     case "caribbean": 
      latlng = new google.maps.LatLng(31.137854, -90.256931); 
      break; 
     case "eu": 
      latlng = new google.maps.LatLng(50.352658, -9.316490); 
      break; 
     case "med": 
      latlng = new google.maps.LatLng(37.309248, 18.786537); 
      break; 
     case "africa": 
      latlng = new google.maps.LatLng(-14.933886, -59.495213); 
      break; 
     case "asia": 
      latlng = new google.maps.LatLng(31.137854, -90.256931); 
      break; 
    } 
    //gMap = new google.maps.Map(document.getElementById('map_canvas')); 
    map.setZoom(3);  // This will trigger a zoom_changed on the map 
    map.setCenter(latlng); 
    //console.log(geoXml.getDefaultBounds()); 
    //return false; 
}