use*_*799 5 google-maps polygon google-maps-api-3 google-maps-markers
我在美国地图上为每个州绘制了多边形。我希望在其顶部显示一个值(文本/整数)。我找不到任何能够在多边形顶部显示文本的多边形选项。有哪些方法可以做到这一点?
var poly = new google.maps.Polygon({
clickable: true,
paths: pts,
strokeColor: '#000000',
strokeOpacity: 0.3,
strokeWeight: 1,
fillColor: colour,
fillOpacity: 0.8,
title: name
});
polys.push(poly);
poly.setMap(map);
Run Code Online (Sandbox Code Playgroud)
您可以使用MapLabel Utility来完成此操作。只需设置标签的位置并通过对象应用选项即可。
label: new MapLabel({
text: result[index].name,
position:
new google.maps.LatLng(object.lat, object.lng), // the lat/lng of location of the label.
fontSize: 10,
fontColor: #000,
labelInBackground: true,
strokeColor: #000,
map: map // The map object to place the label on
})
Run Code Online (Sandbox Code Playgroud)