Put label on Google Maps polygon received by GeoJson data

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

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

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!