2010-07-16 38 views
4
var polygon = new GPolygon(polylines[0],"#FFFFFF", 1, 1.0, color,opacity); 

    polygon.hid = this.id; 
    polygon.heat = this.heat; 

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

    HoodsUnselect(active_hood_id); 
    active_hood_id = polygon.hid; 
polygon.setOptions({fillColor: '#2948e4', fillOpacity: 0.50 }); 
    //polygon.setFillStyle({ color:'#2948e4',opacity:'0.50' }); 

    if (point) { 
     map.openInfoWindowHtml(point, the_list); // open info window where user clicked 

    } else { 
     map.openInfoWindowHtml(polygon.getBounds().getCenter(), the_list); // open info window at the center of polygon 
    } 
    }); 

回答

15

除了Tony's answer之外,v3 API中沒有openInfoWindowHtml()方法。您必須創建一個InfoWindow對象,您可以在其中調用open()close()方法。通常你會想只是一個InfoWindow對象,如果你想在同一時間只有一個可見:

var infoWindow = new google.maps.InfoWindow(); 

google.maps.event.addListener(yourOverlay, 'click', function() { 
    infoWindow.setContent('Some info on yourOverlay'); 
    infoWindow.open(map); 
}); 

的V2 API和v3 API之間的主要區別,當涉及到信息窗口的事實是,在V3 API可以同時打開多個信息窗口。這在v2 API中是不可能的。要打開多個信息窗口,您希望創建多個InfoWindow對象,而不是僅針對所有標記(疊加層)。

至於多邊形,這是如何創建V3 API中的多邊形(從示例mentioned by @Tony借用):

var bermudaTriangle = new google.maps.Polygon({ 
    paths: [ 
    new google.maps.LatLng(25.774252, -80.190262), 
    new google.maps.LatLng(18.466465, -66.118292), 
    new google.maps.LatLng(32.321384, -64.75737) 
    ], 
    strokeColor: "#FF0000", 
    strokeOpacity: 0.8, 
    strokeWeight: 3, 
    fillColor: "#FF0000", 
    fillOpacity: 0.35 
}); 

bermudaTriangle.setMap(map); 
+0

應該有,我使用v3和信息窗口代碼中的問題。打開獲取兩個參數:'infoWindow.open = function(a,b){this.set(「anchor」,b); this.set(「map」,a)}' – 2013-06-27 15:48:59

+0

@Mehdi Karamosly:第二個參數是可選的。如果通過,這是信息窗口將彈出的標記。如果沒有指定,它會出現在某個默認位置(左上角)。 (https://developers.google.com/maps/documentation/javascript/infowindows#open) – 2014-04-27 21:34:53