52,782
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string GetXML(string MyXMLurl)
{
string returnStr = "";
try
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
string xml = string.Empty;
System.Net.HttpWebRequest all_codeRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(MyXMLurl);
System.Net.HttpWebResponse all_codeResponse = (System.Net.HttpWebResponse)all_codeRequest.GetResponse();
if (all_codeResponse.StatusCode == System.Net.HttpStatusCode.OK)
{
string tempstr = all_codeResponse.ContentEncoding;
System.IO.StreamReader the_Reader = new System.IO.StreamReader(all_codeResponse.GetResponseStream(), System.Text.Encoding.UTF8);
xml = the_Reader.ReadToEnd();
doc.LoadXml(xml);
///根据里面的节点 自己 解析
System.Xml.XmlNode node = doc.SelectSingleNode("result");
string nodeStr = node.InnerXml;
System.Xml.XmlNodeList nodeList = node.ChildNodes;
//保存xml文件
doc.Save(@"./XDCPGWeb/XML/proxyHandler.xml");
}
return xml;
}
catch
{
return returnStr;
}
}
}
DisplayRoute = function(XMLurl){
try
{
var pointList = [];
$(document).ready(function(){
$.ajax(
{
type:"post",
url:"WebService.asmx/GetXML",
data:{MyXMLurl:XMLurl},
cache:false,
success: function(data) {
var myData=data.documentElement.textContent;
if (window.DOMParser)//firefox内核的浏览器
{
alert(1);
parser=new DOMParser();
xmlDoc=parser.parseFromString(myData,"text/xml");
}
else // Internet Explorer
{
alert(2);
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
// xmlDoc.async="false";
xmlDoc.loadXML(myData);
}
var items = xmlDoc.getElementsByTagName("routelatlon").length;
alert(3);
for(var i =0;i<items;i++){
var ll ;
if(!xmlDoc.getElementsByTagName("routelatlon")[i].text){
alert(4);
ll = xmlDoc.getElementsByTagName("routelatlon")[i].textContent.split(";");
}else{
alert(5);
ll = xmlDoc.getElementsByTagName("routelatlon")[i].text.split(";");
}
var length = ll.length;
for(var j = 0; j<parseInt(length)-1;j++){
var lonlat = ll[j];
var lonlat = lonlat.split(",");
var newPoint = new GeoSurf.Geometry.Point(lonlat[0],lonlat[1]);
pointList.push(newPoint);
}
alert(7);
var linearRing = new GeoSurf.Geometry.LinearRing(pointList);
DC.Route.lineFeature = new GeoSurf.Feature.Vector(new GeoSurf.Geometry.LineString(pointList),null,DC.Route.style_blue);
DC.Route.lineFeature.style.strokeColor ="#E60000";
DC.Route.routeLayer.addFeatures([DC.Route.lineFeature]);
}
}
});
});
}
catch (oError)
{
alert(oError);
}
}