如何在geoJSON中添加标签和标题以指向点(标记),加载后将显示在Google地图上

问题描述 投票:0回答:1

如何在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个回答
0
投票

首先,您的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添加到它们。

© www.soinside.com 2019 - 2024. All rights reserved.