在 Google 地图中自定义 KML 图层时出现问题

发布于 2024-10-11 22:47:57 字数 294 浏览 5 评论 0原文

我有一个文件,将新南威尔士州的选举边界覆盖在谷歌地图上。每个选区上弹出的标记在缩小时确实会干扰地图的视觉效果。我已经找到了如何禁用信息窗口,但无法弄清楚如何一起关闭标记。

地图示例在这里:

http://www.codepress.com.au/nsw_lower_house_map.html

关闭标记后,是否有办法使整个选区多边形可点击以在 JS 中使用?

I have got a file which overlays the state of New South Wales' electoral boundaries onto a Google Map. The markers which popup on each electorate really interfere with the visuals of the map when zoomed out. I have found how to disable the info window, but can't work out how to turn the markers off all together.

Map example is here:

http://www.codepress.com.au/nsw_lower_house_map.html

With markers turned off, is there then a way to make the whole electorate polygon clickable to work with in JS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一身仙ぐ女味 2024-10-18 22:47:57

要使多边形可单击,请在将图层添加到地图后将事件侦听器绑定到图层。

ctaLayer.setMap(map);
                google.maps.event.addListener(ctaLayer, 'click', function(kmlEvent) {
                    var text = kmlEvent.featureData.name;
                    alert(text);
                })

上面将提醒您单击的要素的名称(前提是在 KML 中设置名称)。请注意:要使多边形能够“有效地”单击,需要设置填充。您的 KML 文件没有填充,因此唯一可单击的区域将是多边形的边界。您需要设置填充才能使此功能有用。

一般来说,KML 要素对象返回以下数据:

{
  author: {
    email: "[email protected]",
    name: "Mr Nobody",
    uri: "http://example.com"
  },
  description: "description",
  id: "id",
  infoWindowHtml: "html",
  name: "name",
  snippet: "snippet"
}

再次 - 前提是在 KML 中设置这些数据

要删除标记,您需要修改 KML 并删除所有地标及其包含的文件夹(其中未指定多边形) - 仅点数据(呈现为标记)。请确保在删除后重新验证您的 XML。

这是不带标记 http://www.mediafire.com/?f9ewd0c5ymk3ccv 的文件。但是,您需要确保多边形已设置填充,否则您将只能单击边框。

To make polygons clickable bind an event listener to a layer after you add layer to the map

ctaLayer.setMap(map);
                google.maps.event.addListener(ctaLayer, 'click', function(kmlEvent) {
                    var text = kmlEvent.featureData.name;
                    alert(text);
                })

The above will alert the name of the feature that you clicked on (providing the name is set in KML). PLEASE NOTE: for polygons to be "usefully" click able they need a fill to be set. Your KML file does not have the fill so the only area click able will be the border of the polygon. You will need to set the fill to make this feature useful.

In general The KML feature object returns the following data:

{
  author: {
    email: "[email protected]",
    name: "Mr Nobody",
    uri: "http://example.com"
  },
  description: "description",
  id: "id",
  infoWindowHtml: "html",
  name: "name",
  snippet: "snippet"
}

Again - providing these are set in KML

To get rid of the markers you will need to modify the KML and remove all Placemarks and their containing Folder which have no polygons specified in them - only Point data (which is rendered as a marker). Make sure you re-validate your XML after deletion.

Here is your file without the markers http://www.mediafire.com/?f9ewd0c5ymk3ccv . However you will need to make sure that your polys have fill set otherwise you will only be able to click on the borders.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文