适用于 Google 地图的县 KML 数据
County KML data that works with Google Maps
我想在我的地图上显示县界线。我发现了几个转换后的人口普查数据的 KML 以不同的分辨率显示。
我创建了一个 Google 站点地图并上传了几个 KML,包括 Google 用作示例的 CTA.kml。 CTA(芝加哥)显示 w/o 问题,因此我知道我的网站设置正确。但是当我link到gz_2010_us_050_00_20m.kml(来自美国人口普查局)或cb_2014_us_county_20m.kml时,什么也没有出现。
我认为 kml 格式对 Google 地图无效,但我没有收到错误或任何消息。它只是没有出现。
我包含了一个我知道是正确的小测试脚本,因为我从 Google 那里偷了它。
如果是 KML 格式问题,有人知道美国县界线的 KML 吗?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<title>KML Layers</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: {lat: 41.876, lng: -87.624}
});
var ctaLayer = new google.maps.KmlLayer({
url: 'https://sites.google.com/site/countykmltester/gz_2010_us_050_00_20m.kml',
map: map
});
google.maps.event.addListener(ctaLayer, "status_changed", function() {
alert( "Kml Status:"+ctaLayer.getStatus());
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?callback=initMap">
</script>
</body>
</html>
将您的 KML 文件分成 3 个部分,将每个文件压缩(使其成为 KMZ)。他们工作(状态正常)。原来的错误信息似乎误导了...
name | kml size | kmz size |
-------------------------------------------------
gz_2010_us_050_00_20m_A | 2,687,331 | 932,267 |
gz_2010_us_050_00_20m_B | 2,633,246 | 836,947 |
gz_2010_us_050_00_20m_C | 2,696,354 | 927,571 |
----- original file -----------------------------
gz_2010_us_050_00_20m | 8,015,535 | 2,693,916 |
来自关于 SO 的这个问题:Max. Number of Placemarks in KML for Google Maps:
(此信息曾经在文档中,但现在已不再可用,link on archive.org)
Google 地图中 KML 呈现的大小和复杂度限制
Google Maps currently has specific limitations to the size and complexity of loaded KML files. Below is a summary of the current limits:
Note: these limits are temporary and are subject to change at any time.
Maximum fetched file size (raw KML, raw GeoRSS, or compressed KMZ) 3MB
Maximum uncompressed KML file size 10MB
Maximum number of Network Links 10
Maximum number of total document-wide features 1,000
代码片段:
var geocoder;
var map;
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: {
lat: 41.876,
lng: -87.624
}
});
var layerA = new google.maps.KmlLayer({
url: 'http://www.geocodezip.com/geoxml3_test/kmz/gz_2010_us_050_00_20m_A.kmz',
map: map
});
google.maps.event.addListener(layerA, 'status_changed', function() {
document.getElementById('status').innerHTML += "layerA:" + layerA.getStatus() + "<br>";
})
var layerB = new google.maps.KmlLayer({
url: 'http://www.geocodezip.com/geoxml3_test/kmz/gz_2010_us_050_00_20m_B.kmz',
map: map
});
google.maps.event.addListener(layerB, 'status_changed', function() {
document.getElementById('status').innerHTML += "layerB:" + layerB.getStatus() + "<br>";
})
var layerC = new google.maps.KmlLayer({
url: 'http://www.geocodezip.com/geoxml3_test/kmz/gz_2010_us_050_00_20m_C.kmz',
map: map
});
google.maps.event.addListener(layerC, 'status_changed', function() {
document.getElementById('status').innerHTML += "layerC:" + layerC.getStatus() + "<br>";
})
}
google.maps.event.addDomListener(window, "load", initMap);
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="status"></div>
<div id="map"></div>
我想在我的地图上显示县界线。我发现了几个转换后的人口普查数据的 KML 以不同的分辨率显示。
我创建了一个 Google 站点地图并上传了几个 KML,包括 Google 用作示例的 CTA.kml。 CTA(芝加哥)显示 w/o 问题,因此我知道我的网站设置正确。但是当我link到gz_2010_us_050_00_20m.kml(来自美国人口普查局)或cb_2014_us_county_20m.kml时,什么也没有出现。
我认为 kml 格式对 Google 地图无效,但我没有收到错误或任何消息。它只是没有出现。
我包含了一个我知道是正确的小测试脚本,因为我从 Google 那里偷了它。
如果是 KML 格式问题,有人知道美国县界线的 KML 吗?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<title>KML Layers</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: {lat: 41.876, lng: -87.624}
});
var ctaLayer = new google.maps.KmlLayer({
url: 'https://sites.google.com/site/countykmltester/gz_2010_us_050_00_20m.kml',
map: map
});
google.maps.event.addListener(ctaLayer, "status_changed", function() {
alert( "Kml Status:"+ctaLayer.getStatus());
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?callback=initMap">
</script>
</body>
</html>
将您的 KML 文件分成 3 个部分,将每个文件压缩(使其成为 KMZ)。他们工作(状态正常)。原来的错误信息似乎误导了...
name | kml size | kmz size | ------------------------------------------------- gz_2010_us_050_00_20m_A | 2,687,331 | 932,267 | gz_2010_us_050_00_20m_B | 2,633,246 | 836,947 | gz_2010_us_050_00_20m_C | 2,696,354 | 927,571 | ----- original file ----------------------------- gz_2010_us_050_00_20m | 8,015,535 | 2,693,916 |
来自关于 SO 的这个问题:Max. Number of Placemarks in KML for Google Maps:
(此信息曾经在文档中,但现在已不再可用,link on archive.org)
Google 地图中 KML 呈现的大小和复杂度限制
Google Maps currently has specific limitations to the size and complexity of loaded KML files. Below is a summary of the current limits: Note: these limits are temporary and are subject to change at any time. Maximum fetched file size (raw KML, raw GeoRSS, or compressed KMZ) 3MB Maximum uncompressed KML file size 10MB Maximum number of Network Links 10 Maximum number of total document-wide features 1,000
代码片段:
var geocoder;
var map;
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: {
lat: 41.876,
lng: -87.624
}
});
var layerA = new google.maps.KmlLayer({
url: 'http://www.geocodezip.com/geoxml3_test/kmz/gz_2010_us_050_00_20m_A.kmz',
map: map
});
google.maps.event.addListener(layerA, 'status_changed', function() {
document.getElementById('status').innerHTML += "layerA:" + layerA.getStatus() + "<br>";
})
var layerB = new google.maps.KmlLayer({
url: 'http://www.geocodezip.com/geoxml3_test/kmz/gz_2010_us_050_00_20m_B.kmz',
map: map
});
google.maps.event.addListener(layerB, 'status_changed', function() {
document.getElementById('status').innerHTML += "layerB:" + layerB.getStatus() + "<br>";
})
var layerC = new google.maps.KmlLayer({
url: 'http://www.geocodezip.com/geoxml3_test/kmz/gz_2010_us_050_00_20m_C.kmz',
map: map
});
google.maps.event.addListener(layerC, 'status_changed', function() {
document.getElementById('status').innerHTML += "layerC:" + layerC.getStatus() + "<br>";
})
}
google.maps.event.addDomListener(window, "load", initMap);
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="status"></div>
<div id="map"></div>