您可以通过
Google Earth API
从任何网络可访问的URL(相同的服务器或其他),然后迭代KML对象并以编程方式更改样式和多边形颜色。
var href = 'http://code.google.com/'
+ 'apis/earth/documentation/samples/kml_example.kml';
google.earth.fetchKml(ge, href, function(kmlObject) {
if (kmlObject) {
checkObject(kmlObject);
// append KML objects to current view
ge.getFeatures().appendChild(kmlObject);
}
});
function checkObject(kmlObject) {
var type = kmlObject.getType();
if (type == 'KmlDocument' || type == 'KmlFolder') {
var features = kmlObject.getFeatures();
if (features.hasChildNodes()) {
var children = features.getChildNodes();
for (i=0; i < children.getLength(); i++) {
checkObject(children.item(i));
}
}
} else if (type == 'KmlPlacemark') {
// check/set style, change color, etc.
// ...
}
}
参考文献:
https://developers.google.com/earth/documentation/kml#fetchkml_and_parsekml