日期:2014-05-16 浏览次数:20466 次
function loadXmlData(xmlfile) { // 利用google maps api中提供的方法加载xml var request = GXmlHttp.create(); request.open("GET", xmlfile, true); /* // 普通方法加载xml var request; if (window.ActiveXObject) { // 只能是ie加载了,其他的搞不定 request = new ActiveXObject("Microsoft.XMLDOM"); alert("ie"); request.async=true; // 异步加载 request.load(xmlfile); } else if (document.implementation && document.implementation.createDocument) { alert("Firefox, Mozilla, Opera, etc."); //request = document.implementation.createDocument("", "", null); //request.async=true; // 异步加载 //request.load(xmlfile); // Firefox 应该也不行,报错了 // request.addEventListener("load",initializeData,false); // request.load(xmlfile,"text/xml"); //Google Chrome 是可以加载上,但是又报错没有getElementsByTagName方法 //request = new window.XMLHttpRequest(); //request.open("GET",xmlfile,true); //request.send(null); } else { alert('Your browser cannot handle this script'); return; } */ request.onreadystatechange = function() { if(request.readyState == 4) { // 获得加载后的mxl对象 var xmlDoc = request.responseXML; var polylines = xmlDoc.documentElement.getElementsByTagName("polyline"); for(var i=0; i<polylines.length; i++) { addPolyline(polylines[i]); } var polygons = xmlDoc.documentElement.getElementsByTagName("polygon"); for(var i=0; i<polygons.length; i++) { addPolygon(polygons[i]); } } } request.send(null); }