如何在ArcGIS Server客户端应用中通过一个中心点和比例尺计算地图范围

文章编号 : 33746
软件: ArcGIS Server 9.0, 9.0.1, 9.1, 9.2, 9.3, 9.3.1
操作系统: Windows XP, 2003Server
已邀请:

EsriSupport

赞同来自:

ArcGIS Server .NET 和 Java的API提供了一个 CenterAndScale 类可以基于中心点和比例尺缩放到一个地图范围。 用户可以从地图出图的结果MapImage中获取MapExtent属性值。 如果不从地图出图结果中获取地图范围,而是在客户端进行计算,可以通过下面的算法进行计算。
示例#1 使用了DisplayTransformation对象,这需要使用ESRI的Display库,否则使用示例#2。示例#3则是将使用CenterAndScale对象替换为直接使用中心点和比例尺进行计算。 示例#1 (C#): 使用CenterAndScale 计算地图范围: /* ** esriDisplay library must be referenced.
The function requires MapServerInfo, ImageDisplay, CenterAndScale
object and returns IEnvelope
ServerContext is optional, only required when your application works
with ServerContext */
private IEnvelope ComputeExtent(IMapServerInfo pMapServerInfo, IImageDisplay pImageDisplay, ICenterAndScale pCenterAndScale, IServerContext pServerContex) { try { /* aRect holds information about the client side’s map size in pixel */ tagRECT aRect = new tagRECT(); aRect.top = 0; aRect.left = 0; aRect.bottom = pImageDisplay.Height; aRect.right = pImageDisplay.Width; /* when application uses ServerContext, DisplayTransformation will be created in ServerContext */ IDisplayTransformation pDT; if (pServerContex != null) pDT = pDT = new DisplayTransformationClass();pServerContex.CreateObject("esriDisplay.DisplayTransformation") as IDisplayTransformation; else
/* Setting different DisplayTransformation properties to compute extent */ pDT.Bounds = pMapServerInfo.FullExtent; IEnvelope pMDscExtent = pMapServerInfo.DefaultMapDescription.MapArea.Extent; pMDscExtent.CenterAt(pCenterAndScale.Center); pDT.VisibleBounds = pMDscExtent; pDT.SpatialReference = pMapServerInfo.DefaultMapDescription.SpatialReference; pDT.Units = pMapServerInfo.MapUnits; pDT.set_DeviceFrame(ref aRect); pDT.Resolution = pImageDisplay.DeviceResolution; pDT.ScaleRatio = pCenterAndScale.MapScale; /* printing map extent */ Debug.Print("New Map Extent - After ScaleRatio: " + pDT.FittedBounds.XMin.ToString() + ", " + pDT.FittedBounds.YMin.ToString() + ", " + pDT.FittedBounds.XMax.ToString() + ", " + pDT.FittedBounds.YMax.ToString());
//returning new map extent return pDT.FittedBounds; } catch (Exception exp) { MessageBox.Show(exp.Message, "Error in ComputeExtent", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } }
示例#2 (C#): 使用WSDL中的CenterAndScale对象计算地图范围:

/* The function requires MapServer WSDL’s MapServerInfo, ImageDisplay, CenterAndScale object and an already created EnvelopeN object (by ref) which will be modified */

private void ComputeExtent(MapServerWSDL.MapServerInfo pMSI, MapServerWSDL.ImageDisplay pImageDisplay, MapServerWSDL.CenterAndScale pCenterAndScale, ref MapServerWSDL.EnvelopeN pOutEnvelope) { try { /* dividing image width by DPI to get it in Inch */ double dblImgWidthInInch = pImageDisplay.ImageWidth / pImageDisplay.ImageDPI; double dblImgHeightInInch = pImageDisplay.ImageHeight / pImageDisplay.ImageDPI;
/* converting Inch to meter (assume the map is in meter) */ double dblImgWidthInMapUnit = dblImgWidthInInch * 0.0254; double dblImgHeightInMapUnit = dblImgHeightInInch * 0.0254;
/* calculating half of map’s height & width at the specific scale */ double dX = (dblImgWidthInMapUnit * pCenterAndScale.Scale) / 2; double dY = (dblImgHeightInMapUnit * pCenterAndScale.Scale) / 2;
/* using the center point and width & height created before, it is computing map’s extent */ MapServerWSDL.PointN pCtrPnt = pCenterAndScale.Center as MapServerWSDL.PointN; double minX = pCtrPnt.X - dX; double maxX = pCtrPnt.X + dX; double minY = pCtrPnt.Y - dY; double maxY = pCtrPnt.Y + dY;
/* assinging values to the Envelope object passed by the caller function */ pOutEnvelope.XMin = minX; pOutEnvelope.XMax = maxX; pOutEnvelope.YMin = minY; pOutEnvelope.YMax = maxY;
/* printing out the extent */ Debug.Print("ComputeExtent Result: " + pOutEnvelope.XMin.ToString() + ", " + pOutEnvelope.YMin.ToString() + ", " + pOutEnvelope.XMax.ToString() + ", " + pOutEnvelope.YMax.ToString()); } catch (Exception exp) { MessageBox.Show(exp.Message, "Error in ComputeExtent", MessageBoxButtons.OK, MessageBoxIcon.Error); } }


创建时间:2007-09-07
最近更新: 2010-06-17


原文链接
http://support.esrichina.com.cn/2007/0907/800.html

要回复问题请先登录注册