環(huán)境: 服務(wù)器 geoserver2.4.1
創(chuàng)新互聯(lián)專注于友好網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供友好營銷型網(wǎng)站建設(shè),友好網(wǎng)站制作、友好網(wǎng)頁設(shè)計、友好網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造友好網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供友好網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
開發(fā)機(jī)訪問服務(wù)器發(fā)布的wms 存在跨域問題,研究兩天終于找到解決方案。
主要思路是: 使用jquery的ajax 代替Groserver的request, 然后將wms的請求地址轉(zhuǎn)發(fā)到.net的處理程序, 使用.net的處理程序進(jìn)行跨域處理。
function mouseClick(e) { var layer = new Array(); layer = map.getLayersByName("Simple_Geometry"); if (layer != null) for (var i = 0; i < layer.length; i++) { map.removeLayer(layer[i]); } var wms_url = "http://10.72.4.219:8089/geoserver/xj/wms?"; var params = { REQUEST: "GetFeatureInfo", BBOX: map.getExtent().toBBOX(), WIDTH: map.size.w, HEIGHT: map.size.h, X: e.xy.x, Y: e.xy.y, SERVICE: "WMS", QUERY_LAYERS: map.layers[0].params.LAYERS, INFO_FORMAT: 'text/html', FEATURE_COUNT: 50, Layers: 'xj:cswl_group', Styles: "", format: "application/vnd.ogc.gml", EXCEPTIONS: "application/vnd.ogc.se_xml", // Exception 類型 srs: 'EPSG:4326' }; var domainUrl = "crossDomain.ashx?URL="; var request = parpreUrl(wms_url, params); request = encodeURIComponent(encodeURIComponent(request)); $.post(domainUrl + request, "", function (e) { document.getElementById('nodelist').innerHTML = e; }); OpenLayers.Event.stop(e); } function parpreUrl(url, paramsObj) { for (var k in paramsObj) { url += (k + "=" + paramsObj[k] + "&"); } return url; }
如果使用Groserver.ProxyHost , 會遇到 triggerEvent未定義問題,所以使用了jqueyr的ajax代替 Geoserver.Request ,另外
public void Proce***equest(HttpContext context) { context.Response.ContentType = "text/html"; string url = ""; url = context.Request.QueryString["URL"].ToString(); url = context.Server.UrlDecode(url); 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(); }
這樣就可以解決 跨域問題