ArcGis 9.2客户端开发简介(2)

放大

       以下例程将实现对图片的放大操作

              public void ZoomIn(PictureBox m_PictureBox)

        {

            fuzhou.MapDescription pMapDescription = m_sMapDesc;

            fuzhou.EnvelopeN pEnvelope = pMapDescription.MapArea.Extent as fuzhou.EnvelopeN;

            double eWidth = Math.Abs(pEnvelope.XMax - pEnvelope.XMin);

            double eHeight = Math.Abs(pEnvelope.YMax - pEnvelope.YMin);

            double xFactor = (eWidth - (eWidth * 0.5)) / 2;

            double yFactor = (eHeight - (eHeight * 0.5)) / 2;

            pEnvelope.XMax = pEnvelope.XMax - xFactor;

            pEnvelope.XMin = pEnvelope.XMin + xFactor;

            pEnvelope.YMax = pEnvelope.YMax - yFactor;

            pEnvelope.YMin = pEnvelope.YMin + yFactor;

            fuzhou.MapExtent pMapExtext = new fuzhou.MapExtent();

            pMapExtext.Extent = pEnvelope;

            pMapDescription.MapArea = pMapExtext;

            // save the map description and draw the map

            m_sMapDesc = pMapDescription;

            drawMap(ref pMapDescription, m_PictureBox);

        }

放大操作的基本原理是取得当前的地图描述MapDescription,然后按照比例计算出放大或缩小的比例。在得出按照比例计算出来的周边坐标,然后将其提交服务器,取得图形进行显示。

实例图形:

      

缩小

       public void ZoomOut(PictureBox m_PictureBox)

        {

            fuzhou.MapDescription pMapDescription = m_sMapDesc;

            fuzhou.EnvelopeN pEnvelope = pMapDescription.MapArea.Extent as fuzhou.EnvelopeN;

            double eWidth = Math.Abs(pEnvelope.XMax - pEnvelope.XMin);

            double eHeight = Math.Abs(pEnvelope.YMax - pEnvelope.YMin);

            double xFactor = (eWidth - (eWidth * 1.5)) / 2;

            double yFactor = (eHeight - (eHeight * 1.5)) / 2;

            pEnvelope.XMax = pEnvelope.XMax - xFactor;

            pEnvelope.XMin = pEnvelope.XMin + xFactor;

            pEnvelope.YMax = pEnvelope.YMax - yFactor;

            pEnvelope.YMin = pEnvelope.YMin + yFactor;

            fuzhou.MapExtent pMapExtext = new fuzhou.MapExtent();

            pMapExtext.Extent = pEnvelope;

            pMapDescription.MapArea = pMapExtext;

            m_sMapDesc = pMapDescription;

            drawMap(ref pMapDescription, m_PictureBox);

         }

放大操作的基本原理是取得当前的地图描述MapDescription,然后按照比例计算出放大或缩小的比例。在得出按照比例计算出来的周边坐标,然后将其提交服务器,取得图形进行显示。

漫游

       漫游的过程中需要监控鼠标在整个过程中的变化,如鼠标点击,移动等等,因此漫游的实现也需要在地图显示空间的MouseDownMouseMoveMouseUp事件中实现,在例程中使用的PictureBox空间名为picGis,代码如下所示:

     private void picGis_MouseDown(object sender, MouseEventArgs e)

        {

            if (e.Button != MouseButtons.Left)

                return;

            if (ispanning == true)

            {

                PointClass m_point=new PointClass();

                m_point.X = e.X;

                m_point.Y = e.Y;

                IPoint m_ipoint = m_MapOperate.ScreenPointToMapPoint(m_point);//将鼠标的位置坐标转换成图形坐标

                startX = m_ipoint.X;

                startY = m_ipoint.Y;

                startDragX = e.X;

                startDragY = e.Y;

            }

        }

 

        private void picGis_MouseMove(object sender, MouseEventArgs e)

        {

            if (e.Button != MouseButtons.Left)

                return;

            if (ispanning==true)

            {

                // drag the image

                picGis.Image = null;

                deltaDragX = startDragX - e.X;

                deltaDragY = startDragY - e.Y;

                picGis.Invalidate();

            }

        }

 

        private void picGis_MouseUp(object sender, MouseEventArgs e)

        {

            if (e.Button != MouseButtons.Left)

                return;

            if (ispanning==true )

            {

                this.Cursor = Cursors.WaitCursor;

                PointClass m_point = new PointClass();

                m_point.X = e.X;

                m_point.Y = e.Y;

                IPoint  m_ipoint = m_MapOperate.ScreenPointToMapPoint(m_point);//记录漫游终结点的屏幕坐标并将其转换成图形坐标

                double deltaX = m_ipoint.X - startX;

                double deltaY = m_ipoint.Y - startY;

 

                //change the extent and draw

                fuzhou.MapDescription pMapDescription =m_MapOperate.getMapDescription() ;

                fuzhou.EnvelopeN pEnvelope = pMapDescription.MapArea.Extent as fuzhou.EnvelopeN;

                pEnvelope.XMax = pEnvelope.XMax - deltaX;

                pEnvelope.XMin = pEnvelope.XMin - deltaX;

                pEnvelope.YMax = pEnvelope.YMax - deltaY;

                pEnvelope.YMin = pEnvelope.YMin - deltaY;

                fuzhou.MapExtent pMapExtext = new fuzhou.MapExtent();

                pMapExtext.Extent = pEnvelope;

                pMapDescription.MapArea = pMapExtext;

                // save the map description and draw the map

                m_MapOperate.SetMapDescription( pMapDescription);

                m_MapOperate.drawMap(ref pMapDescription, picGis);

                deltaDragX = 0;

                deltaDragY = 0;

                picGis.Invalidate();

                this.Cursor = Cursors.Default;

            }

        }

实例图:

 

全图

public void Extend(PictureBox m_PictureBox)

        {

            try

            {

               

                String  m_sDataFrame = map.GetDefaultMapName();

                fuzhou.MapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

 

                fuzhou.Envelope pEnvelope = mapi.FullExtent;

                fuzhou.MapDescription pMapDescription = m_sMapDesc;

                fuzhou.MapExtent pMapExtext = new fuzhou.MapExtent();

                pMapExtext.Extent = pEnvelope;

                pMapDescription.MapArea = pMapExtext;

 

                // save the map description and draw the map

                m_sMapDesc = pMapDescription;

                drawMap(ref pMapDescription, m_PictureBox);

            }

            catch (Exception exception)

            {

                MessageBox.Show(exception.Message, "An error has occurred");

            }

        }

放大操作的基本原理是取得mapserver服务器该地图的FullExtent,然后将其转换提交服务器,取得图形进行显示。

