2012-12-19 30 views
10

在Google Map V3中,如何在多邊形的內部和上方添加標籤? V2中沒有標籤覆蓋當我使用庫maplabel時,即使我指定了更高的Z-index,我也可以將文本放在裏面,但不能放在上面。 感謝 菲爾在Google地圖V3中,如何在多邊形內部和上方放置標籤?

+1

你有沒有想過這個? –

+2

您是否在尋找[this](http://www.geocodezip.com/geoxml3_test/v3_FusionTables_zipcode_map_whiteBg.html)(使用FusionTablesLayer作爲多邊形,InfoBox作爲標籤) – geocodezip

+0

[Google Maps Javascript API v3 Map標籤和多邊形](http://stackoverflow.com/questions/12714031/google-maps-javascript-api-v3-map-label-and-polygons) – geocodezip

回答

0

使用google-maps-utility-library

設置標籤內容,找到你的多邊形center position和多數民衆贊成:)

var labelOptions = { 
    content: label, 
    boxStyle: { 
     textAlign: "center", 
     fontSize: "8pt", 
     width: "50px" 
    }, 
    disableAutoPan: true, 
    pixelOffset: new google.maps.Size(-25, 0), 
    position: this.my_getBounds(gpoints).getCenter(), 
    closeBoxURL: "", 
    isHidden: false, 
    pane: "mapPane", 
    enableEventPropagation: true 
}; 

var polygonLabel = new InfoBox(labelOptions); 
polygonLabel.open(map); 
-1

maplabel呈現在mapPane,通常低於呈現一個畫布上的文字floatPane中的所有zIndex值。 爲了使mapPane畫布到你的zIndex的順序,嘗試:

var mapLabel = new MapLabel({ 
    position: new google.maps.LatLng(yourLat, yourLng), 
    text: 'test', 
    zIndex: 101}); 
$(mapLabel.getPanes().mapPane).css('z-index', mapLabel.zIndex); 
1

太晚,但我面臨同樣的問題,這個代碼工作正常!

var triangleCoords = [ 
    { lat:30.655993, lng: 76.732375 }, 
    { lat: 30.651379, lng: 76.735808}, 
    { lat: 30.653456, lng: 76.729682} 
] 

var bermudaTriangle = new google.maps.Polygon({ 
    paths: triangleCoords , 
    strokeColor: '#FF0000', 
    strokeOpacity: 0.8, 
    strokeWeight: 2, 
    fillColor: '#FF0000', 
    fillOpacity: 0.35 
}); 
attachPolygonInfoWindow(bermudaTriangle) 

function attachPolygonInfoWindow(polygon) { 
    var infoWindow = new google.maps.InfoWindow(); 
    google.maps.event.addListener(polygon, 'mouseover', function (e) { 
     infoWindow.setContent("Polygon Name"); 
     var latLng = e.latLng; 
     infoWindow.setPosition(latLng); 
     infoWindow.open(map); 
    }); 
} 
+0

工作正常!非常感謝。 –

相關問題