Wie legt man in Google Map V3 ein Label innerhalb und außerhalb eines Polygons? Es gibt keine Label-Overlay wie in V2 Wenn ich die Bibliothek Maplabel verwenden, kann ich den Text hinein, aber nicht oben, auch wenn ich einen höheren Z-Index angeben. Dank PhilIn Google Map V3, wie wird ein Label innerhalb und außerhalb eines Polygons platziert?
10
A
Antwort
0
Verwenden google-maps-utility-library
Set Label Inhalt, center position Ihres Polygon finden und das ist es :)
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 seinen Text in der mapPane auf einer Leinwand macht, die normalerweise unter rendert Alle zIndex-Werte im floatPane. die mapPane Leinwand in der zIndex Ordnung zu bringen, versuchen:
var mapLabel = new MapLabel({
position: new google.maps.LatLng(yourLat, yourLng),
text: 'test',
zIndex: 101});
$(mapLabel.getPanes().mapPane).css('z-index', mapLabel.zIndex);
1
Es ist zu spät, aber ich habe das gleiche Problem und dieser Code funktioniert gut konfrontiert!
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
funktioniert gut !. Danke vielmals. –
Haben Sie das jemals herausgefunden? –
Suchen Sie etwas wie [this] (http://www.geocodepzip.com/geoxml3_test/v3_FusionTables_zipcode_map_whiteBg.html) (verwendet FusionTablesLayer für das Polygon, InfoBox für das Label) – geocodezip
möglich Duplikat von [Google Maps Javascript API v3 Karte Label und Polygone] (http://stackoverflow.com/questions/12714031/google-maps-javascript-api-v3-map-label-and-polygons) – geocodezip