1

嗨,我有 2 套 KML 文件要添加到谷歌地图中。但是我无法让这 2 套同时存在于地图上。这些套单独工作正常。有人可以指导我吗?我将 KML 文件设置如下

kml19 =  new google.maps.KmlLayer({url:'url',preserveViewport: true,map: map});
kml19.setMap(map);

[已编辑]

我尝试将两组KML文件合并设置在地图上。发现在地图上设置了16个KML文件后,我们再次尝试添加一个,地图没有显示任何KML文件。是我们可以添加的 KML 文件的数量有什么限制吗?

    kml11 = new  google.maps.KmlLayer({url:'url1',preserveViewport: true,map: map});
    kml12 =  new google.maps.KmlLayer({url:'url2',preserveViewport: true,map: map});
    kml13 = new  google.maps.KmlLayer({url:'url3',preserveViewport: true,map: map});
    kml14 =  new google.maps.KmlLayer({url:'url4',preserveViewport: true,map: map});
    kml15 =  new google.maps.KmlLayer({url:'url5',preserveViewport: true,map: map});
    kml16 =  new google.maps.KmlLayer({url:'url6',preserveViewport: true,map: map});
    kml17 =  new google.maps.KmlLayer({url:'url7',preserveViewport: true,map: map});
    kml18 =  new google.maps.KmlLayer({url:'url8',preserveViewport: true,map: map});
    kml19 =  new google.maps.KmlLayer({url:'url9',preserveViewport: true,map: map});

    kml11.setMap(map);
    kml12.setMap(map);
    kml13.setMap(map);
    kml14.setMap(map);
    kml15.setMap(map);
    kml16.setMap(map);
    kml17.setMap(map);
    kml18.setMap(map);
    kml19.setMap(map);

    kml1    =  new google.maps.KmlLayer({url:'url10',preserveViewport: true,map: map});
    kml2    = new google.maps.KmlLayer({url:'url11',preserveViewport: true,map: map});
    kml3    = new google.maps.KmlLayer({url:'url12',preserveViewport: true,map: map});
    kml4    = new google.maps.KmlLayer({url:'url13',preserveViewport: true,map: map});
    kml5    = new google.maps.KmlLayer({url:'url14',preserveViewport: true,map: map});
    kml51   =  new google.maps.KmlLayer({url:'url15',preserveViewport: true,map: map});
    kml52   =  new google.maps.KmlLayer({url:'url16',preserveViewport: true,map: map});     
    /*kml6  =  new google.maps.KmlLayer({url:'url17',preserveViewport: true,map: map});
    kml61   =  new google.maps.KmlLayer({url:'url18',preserveViewport: true,map: map});
    kml7    = new google.maps.KmlLayer({url:'url19',preserveViewport: true,map: map});
    kml71   = new google.maps.KmlLayer({url:'url20',preserveViewport: true,map: map});
    kml8    = new google.maps.KmlLayer({url:'url21',preserveViewport: true,map: map});
    kml9    =  new google.maps.KmlLayer({url:'url22',preserveViewport: true,map: map});
    kml91   =  new google.maps.KmlLayer({url:'url23',preserveViewport: true,map: map});*/

    kml1.setMap(map);

    kml2.setMap(map);

    kml3.setMap(map);

    kml4.setMap(map);

    kml5.setMap(map);

    kml51.setMap(map);
    kml52.setMap(map);      
    /*kml6.setMap(map);
    kml61.setMap(map);
    kml7.setMap(map);
    kml71.setMap(map);
    kml8.setMap(map);
    kml9.setMap(map);
    kml91.setMap(map);*/
4

1 回答 1

1

您需要为每个 URL 创建一个 KmlLayer 对象:

var kml19 =  new google.maps.KmlLayer({url:'url1',preserveViewport: true,map: map});
var kml11 =  new google.maps.KmlLayer({url:'url2',preserveViewport: true,map: map});

更新 您正在加载大量 KML 文件。可以加载的数量有限制,在文档中进行了描述

可以在单个 Google 地图上显示的 KML 图层的数量是有限制的。如果超出此限制,则不会显示任何图层。该限制基于传递给 KMLLayer 类的所有 URL 的总长度,因此会因应用程序而异;平均而言,您应该能够加载 10 到 20 层而不会达到限制。

于 2013-06-11T11:22:25.723 回答