如何在一张地图上显示多个 KML 文件

How to display multiple KML files on one map

我正在尝试使用 JS 通过 Google 的 API 在 google 地图上显示多个历史形状边界。我目前有一个 KML 文件 displayed correctly,但我希望同时显示其中的 100 个,并能够突出显示特定的一个。这是我现在加载一个 kml 文件的方式:

function loadKmlLayer(src, map) {
    var kmlLayer = new google.maps.KmlLayer(src, {
    preserveViewport: false,
    map: map
  });

有没有办法同时显示数百个?我可以拒绝的数量有限制吗?提前致谢

您可以在每个 KmlLayer 中显示一个,但除了 hide/show 它们之外您无法控制它们。

有一个限制,在某些时候内部 URL 请求(包括所有单独的 KmlLayer url)超过了限制,并且显示了 none 个。 Described in the documentation:

There is a limit on the number of KML Layers that can be displayed on a single Google Map. If you exceed this limit, none of your layers will display. The limit is based on the total length of all URLs passed to the KMLLayer class, and consequently will vary by application; on average, you should be able to load between 10 and 20 layers without hitting the limit.

您可以将您的 KML 导入 FusionTables,在 FusionTablesLayer 中显示它并通过 Google 地图 Javascript API v3 控制样式和显示(同样有限制,但似乎更有可能工作那一百个 KmlLayers)

我对这个问题的回答: 包含一个具有两种不同样式的示例,一种用于中心(蓝色边框),一种用于周边县(红色)。