heminzhou

程序员民工的笔记本

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
    制作点选(Identify)、框选(Select)等操作时,必要的一步是将客户端的屏幕坐标转换到地图坐标。在ArcGIS Server .NET ADF SP3以前,使用如下语句进行转换:

Rectangle rect = (args as RectangleEventArgs).ScreenExtent;
ESRI.ArcGIS.ADF.Web.Geometry.Point minAdfPoint 
= ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Left, rect.Bottom, mapCtrl.Extent, mapFunc.DisplaySettings.ImageDescriptor.Width, mapFunc.DisplaySettings.ImageDescriptor.Height);
ESRI.ArcGIS.ADF.Web.Geometry.Point maxAdfPoint 
= ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Right, rect.Top, mapCtrl.Extent, mapFunc.DisplaySettings.ImageDescriptor.Width, mapFunc.DisplaySettings.ImageDescriptor.Height);
ESRI.ArcGIS.ADF.Web.Geometry.Envelope adfEnvelope 
= new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minAdfPoint, maxAdfPoint);

    而在
SP3以后,上述语句在编译时会收到一条警告:“ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(int, int, ESRI.ArcGIS.ADF.Web.Geometry.Envelope, int, int)”已过时。运行程序,似乎没觉得有什么偏差嘛。给Map Service做个缓存,再运行,出现了明显的偏差。看下面两张图:
                                      
                                                      图-1
                                      
                                                      图-2
    进一步测试,只要MapResourceManager中引用的任何一个Map Service做了缓存,就会出现偏差,而没有缓存的情况下居然正常。这也恰恰是忽悠人的地方。最可气的是ESRI的帮助文档之简陋令人发指,ArcGIS Server .NET ADFAPI文档看上去一片光秃秃的,告诉你方法已过时,却不提示你用什么方法替代。看来真的像我经理说的,GIS软件巨头在美国不过是个三流小软件公司。
    好在经过孜孜不倦的google终于找到了正确的方法,请使用如下语句:

Rectangle rect = (args as RectangleEventArgs).ScreenExtent;
ESRI.ArcGIS.ADF.Web.Geometry.Point minAdfPoint 
= ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Left, rect.Bottom, mapCtrl.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
ESRI.ArcGIS.ADF.Web.Geometry.Point maxAdfPoint 
= ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Right, rect.Top, mapCtrl.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
ESRI.ArcGIS.ADF.Web.Geometry.Envelope adfEnvelope 
= new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minAdfPoint, maxAdfPoint);

    注意其中的GetTransformationParams和TransformationDirection。我的开发环境是Visual Studio 2005 + ArcGIS Server .NET ADF SP4 + ArcGIS Desktop 9.2 SP4 + ArcSDE 9.1。
    
posted on 2008-01-21 15:59  heminzhou  阅读(1574)  评论(6编辑  收藏  举报