[英]How to add label and title to point (marker) in geoJSON that would show up on Google Maps once loaded
如何在 geoJSON 中添加 label 文本,使其顯示在谷歌地圖的標記(點)上?
我一直在嘗試這個,但 label 或標題沒有出現。
"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 圖標生成標記並向它們添加事件處理程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.