将标签贴在由GeoJson数据收到的Google地图多边形上 [英] Put label on Google Maps polygon received by GeoJson data

查看:132
本文介绍了将标签贴在由GeoJson数据收到的Google地图多边形上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在由以下代码片段绘制的多边形上放置带有信息的标签(或带有标签的div)。样式属性已成功应用于特征(类型为Polygon)。有人知道如何将文字添加到这些要显示在多边形中心的特征吗?

 函数handleGeoJson(data){

map.data.addGeoJson(data);

map.data.setStyle(function(feature){

if(feature.getProperty('isColorful')){
color = feature.getProperty('颜色');
}
return / ** @type {google.maps.Data.StyleOptions} * /({
fillColor:color,
strokeColor:color,
strokeWeight:1,
});
});

map.data.setStyle(featureStyle);



解决方案

如果你有一种方法来获取多边形的中心(如此答案或预处理您的数据), Google地图地图标签库可用于将您的文本放在地图上的那一点。

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.

这篇关于将标签贴在由GeoJson数据收到的Google地图多边形上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