鹰眼操作

       由于在实际使用过程中。有很多针对地图的操作需要在鹰眼上来实现,所以在本实例中添加了鹰眼点击漫游的功能:具体实现代码如下:

       private void Eager_eye_MouseDown(object sender, MouseEventArgs e)

        {

            if (e.Button.ToString() =="Left")

            {

                PointClass m_Point=new PointClass() ;

                m_Point.X = e.X;

                m_Point.Y = e.Y;

                m_MapOperate.CenterAtByEye(e.X, e.Y,Eager_eye  ,picGis);

             }

        }

 

     public void CenterAtByEye(int X, int Y,PictureBox m_eyePictureBox, PictureBox m_PictureBox)

        {

            String m_sDataFrame = map.GetDefaultMapName();

            fuzhou.MapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

            m_sEyeMapDesc = mapi.DefaultMapDescription;

            //fuzhou.Envelope pEnvelope = mapi.FullExtent;

            fuzhou.fujian_MapServer  map1 = new fuzhou.fujian_MapServer ();

            PointClass m_tmpPoint = new PointClass();

            fuzhou.ImageDisplay idisp1;

            idisp1 = new fuzhou.ImageDisplay();

            idisp1.ImageHeight = m_eyePictureBox.Height;

            idisp1.ImageWidth = m_eyePictureBox.Width;

            idisp1.ImageDPI = 150;

            int[] Xs = { X };

            int[] Ys = { Y };

            fuzhou.MultipointN mpnt = map1.ToMapPoints(m_sEyeMapDesc, idisp1, Xs, Ys) as fuzhou.MultipointN;

            fuzhou.Point[] pnta = mpnt.PointArray;

            fuzhou.PointN pnt = pnta[0] as fuzhou.PointN;

            m_tmpPoint.X = pnt.X;

            m_tmpPoint.Y = pnt.Y;

            fuzhou.MapDescription pMapDescription = m_sMapDesc;

            fuzhou.EnvelopeN pEnvelope = pMapDescription.MapArea.Extent as fuzhou.EnvelopeN;

            double m_Width = Math.Abs(pEnvelope.XMax - pEnvelope.XMin) / 2;

            double m_Height = Math.Abs(pEnvelope.YMax - pEnvelope.YMin) / 2;

            pEnvelope.XMax = m_tmpPoint.X + m_Width;

            pEnvelope.XMin = m_tmpPoint.X - m_Width;

            pEnvelope.YMax = m_tmpPoint.Y + m_Height;

            pEnvelope.YMin = m_tmpPoint.Y - m_Height;

            fuzhou.MapExtent pMapExtext = new fuzhou.MapExtent();

            pMapExtext.Extent = pEnvelope;

            pMapDescription.MapArea = pMapExtext;

            // save the map description and draw the map

            m_sMapDesc = pMapDescription;

            drawMap(ref pMapDescription, m_PictureBox);

            return ;

        }

图层操作

       以下是针对图层设置其是否显示的代码,这些代码可以结合treeview控件来实现对地图图层的整体控制功能:

public void setLayerVisible(int LayerId,PictureBox PictureBox,Boolean m_bVisible)

        {

            String m_sDataFrame = map.GetDefaultMapName();

            fuzhou.MapDescription pMapDescription;

            fuzhou.MapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

            pMapDescription = m_sMapDesc;

            int m_layerCount = mapi.MapLayerInfos.GetLength(0);

            for (int i = 0; i < m_layerCount; i++)

            {

                if (pMapDescription.LayerDescriptions[i].LayerID == LayerId)

                {

                    pMapDescription.LayerDescriptions[i].Visible = m_bVisible;

                    i = m_layerCount;

                }

            }

            m_sMapDesc = pMapDescription;

            drawMap(ref pMapDescription, PictureBox);

        }

        public void setLayerVisible(String LayerName,PictureBox PictureBox,Boolean m_bVisible)

        {

            String m_sDataFrame = map.GetDefaultMapName();

            fuzhou.MapDescription pMapDescription;

            fuzhou.MapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

            pMapDescription = m_sMapDesc;

            int m_layerCount = mapi.MapLayerInfos.GetLength(0);

 

            for (int i = 0; i < m_layerCount; i++)

            {

                if (mapi.MapLayerInfos[i].Name  == LayerName)

                {

                    pMapDescription.LayerDescriptions[i].Visible = m_bVisible;

                    i = m_layerCount;

                }

            }

            m_sMapDesc = pMapDescription;

            drawMap(ref pMapDescription, PictureBox);

        }

