没有尝试过 KML 解析器,但这里有一个使用 Geoserver geoJSON 的示例
<style>
.layer path { fill: none; stroke: blue; stroke-width: 2;}
.layer circle { fill: lightcoral; fill-opacity: .5; stroke: brown; }
</style>
<script>
function myCallback(data) {
po = org.polymaps;
map = po.map()
.container(document.getElementById("map").appendChild(po.svg("svg")))
.center({
lat:(data.bbox[1] + (data.bbox[3]-data.bbox[1])/2),
lon:(data.bbox[0] + (data.bbox[2]-data.bbox[0])/2)
})
.zoom(15)
.add(po.interact());
// points
map.add(po.geoJson().features( data.features ));
// make path
var paths=[];
for (var i=0;i<data.features.length;i++)
paths.push(data.features[i].geometry.coordinates);
map.add(po.geoJson()
.features([{"geometry":{"coordinates":paths, "type": "LineString"}}]));
}
var client = document.createElement("script");
client.src = 'http://localhost:8082/geoserver/ows?'+
'service=WFS&version=1.0.0&request=GetFeature'+
'&typeName=tiger:poi&maxFeatures=50'+
'&outputFormat=json&format_options=callback:myCallback';
document.body.appendChild(client);
</script>