我正在尝试在Google map 上显示KML。该 map 可以完美加载,但KML根本不显示。另外,我在控制台中没有收到任何错误消息。
我从gadm.org下载了.kmz文件,将其解压缩并解压缩了.kml文件。
这是我的代码,以及我的KML的URL。
http://locallocal.com/endline/mex2.kml
<script>
var map;
var src = 'http://locallocal.com/endline/mex2.kml';
/**
* Initializes the map and calls the function that loads the KML layer.
*/
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(-19.257753, 146.823688),
zoom: 2,
mapTypeId: 'roadmap'
});
loadKmlLayer(src, map);
}
/**
* Adds a KMLLayer based on the URL passed. Clicking on a marker
* results in the balloon content being loaded into the right-hand div.
* @param {string} src A URL for a KML file.
*/
function loadKmlLayer(src, map) {
var kmlLayer = new google.maps.KmlLayer(src, {
suppressInfoWindows: true,
preserveViewport: false,
map: map
});
google.maps.event.addListener(kmlLayer, 'click', function(event) {
var content = event.featureData.infoWindowHtml;
var testimonial = document.getElementById('capture');
testimonial.innerHTML = content;
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=[MYKEY]&callback=initMap">
最佳答案
我收到该KML的Kml状态:INVALID_DOCUMENT(link)。您的KML太大(为5.8 MB),不符合the documentation的要求:
我可以用没有该限制的geoxml3加载它。
或者我可以将其压缩(将其制成.kmz文件),并且可以正常使用(1.3 MB):
loading it as a KMZ file
关于javascript - KML图层未显示在 map 上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42149489/