程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> ArcGis 9.2客戶端開發簡介(2)

ArcGis 9.2客戶端開發簡介(2)

編輯:.NET實例教程

 編程實現

放大

       以下例程將實現對圖片的放大操作

              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,然後按照比例計算出放大或縮小的比例。在得出按照比例計算出來的周邊坐標,然後將其提交服務器,取得圖形進行顯示。

漫游

       漫游的過程中需要監控鼠標在整個過程中的變化,如鼠標點擊,移動等等,因此漫游的實現也需要在地圖顯示空間的MouseDown、MouseMove、MouseUp事件中實現,在例程中使用的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);

&n
bsp;               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 QueryF


eatureCount(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.Quer


yFilter 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;

           &nb
sp;                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);

                        }

                    }

                   

                }

            }

        }



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved