欢迎为《GIS初学者》投稿!网址:http://www.gisuniversity.net/thread.php?fid=22
SharpMap发布WMS,OpenLayers显示出乱图问题
上一篇 /
下一篇 2008-07-08 10:06:59
/ 个人分类:GIS研习
小弟用SharpMap做WMS服务,用OpenLayer显示,结果出现如下现象:

但是SharpMap提供的WMS服务是正常的:

改用MapServer做服务,OpenLayer显示正常:

俺对WMS理解很浅,高手GG们帮俺分析一下,问题可能出在哪儿呢?[code]//初始化
function init(){
//边界
var bounds = new OpenLayers.Bounds(488236.247486, 3513438.941320, 505728.189386, 3527536.968320);
//参数
var ptions = {
maxExtent: bounds,
maxScale: 10000,
minScale: 100000,
projection: "EPSG:2437",
units: 'm'
};
//创建地图
map = new OpenLayers.Map('map', options);
//!!!!!!!!!
//SharpMap的服务
var strUrl = "wms.ashx?REQUEST=GetMap&Layers=街道,小区&STYLES=&CRS=EPSG:2437&BBOX=488236.247486, 3513438.941320, 505728.189386, 3527536.968320&WIDTH=600&HEIGHT=300&FORMAT=image/png&VERSION=1.3.0";
//!!!!!!!!!
//MapServer的服务
//var strUrl = "http://localhost:81/cgi-bin/mapserv.exe?map=/ms4w/apache/htdocs/Map/cdstm.map";
var objLayer;
//创建图层
bjLayer = new OpenLayers.Layer.WMS("街道", strUrl , {layers: 'towns'} );
map.addLayer(objLayer);
bjLayer = new OpenLayers.Layer.WMS("小区", strUrl, {layers: 'communities',transparent: "true"} );
map.addLayer(objLayer);
//添加控件
map.addControl(new OpenLayers.Control.LayerSwitcher()); //图层切换
map.addControl(new OpenLayers.Control.MousePosition()); //鼠标位置
if (!map.getCenter()) map.zoomToMaxExtent();
}[/code]换什么数据都一样
根据网友提示,我去掉了一些参数后,整幅图终于能够正确显示。[code]var strUrl = "wms.ashx?REQUEST=GetMap&Layers=街道,小区&CRS=EPSG:2437&FORMAT=image/png&VERSION=1.3.0";[/code]然而放大之后,乱图又出现了:

并且,我很奇怪的是,源代码的WmsServer.cs的ParseQueryString方法中有这么一段:[code] //Check for required parameters
if (context.Request.Params["LAYERS"] == null)
{ WmsException.ThrowWmsException("Required parameter LAYERS not specified"); return; }
if (context.Request.Params["STYLES"] == null)
{ WmsException.ThrowWmsException("Required parameter STYLES not specified"); return; }
if (context.Request.Params["CRS"] == null)
{ WmsException.ThrowWmsException("Required parameter CRS not specified"); return; }
else if (context.Request.Params["CRS"] != "EPSG:" + map.Layers[0].SRID.ToString())
{ WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidCRS, "CRS not supported"); return; }
if (context.Request.Params["BBOX"] == null)
{ WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified"); return; }
if (context.Request.Params["WIDTH"] == null)
{ WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter WIDTH not specified"); return; }
if (context.Request.Params["HEIGHT"] == null)
{ WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter HEIGHT not specified"); return; }
if (context.Request.Params["FORMAT"] == null)
{ WmsException.ThrowWmsException("Required parameter FORMAT not specified"); return; }[/code]有一些参数我分明没有请求,为什么没有出错呢?
我试图F11跟踪,但发现在这里并不是逐语句运行下去的,会时不时地蹦回到wms.ashx的SharpMap.Web.Wms.WmsServer.ParseQueryString(myMap, description);语句。并且,我添加监视context.Request.Params["BBOX"],一开始总是计算超时,然后莫名其妙的就有值了。很费解。不知有没有人对这里比较熟悉的?多谢!
相关阅读:
- OpenLayers的Vector与Markers (Classicning, 2007-7-24)
- OpenLayers 离线文档 (Classicning, 2007-9-27)
- OpenLayers 项目完整分析——(二)源代码总体结构分析 (liulin, 2008-1-07)
- OpenLayers 项目分析——(三)BaseTypes (liulin, 2008-1-08)
- OpenLayers 项目分析——(三)BaseTypes (续) (liulin, 2008-1-08)
- OpenLayers项目分析——(八)地图表现(续) (liulin, 2008-1-20)
- OpenLayers项目分析——(八)地图表现(续) (liulin, 2008-1-20)
- OpenLayers项目分析——(九)控件 (liulin, 2008-1-21)
- OpenLayers项目分析——(十)事件机制分析 (liulin, 2008-1-21)
- zzflash 实现 OpenLayers (chongya, 2008-5-08)
导入论坛
收藏
分享给好友
管理
举报
TAG:
OpenLayers
SharpMap
WMS