Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put label on Google Maps polygon received by GeoJson data

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

}
like image 942
DehMotth Avatar asked Oct 31 '22 16:10

DehMotth


1 Answers

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.

like image 61
Sarah Avatar answered Nov 09 '22 15:11

Sarah