如何在加载后显示在谷歌地图上的geoJSON中添加标签和标题指向(标记)



如何在geoJSON中添加标签文本,使其显示在谷歌地图上的标记(点(上?

我一直在尝试这个,但标签或标题没有出现。

"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [7.090301513671875,44.66743203082226]
},
"properties": {
"label": "W",
"title": "World Wide Web"
}]
}

我正在生成点json,每个标记都有一个不同的标记。此外,我可能需要单独设计。

有什么想法和建议吗?非常感谢。

首先,您的geojson无效。使用此:

{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[7.090301513671875,44.66743203082226]},"properties":{"label":"W","title":"World Wide Web"}}]}

其次,您可以在setStyle回调中添加自定义标记,如下所示:

map.data.setStyle(function (feature) {
return {
icon: {
path: "M-20,0a20,20 0 1,0 40,0a20,20 0 1,0 -40,0",
fillColor: '#FF0000',
fillOpacity: .6,
anchor: new google.maps.Point(0, 0),
strokeWeight: 0,
scale: 1
}
};
});

这意味着您可以使用自定义SVG图标生成标记,并向其添加事件处理程序。

最新更新