2012-08-02 159 views
1

我正在創建一個具有融合層的Google地圖,因此網站的訪問者可以獲得有關各個州的技術人員的信息。以下是供參考的網址:http://horizonwebtest.zxq.net/techmap.html地圖需要鎖定到美國大陸,所以我禁用了默認UI,可拖動,雙擊縮放,鍵盤快捷鍵,滾輪和自動平移。問題是當信息窗口彈出時,它仍然強制地圖平移。有沒有人知道解決這個問題的方法?這裏是JavaScript:谷歌地圖API v3停止信息框從平移地圖

// JavaScript Document 
    function initialize() { 
    var mapOptions = { 
     center: new google.maps.LatLng(38.816223025492505, -94.15954943749999), 
     zoom: 4, 
     disableDefaultUI: true, 
     draggable: false, 
     disableDoubleClickZoom: true, 
     keyboardShortcuts: false, 
     scrollwheel: false, 
     disableAutoPan: true, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var horizonStyles = [ 
    { 
     featureType: "water", 
      stylers: [ 
       { hue: "#0077ff" }, 
       { saturation: 20 }, 
       { lightness: -50 }, 
      ] 
    },{ 
     featureType: "administrative.locality", 
      stylers: [ 
       { visibility: "off" } 
      ] 
    },{ 
     featureType: "administrative.province", 
     elementType: "labels.text.fill", 
      stylers: [ 
       { lightness: -80 } 
      ] 
    } 
    ]; 
    var layer = new google.maps.FusionTablesLayer({ 
     query: { 
      select: 'geometry', 
      from: '18KqZR_1Nd39CyWN1kKt8Pufd6wlLS2oQArpCugw' 
     }, 
    }); 
    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     mapOptions); 
    map.setOptions({styles: horizonStyles}); 
    layer.setMap(map); 
} 

任何想法將不勝感激。

回答

0

經過大量的搜索和反覆試驗,似乎融合層不包含可編輯元素。要編輯信息框,需要設置suppressInfoWindows:true,然後創建信息窗口。下面是引用成品代碼:

// JavaScript Document 
    function initialize() { 
    var latlng = new google.maps.LatLng(38.816223025492505, -94.15954943749999); 
    var infoposition = new google.maps.LatLng(40, -81); 
    var infowindow = new google.maps.InfoWindow({ 
     disableAutoPan: true, 
     position: infoposition, 
    }); 
    var infoWindowContent = ''; 
    var mapOptions = { 
     center: latlng, 
     zoom: 4, 
     disableDefaultUI: true, 
     draggable: false, 
     disableDoubleClickZoom: true, 
     keyboardShortcuts: false, 
     scrollwheel: false, 
     disableAutoPan: true, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var horizonStyles = [ 
    { 
     featureType: "water", 
      stylers: [ 
       { hue: "#0077ff" }, 
       { saturation: 20 }, 
       { lightness: -50 }, 
      ] 
    },{ 
     featureType: "administrative.locality", 
      stylers: [ 
       { visibility: "off" } 
      ] 
    },{ 
     featureType: "administrative.province", 
     elementType: "labels.text.fill", 
      stylers: [ 
       { lightness: -80 } 
      ] 
    } 
    ]; 
    var layer = new google.maps.FusionTablesLayer({ 
     query: { 
      select: 'geometry', 
      from: '18KqZR_1Nd39CyWN1kKt8Pufd6wlLS2oQArpCugw', 
     }, 
     suppressInfoWindows: true, 
    }); 
    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     mapOptions); 
    map.setOptions({styles: horizonStyles}); 
    layer.setMap(map); 

//click listener on layer 
google.maps.event.addListener(layer, 'click', function(e) { 
if(infowindow) infowindow.close(); 
else infowindow; 

//create info window layer 
infoWindowContent = infowindow.setContent(
    '<p class="info_window" style="font-weight: bold">' + e.row['State'].value + '</p>' + 
    '<p class="info_window">' + e.row['Number of Technicians'].value + ' technicians available<br>' + 
    '<a href="http://horizonwebtest.zxq.net/contact/">Click here to schedule a service call or installation<br>' + 
    'or <style="font-weight:bold">CALL 727-845-4444 NOW</style> for a live help desk<br>' + 
    'person to assist you over the phone or to dispatch<br>' + 
    'a technician to your site.</a></p>' 
    ); 

map.setCenter(latlng); 
infowindow.open(map);   
}); 
} 

我希望幫助別人......