示例代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript" language="javascript"> function LoadKML() { try { var sg = CreateSGObj(); var kmlLayer = sg.Creator.CreateKMLLayer(abspath()+"/Binoculars.kml",""); } catch (e) { alert(e); } } /* 功能: 创建sgworld对象 备注: 赵贺 2011.04.01. */ function CreateSGObj() { var obj = $("sgworld"); if (obj == null) { obj = document.createElement(‘object‘); document.body.appendChild(obj); obj.name = "sgworld"; obj.id = "sgworld"; obj.classid = "CLSID:3a4f9197-65a8-11d5-85c1-0001023952c1"; } return obj; } function $(id) { return window.document.getElementById(id); } //-------------- // abspath function abspath() { var abspath = unescape(window.location.href); // Remove query String var index = abspath.indexOf("?"); if (index > 0) abspath = abspath.substr(0, index - 1); index = abspath.lastIndexOf("/"); var index2 = abspath.lastIndexOf("\\"); index = (index > index2) ? index : index2; if (index <= 0) return abspath; abspath = abspath.substring(0, index); if (abspath.substring(0, 1) == "/") abspath = abspath.slice(1); var re = /file:\/\/\//gi; if (abspath.match(re) != null) abspath = abspath.replace(re, ""); // if this is indeed a local file, we strip the "file://" prefix from it. return (abspath); } </script> </head> <body > <input id="Button1" type="button" value="加载KML" onclick="LoadKML()" /> <object id="TE3DWindow" classid="CLSID:3a4f9192-65a8-11d5-85c1-0001023952c1" width="1000px" height="600px"> </object> <OBJECT ID="TerraExplorerInformationWindow" CLASSID="CLSID:3a4f9193-65a8-11d5-85c1-0001023952c1" width="200px" height="600px" ></OBJECT> </body> </html>
时间: 2024-10-22 11:52:24