查询

       统计查询结果的数量:

      public int QueryFeatureCount(int LayerID,String FieldName,String SearchStr)

        {

            try{

                fuzhou.QueryFilter m_queryFilter=new fuzhou.QueryFilter();

                m_queryFilter.WhereClause = FieldName + " like '%" + SearchStr + "%'";

                int i = map.QueryFeatureCount(map.GetDefaultMapName(), LayerID, m_queryFilter);

                return i;

             }

            catch (Exception exception)

            {

                MessageBox.Show(exception.Message, "An error has occurred");

            }

            return 0;

        }

        public int QueryFeatureCount(String LayerName, String FieldName, String SearchStr)

        {

            try

            {

                String m_sDataFrame = map.GetDefaultMapName();

                fuzhou.MapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

                for (int i = 0; i < mapi.MapLayerInfos.GetLength(0); i++)

                {

                    if (mapi.MapLayerInfos[i].Name == LayerName)

                    {

                        int LayerID = mapi.MapLayerInfos[i].LayerID;

                        fuzhou.QueryFilter m_queryFilter = new fuzhou.QueryFilter();

                        m_queryFilter.WhereClause = FieldName + " like '%" + SearchStr + "%'";

                        int j = map.QueryFeatureCount(map.GetDefaultMapName(), LayerID, m_queryFilter);

                        return j;

                    }

                }

            }

            catch (Exception exception)

            {

                MessageBox.Show(exception.Message, "An error has occurred");

            }

            return 0;

        }

     查询结果:

public fuzhou.RecordSet QueryFeatureData(int LayerID, String FieldName, String SearchStr)

        {

            try

            {

                fuzhou.QueryFilter m_queryFilter = new fuzhou.QueryFilter();

                m_queryFilter.WhereClause = FieldName + " like '%" + SearchStr + "%'";

                fuzhou.RecordSet m_recordset = map.QueryFeatureData(map.GetDefaultMapName(), LayerID, m_queryFilter);

                return m_recordset;

            }

            catch (Exception exception)

            {

                MessageBox.Show(exception.Message, "An error has occurred");

            }

            return null;

        }

        public fuzhou.RecordSet QueryFeatureData(String LayerName, String FieldName, String SearchStr)

        {

            try

            {

                String m_sDataFrame = map.GetDefaultMapName();

                fuzhou.MapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

                for (int i = 0; i < mapi.MapLayerInfos.GetLength(0); i++)

                {

                    if (mapi.MapLayerInfos[i].Name == LayerName)

                    {

                        int LayerID = mapi.MapLayerInfos[i].LayerID;

                        fuzhou.QueryFilter m_queryFilter = new fuzhou.QueryFilter();

                        m_queryFilter.WhereClause = FieldName + " like '%" + SearchStr + "%'";

                        fuzhou.RecordSet m_recordset = map.QueryFeatureData(map.GetDefaultMapName(), LayerID, m_queryFilter);

                        return m_recordset;

                         

                    }

                }

            }

            catch (Exception exception)

            {

                MessageBox.Show(exception.Message, "An error has occurred");

            }

            return null;

        }

        public fuzhou.RecordSet QueryFeatureData(String LayerName, String FieldName, String SearchStr,String SqlWhere)

        {

            try

            {

                String m_sDataFrame = map.GetDefaultMapName();

                fuzhou.MapServerInfo mapi = map.GetServerInfo(m_sDataFrame);

                for (int i = 0; i < mapi.MapLayerInfos.GetLength(0); i++)

                {

                    if (mapi.MapLayerInfos[i].Name == LayerName)

                    {

                        int LayerID = mapi.MapLayerInfos[i].LayerID;

                        fuzhou.QueryFilter m_queryFilter = new fuzhou.QueryFilter();

                        m_queryFilter.WhereClause = FieldName + " like '%" + SearchStr + "%' " + SqlWhere;

                        fuzhou.RecordSet m_recordset = map.QueryFeatureData(map.GetDefaultMapName(), LayerID, m_queryFilter);

                        return m_recordset;

 

                    }

                }

            }

            catch (Exception exception)

            {

                MessageBox.Show(exception.Message, "An error has occurred");

            }

            return null;

        }

查询定位

查询定位主要分两种情况,一个是查询的结果是点、一个是多边形,因此在程序中需要针对不同的结果进行定位显示

public void LocationBySql(String LayerName, String FieldName, String SearchStr, PictureBox m_PictureBox)

        {

            fuzhou.RecordSet m_recordset = new FzSecurityGisServer.fuzhou.RecordSet();

            m_recordset = QueryFeatureData(LayerName, FieldName, SearchStr);

            for (int i = 0; i < m_recordset.Records.GetLength(0); i++)

            {

                fuzhou.Geometry m_geometry=new FzSecurityGisServer.fuzhou.Geometry() ;

                fuzhou.GeometryDef m_GeometryDef = new fuzhou.GeometryDef();

                fuzhou.Field m_Field = new FzSecurityGisServer.fuzhou.Field();

                for (int j = 0; j < m_recordset.Fields.FieldArray.GetLength(0); j++)

                {

                    m_Field = m_recordset.Fields.FieldArray[j];

                    if (m_Field.Type == fuzhou.esriFieldType.esriFieldTypeGeometry)

                    {

                        m_GeometryDef = m_Field.GeometryDef;

                        if (m_GeometryDef.GeometryType == fuzhou.esriGeometryType.esriGeometryPolygon)

                        {

                            fuzhou.PolygonN pgnn = m_recordset.Records[i].Values[j] as fuzhou.PolygonN;

                            fuzhou.EnvelopeN pEnvelope = pgnn.Extent as fuzhou.EnvelopeN;

                            fuzhou.MapDescription pMapDescription = m_sMapDesc;

                            double eWidth = Math.Abs(pEnvelope.XMax - pEnvelope.XMin);

                            double eHeight = Math.Abs(pEnvelope.YMax - pEnvelope.YMin);

                            double xFactor = (eWidth - (eWidth * 1.5)) / 2;

                            double yFactor = (eHeight - (eHeight * 1.5)) / 2;

                            pEnvelope.XMax = pEnvelope.XMax - xFactor;

                            pEnvelope.XMin = pEnvelope.XMin + xFactor;

                            pEnvelope.YMax = pEnvelope.YMax - yFactor;

                            pEnvelope.YMin = pEnvelope.YMin + yFactor;

                            fuzhou.MapExtent pMapExtext = new fuzhou.MapExtent();

                            pMapExtext.Extent = pEnvelope;

                            pMapDescription.MapArea = pMapExtext;

                            m_sMapDesc = pMapDescription;

                            drawMap(ref pMapDescription, m_PictureBox);

 

                        }

                        if (m_GeometryDef.GeometryType == fuzhou.esriGeometryType.esriGeometryPoint)

                        {

                            fuzhou.PointN m_point = m_recordset.Records[i].Values[j] as fuzhou.PointN;

                            fuzhou.EnvelopeN pEnvelope = new fuzhou.EnvelopeN() ;

                            pEnvelope.XMax = m_point.X;

                            pEnvelope.XMin = m_point.X;

                            pEnvelope.YMax = m_point.Y;

                            pEnvelope.YMin = m_point.Y;

                            fuzhou.MapDescription pMapDescription = m_sMapDesc;

                            double eWidth = 1000;

                            double eHeight = 1000;

                            double xFactor = (eWidth - (eWidth * 1.5)) / 2;

                            double yFactor = (eHeight - (eHeight * 1.5)) / 2;

                            pEnvelope.XMax = pEnvelope.XMax - xFactor;

                            pEnvelope.XMin = pEnvelope.XMin + xFactor;

                            pEnvelope.YMax = pEnvelope.YMax - yFactor;

                            pEnvelope.YMin = pEnvelope.YMin + yFactor;

                            fuzhou.MapExtent pMapExtext = new fuzhou.MapExtent();

                            pMapExtext.Extent = pEnvelope;

                            pMapDescription.MapArea = pMapExtext;

                            // save the map description and draw the map

                            m_sMapDesc = pMapDescription;

                            drawMap(ref pMapDescription, m_PictureBox);

                        }

                    }

                   

                }

            }

        }

 

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1920290 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值