admin管理员组

文章数量:1391937

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

}

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

}
Share Improve this question edited Oct 21, 2017 at 18:49 Brian Burns 22.2k10 gold badges93 silver badges79 bronze badges asked Sep 19, 2014 at 9:23 DehMotthDehMotth 6893 gold badges13 silver badges22 bronze badges 2
  • related question Google Maps Javascript API v3 Map Label and Polygons – geocodezip Commented Sep 19, 2014 at 12:33
  • 1 related question Google Maps get the center of coordinates – geocodezip Commented Sep 19, 2014 at 12:33
Add a ment  | 

1 Answer 1

Reset to default 3

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.

本文标签: javascriptPut label on Google Maps polygon received by GeoJson dataStack Overflow