OpenLayer加载WFS图层及C#编写ASP.net代理处理跨域问题
发布时间:2021-11-20 18:07:37 所属栏目:教程 来源:互联网
导读:用C#编写代理网上普遍是这样的: public class GeoServerProxy1 : IHttpHandler { public void ProcessRequest(HttpContext context) { if (context.Request.QueryString[URL] != null) { string url = ; url = context.Request.QueryString[URL].ToString()
|
用C#编写代理网上普遍是这样的: public class GeoServerProxy1 : IHttpHandler { public void ProcessRequest(HttpContext context) { if (context.Request.QueryString["URL"] != null) { string url = ""; url = context.Request.QueryString["URL"].ToString(); HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(url); loHttp.Timeout = 10000; // 10 secs loHttp.UserAgent = "Web Client"; HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse(); Encoding enc = Encoding.GetEncoding(65001); StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc); string lcHtml = loResponseStream.ReadToEnd(); context.Response.Write(lcHtml); loWebResponse.Close(); loResponseStream.Close(); } } public bool IsReusable { get { return false; } } } 但是上面这种情况,没有考虑post,不适用于openlayers官方的wfs协议访问,但是可以用于http查询方式的访问,例如: JS代码: vectorLayer = new OpenLayers.Layer.Vector("覆冰点", { protocol: new OpenLayers.Protocol.HTTP({ //url: "http://10.180.80.206:9000/geoserver/sdgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=sdgis:V_YL_24&maxFeatures=50", //url: "http://10.180.80.206:9000/geoserver/sdgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=sdgis:GIS_WEATHER_FORECAST&maxFeatures=50", url: "http://10.180.80.206:9000/geoserver/sdgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=sdgis:V_FBJC_PT&maxFeatures=50", format: new OpenLayers.Format.GML() }), styleMap: new OpenLayers.StyleMap({ 'default': { strokeColor: "#00FF00", strokeOpacity: 1, strokeWidth: 2, fillColor: "#FF0000", fillOpacity: 1, pointRadius: 6, strokeDashstyle: 'longdashdot', pointerEvents: "visiblePainted", externalGraphic: "snow.gif", graphicWidth: 12, graphicHeight: 12, //label: "name: ${OWNER}, age: ${FLAGS}", fontColor: "${favColor}", fontSize: "12px", fontFamily: "Courier New, monospace", fontWeight: "bold", labelAlign: "${align}", labelXOffset: "${xOffset}", labelYOffset: "${yOffset}" } }), renderers: renderer, strategies: [new OpenLayers.Strategy.Fixed()] }); ![]() (编辑:南通站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |



