【问题标题】:How to add label and title to point (marker) in geoJSON that would show up on Google Maps once loaded如何在geoJSON中添加标签和标题到点(标记),一旦加载就会显示在谷歌地图上
【发布时间】:2020-03-09 23:40:25
【问题描述】:

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

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

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

我正在生成点 json,每个标记都有不同的标记。另外我可能需要单独设置样式。

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

【问题讨论】:

    标签: javascript json google-maps geojson


    【解决方案1】:

    首先,您的 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
            }
        };
    });
    

    这意味着您可以使用custom SVG icons 生成标记并将event handlers 添加到它们。

    【讨论】:

    • 这对@Guntar 有帮助吗?
    猜你喜欢
    • 2018-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 2016-03-16
    相关资源
    最近更新 更多