官网实例http://code.google.com/apis/ajax/playground/?exp=earth#hello,_earth
APi查看http://code.google.com/intl/zh-CN/apis/earth/documentation/reference/index.html
//加载kml文件
function addKML(url) {
//DS_ge为整个web控件对象
google.earth.fetchKml(DS_ge,url,function(kmlObject)
{
/**
if (!kmlObject) {
// show error
setTimeout(function() {
alert('Error loading KML.');
}, 0);
return;
}
else
{
DS_ge.getFeatures().appendChild(kmlObject);
});
}
url为数据发布的路径
在初始化成功initCallback函数里加入addKML(url)
function initCallback(object) {
DS_ge = object;
tools= new Tools();
DS_ge.getWindow().setVisibility(true);
//这里发布的数据是geoserver发布的wms数据,也可以说kml文件
addKML("http://192.168.0.33:8080/geoserver/wms/kml?layers=nci:ORA_GIS_TRANS_LINE");
addKML("http://192.168.0.33:8080/test/pt.kml");
var la = DS_ge.createLookAt('');
la.set(defaultview.lat,defaultview.lng,
defaultview.altitude, //高度
DS_ge.ALTITUDE_RELATIVE_TO_GROUND,
0, // heading
0, // straight-down tilt
50000 // range (inverse of zoom)
);
DS_ge.getView().setAbstractView(la);
tool_operate("0","select");
addToolbar();
changeMapToOverviewMap();
createNativeHTMLButton(locationx-hawkeyeIframe_width, locationy-hawkeyeIframe_heigt, hawkeyeIframe_width,hawkeyeIframe_heigt); // x, y, width, height
}