I want to put labels with information (or a div with a label) on polygons which are drawn by the below code fragment. Style attributes were applied successfully to the features (of type Polygon). Does anybody know how add text to this features which will be shown on the centre of the polygons?
function handleGeoJson(data) {
map.data.addGeoJson(data);
map.data.setStyle(function(feature) {
if (feature.getProperty('isColorful')) {
color = feature.getProperty('color');
}
return /** @type {google.maps.Data.StyleOptions} */( {
fillColor : color,
strokeColor : color,
strokeWeight : 1,
});
});
map.data.setStyle(featureStyle);
}
If you have a way to get the center of your polygon (like this answer, or with preprocessing your data), the Google Maps Map Label library can be used to put your text at that point on the map.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With