6

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);

}
Brian Burns
  • 20,575
  • 8
  • 83
  • 77
DehMotth
  • 679
  • 3
  • 12
  • 21
  • related question [Google Maps Javascript API v3 Map Label and Polygons](http://stackoverflow.com/questions/12714031/google-maps-javascript-api-v3-map-label-and-polygons/12716168#12716168) – geocodezip Sep 19 '14 at 12:33
  • 1
    related question [Google Maps get the center of coordinates](http://stackoverflow.com/questions/19956691/google-maps-get-the-center-of-coordinates/19957258#19957258) – geocodezip Sep 19 '14 at 12:33

1 Answers1

2

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.

Community
  • 1
  • 1
Sarah
  • 21
  • 4