Beispiel #1
0
        public ESRI.ArcGIS.Geometry.IEnvelope DrawRectangle(ESRI.ArcGIS.Carto.IActiveView activeView)
        {
            if (activeView == null)
            {
                return(null);
            }
            else
            {
                ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

                // Constant
                screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
                //ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
                //rgbColor.Red = 255;

                //ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
                ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
                //simpleFillSymbol.Color = color;
                simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;

                ESRI.ArcGIS.Display.ISymbol     symbol     = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
                ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberEnvelopeClass();
                ESRI.ArcGIS.Geometry.IGeometry  geometry   = rubberBand.TrackNew(screenDisplay, symbol);
                screenDisplay.SetSymbol(symbol);
                ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = geometry as ESRI.ArcGIS.Geometry.IEnvelope;
                screenDisplay.DrawRectangle(pEnvelope); // Dynamic Cast
                screenDisplay.FinishDrawing();

                return(pEnvelope);
            }
        }
        // ArcGIS Snippet Title:
        // Create JPEG from ActiveView
        //
        // Long Description:
        // Creates a .jpg (JPEG) file from IActiveView. Default values of 96 DPI are used for the image creation.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Carto
        // ESRI.ArcGIS.Display
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.Output
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //

        ///<summary>Creates a .jpg (JPEG) file from IActiveView. Default values of 96 DPI are used for the image creation.</summary>
        ///
        ///<param name="activeView">An IActiveView interface</param>
        ///<param name="pathFileName">A System.String that the path and filename of the JPEG you want to create. Example: "C:\temp\test.jpg"</param>
        ///
        ///<returns>A System.Boolean indicating the success</returns>
        ///
        ///<remarks></remarks>
        public System.Boolean CreateJPEGFromActiveView(ESRI.ArcGIS.Carto.IActiveView activeView, System.String pathFileName)
        {
            //parameter check
            if (activeView == null || !(pathFileName.EndsWith(".jpg")))
            {
                return(false);
            }
            IExport export = (IExport) new ExportJPEG();

            export.ExportFileName = pathFileName;

            // Microsoft Windows default DPI resolution
            export.Resolution = 96;
            tagRECT exportRECT = activeView.ExportFrame;

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;
            System.Int32 hDC = export.StartExporting();
            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

            // Finish writing the export file and cleanup any intermediate files
            export.FinishExporting();
            export.Cleanup();

            return(true);
        }
Beispiel #3
0
        //根据层名,得到层的索引
        public System.Int32 GetIndexNumberFromLayerName(ESRI.ArcGIS.Carto.IActiveView activeView, System.String layerName)
        {
            if (activeView == null || layerName == null)
            {
                return(-1);
            }
            ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;

            // Get the number of layers
            int numberOfLayers = map.LayerCount;

            // Loop through the layers and get the correct layer index
            for (System.Int32 i = 0; i < numberOfLayers; i++)
            {
                if (layerName == map.get_Layer(i).Name)
                {
                    // Layer was found
                    return(i);
                }
                //map.get_Layer(i).Visible = false;
            }

            // No layer was found
            return(-1);
        }
Beispiel #4
0
        private void AddItemsOnStartup(ESRI.ArcGIS.Carto.IActiveView activeView)
        {
            ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;

            var numberOfLayers = map.LayerCount;

            for (var i = 0; i < numberOfLayers; i++)
            {
                ArcMapItemAdded(map.Layer[i]);
            }
        }
Beispiel #5
0
        public override void OnClick()
        {
            DrawTypeConstant nDrawType = DrawTypeConstant.CommonPolygon;

            this.m_blCanEdit = true;

            this.m_pMap = this.m_pHookHelper.FocusMap;
            if (this.m_pMap == null)
            {
                return;
            }

            this.m_pMap.ClearSelection();
            this.m_pActiveView = this.m_pMap as IActiveView;

            m_pActiveView.ScreenDisplay.Invalidate(m_pActiveView.Extent.Envelope, true, -1);
            m_pActiveView.ScreenDisplay.UpdateWindow();
            try
            {
                m_pActiveViewEvent            = (IActiveViewEvents_Event)m_pMap;
                m_pActiveViewEvent.AfterDraw += new IActiveViewEvents_AfterDrawEventHandler(m_pActiveViewEvent_AfterDraw);
            }
            catch (Exception ex)
            {
            }
            if (this.m_clsEditorMain == null)
            {
                return;
            }

            //this.m_blCanEdit = m_pOperateWorkSpace.InitOperater(nDrawType, ref m_pMap, m_clsEditorMain);
            if (this.m_blCanEdit == false)
            {
                return;
            }

            this.m_blCanEdit = m_pDrawLineTrack.InitTrack(nDrawType, ref m_pMap, m_clsEditorMain);

            if (this.m_blCanEdit == false)
            {
                System.Windows.Forms.MessageBox.Show("反馈环境初始化失败!", "系统提示", MessageBoxButtons.OK);
                return;
            }
            isInSubCommand = false;
            SetNextStep("0");
        }
Beispiel #6
0
        public void ClearSelectedMapFeatures(ESRI.ArcGIS.Carto.IActiveView activeView, ESRI.ArcGIS.Carto.IFeatureLayer featureLayer) //dhncho 01.10
        {
            if (activeView == null || featureLayer == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = featureLayer as ESRI.ArcGIS.Carto.IFeatureSelection; // Dynamic Cast

            // Invalidate only the selection cache. Flag the original selection
            activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);

            // Clear the selection
            featureSelection.Clear();

            // Flag the new selection
            activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            ILayer layer = m_engineEditor.TargetLayer;

            if (layer == null)
            {
                return;
            }
            m_activeView = m_hookHelper.ActiveView;
            m_map        = m_hookHelper.FocusMap;
            IEnumFeature selectedFeatures = GetSelectedFeatures();

            if (selectedFeatures == null)
            {
                return;
            }
            UnionFeatures(selectedFeatures); m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent);

            // TODO: Add UnionFeaturesCmd.OnClick implementation
        }
        private void OnActiveViewEventsViewRefreshed(ESRI.ArcGIS.Carto.IActiveView view, ESRI.ArcGIS.Carto.esriViewDrawPhase phase, System.Object data, ESRI.ArcGIS.Geometry.IEnvelope envelope)
        {
            IPoint point           = new Point();
            IPoint lowerLeftPoint  = new Point();
            IPoint upperRightPoint = new Point();


            double latXmin, latXmax, longYmin, longYmax, diagonal;

            lowerLeftPoint.X = view.Extent.XMin;
            lowerLeftPoint.Y = view.Extent.YMin;

            upperRightPoint.X = view.Extent.XMax;
            upperRightPoint.Y = view.Extent.YMax;

            PointToLatLong(lowerLeftPoint, out latXmin, out longYmin);
            PointToLatLong(upperRightPoint, out latXmax, out longYmax);

            diagonal = Distance(latXmin, longYmin, latXmax, longYmax, 'K') * 1000; // "1KM * 1000
            diagonal = Math.Round(diagonal, 2);

            _altitude = Convert.ToString(0.5 * Math.Sqrt(3) * diagonal, CultureInfo.InvariantCulture);

            point.X = (view.Extent.XMax + view.Extent.XMin) / 2;
            point.Y = (view.Extent.YMax + view.Extent.YMin) / 2;

            Double lat;
            Double lon;

            PointToLatLong(point, out lat, out lon);

            lat = Math.Round(lat, 5);
            lon = Math.Round(lon, 5);

            _latitude  = Convert.ToString(lat, CultureInfo.InvariantCulture);
            _longitude = Convert.ToString(lon, CultureInfo.InvariantCulture);

            CreateTrackingKML();
        }
        // ArcGIS Snippet Title:
        // Create JPEG (hi-resolution) from ActiveView
        //
        // Long Description:
        // Creates a .jpg (JPEG) file from IActiveView using a high resolution exporting option. Default values of 96 DPI are overwritten to 300 used for the image creation.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Carto
        // ESRI.ArcGIS.Display
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.Output
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //

        ///<summary>Creates a .jpg (JPEG) file from the ActiveView using a high resolution exporting option. Default values of 96 DPI are overwritten to 300 used for the image creation.</summary>
        ///
        ///<param name="activeView">An IActiveView interface</param>
        ///<param name="pathFileName">A System.String that the path and filename of the JPEG you want to create. Example: "C:\temp\hiResolutionTest.jpg"</param>
        ///
        ///<returns>A System.Boolean indicating the success</returns>
        ///
        ///<remarks></remarks>
        public System.Boolean CreateJPEGHiResolutionFromActiveView(ESRI.ArcGIS.Carto.IActiveView activeView, System.String pathFileName)
        {
            //parameter check
            if (activeView == null || !(pathFileName.EndsWith(".jpg")))
            {
                return(false);
            }
            ESRI.ArcGIS.Output.IExport export = (IExport) new ESRI.ArcGIS.Output.ExportJPEG();
            export.ExportFileName = pathFileName;

            // Because we are exporting to a resolution that differs from screen
            // resolution, we should assign the two values to variables for use
            // in our sizing calculations
            System.Int32 screenResolution = 96;
            System.Int32 outputResolution = 300;

            export.Resolution = outputResolution;

            tagRECT exportRECT; // This is a structure

            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = activeView.ExportFrame.right * (outputResolution / screenResolution);
            exportRECT.bottom = activeView.ExportFrame.bottom * (outputResolution / screenResolution);

            // Set up the PixelBounds envelope to match the exportRECT
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;

            System.Int32 hDC = export.StartExporting();

            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
            export.FinishExporting();
            export.Cleanup();

            return(true);
        }
Beispiel #10
0
        public void DrawPoint(ESRI.ArcGIS.Carto.IActiveView activeView, System.Int32 x, System.Int32 y)
        {
            if (activeView == null)
            {
                return;
            }
            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;


            // Constant
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
            ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();

            ESRI.ArcGIS.Display.ISymbol symbol = simpleMarkerSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
            screenDisplay.SetSymbol(symbol);
            ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;

            // x and y are in device coordinates
            ESRI.ArcGIS.Geometry.IPoint point = displayTransformation.ToMapPoint(x, y);


            screenDisplay.DrawPoint(point);
            screenDisplay.FinishDrawing();
        }
 private void OnActiveViewEventsViewRefreshed(ESRI.ArcGIS.Carto.IActiveView view, ESRI.ArcGIS.Carto.esriViewDrawPhase phase, System.Object data, ESRI.ArcGIS.Geometry.IEnvelope envelope)
 {
     if (!_iscloned)
     {
         return;
     }
     if (!_isthisadmin)
     {
         return;
     }
     try
     {
         //first check if the map extent has changed
         if (ExtentHasChanged())
         {
             //this flag is to avoid an infinite loop; any change to the map will cause this 'view refresh'
             //event to be fired again
             if (_firstRefresh)
             {
                 _firstRefresh = false;
                 using (StreamWriter sw = new StreamWriter(_extentfile))
                 {
                     sw.WriteLine(_currentExtent.XMin.ToString());
                     sw.WriteLine(_currentExtent.XMax.ToString());
                     sw.WriteLine(_currentExtent.YMin.ToString());
                     sw.WriteLine(_currentExtent.YMax.ToString());
                     sw.WriteLine(Math.Round(_map.MapScale).ToString());
                 }
             }
         }
     }
     catch (Exception ex)
     {
         string message = ex.Message;
     }
 }
        //开始提取
        private void Deal()
        {
            IWorkspace    pWorkspace      = default(IWorkspace);
            string        sDesFeatClsName = null;
            IFeatureClass pDesFeatCls     = default(IFeatureClass);
            string        sInfo           = null;
            IFeatureLayer pFeatLayer      = default(IFeatureLayer);
            IFeatureClass pFeatureCls     = default(IFeatureClass);
            IGeometry     pDomainGeometry = default(IGeometry);
            int           ErrorCount      = 0;
            int           lFeatCount      = 0;
            bool          bIsCut          = false;

            if (this.ChkClip.Checked)
            {
                bIsCut = true;
                ////是否剪切
            }
            else
            {
                bIsCut = false;
            }
            int intChooseLayer = 0;

            ////印骅 20081121  获得多边形范围
            int iRegion = 0;

            if (_featureLayerRegion != null)
            {
                IFeatureCursor featureCursor = _featureLayerRegion.FeatureClass.Search(null, true);
                IFeature       feature       = featureCursor.NextFeature();
                while (feature != null)
                {
                    iRegion++;
                    if (Convert.ToBoolean(((DataGridViewCheckBoxCell)dgvRegionChoose.Rows[iRegion - 1].Cells["colChoose"]).Value))
                    {
                        intChooseLayer++;
                        IPolygon polygon = feature.Shape as IPolygon;
                        pDomainGeometry = polygon;

                        if (_map.LayerCount == 0)
                        {
                            MessageBoxEx.Show("没有加载图层或没有图层处于选中状态!请选中需要提取的图层!", "提示");
                            return;
                        }

                        int      iCount       = 0;
                        IDataset pTempDataset = default(IDataset);
                        //ploger = new WHFUtilities.clsLog();
                        //ploger.DBConnectionString = "Data Source=" + g_Sys.DbName + ";User ID=" + g_Sys.DbUser + " ;Password="******"当前操作层:" + pFeatLayer.Name;
                                this.lblInfo.Text = sInfo;
                                Application.DoEvents();
                                if (!string.IsNullOrEmpty(sDesFeatClsName.Trim()))
                                {
                                    if (pFeatureCls != null)
                                    {
                                        this.lblInfo.Text = sInfo + "正在获得目标要素类,请稍候....";
                                        lblInfo.Refresh();
                                        Application.DoEvents();
                                        if (sDesFeatClsName.Contains("."))
                                        {
                                            int dotIndex = 0;
                                            dotIndex        = sDesFeatClsName.IndexOf(".");
                                            sDesFeatClsName = sDesFeatClsName.Substring(dotIndex + 1, sDesFeatClsName.Length - dotIndex - 1);
                                        }

                                        //判断是否需要创建要素类 yh 15/4/09
                                        ClsCreateFeat.CheckFeatCls(bIsCut, pFeatLayer, ref lFeatCount, pDomainGeometry);
                                        if (lFeatCount != 0)
                                        {
                                            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                                            IFields           pFields           = pFeatureCls.Fields;
                                            pDesFeatCls = ClsCreatAndGetDataset.CreatOrOpenFeatClsByName(ref pFeatureWorkspace, sDesFeatClsName, ref pFields, null, null);
                                            pWorkspace  = (IWorkspace)pFeatureWorkspace;
                                            //pFeatureCls.Fields = pFields;
                                        }
                                        if (pDesFeatCls != null)
                                        {
                                            //如果不剪切的,则使用该方法,需要剪切,则使用选择集,分位于内部要素和位于外部要素或直接使用pfeatcls搜索二遍
                                            //如果数据量大的话,搜索二遍的方法是不可行的
                                            ISpatialReference           pSpatialReference = null;
                                            Dictionary <string, string> pDicField         = null;

                                            iCount = (int)ClsCreateFeat.OutPutFeat(ref pDesFeatCls, ref pFeatureCls, strRegionLayer[i], pDomainGeometry, bIsCut, ref pSpatialReference, pDicField, ref this.lblInfo, sInfo);
                                            IFeatureLayer showFeatureLayer = new FeatureLayer();
                                            showFeatureLayer.FeatureClass = pDesFeatCls;
                                            ILayer showLayer = showFeatureLayer as ILayer;
                                            showLayer.Name = pDesFeatCls.AliasName;
                                            _map.AddLayer(showLayer);
                                            // 陈昉  2009-3-1  修改 修改原因 写日志
                                            if (iCount > 0)
                                            {
                                                pTempDataset = (IDataset)pFeatureCls;
                                                //ploger.log(System.Environment.MachineName, g_Sys.User.UserID, System.DateTime.Now.ToString(),
                                                //        "数据管理子系统", "WHFDataExtract", "快速提取" + pTempDataset.Name + "中" + iCount +
                                                //        "个要素到" + pDesFeatCls.AliasName, "目标:" + System.IO.Path.GetFileName(pWorkspace.PathName));
                                            }
                                        }
                                        else
                                        {
                                            ErrorCount = ErrorCount + 1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    feature = featureCursor.NextFeature();
                }
                this.Refresh();
                Application.DoEvents();
                if (ErrorCount > 0)
                {
                    this.lblInfo.Text = "操作中有错误发生!";
                    //g_clsErrorHandle.DisplayInformation("操作中有错误发生!", false);
                    MessageBoxEx.Show("操作中有错误发生!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                if (intChooseLayer == 0)
                {
                    MessageBoxEx.Show("没有选择提取要素,请选择!", "提示");
                    return;
                }
                //Member member = new Member();
                //member.AddLayerToMap(pWorkspace, _map);
                ESRI.ArcGIS.Carto.IActiveView activeView = _map as ESRI.ArcGIS.Carto.IActiveView;
                activeView.Refresh();
                this.lblInfo.Text = "操作完成!";
                MessageBoxEx.Show("操作完成!", "提示");
            }
        }
Beispiel #13
0
        protected override void OnClick()
        {
            // Get the min/max zoom from user input
            int minzoom = 0;
            int maxzoom = 6;

            Ecotrust.Form1 form1 = new Ecotrust.Form1();
            if (form1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                minzoom = (int)form1.numericUpDown1.Value;
                maxzoom = (int)form1.numericUpDown2.Value;
            }
            else
            {
                return; //TODO
            }

            // Use the FolderBrowserDialog Class to choose export folder
            System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
            folderDialog.Description = "Select output folder for map tiles...";
            string exportDir = "";

            if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp"
                exportDir = folderDialog.SelectedPath;
                if (exportDir == "")
                {
                    return;  // TODO raise error
                }
            }
            else
            {
                return; //TODO
            }

            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
            ESRI.ArcGIS.Carto.IActiveView    activeView = mxDocument.ActiveView;
            ESRI.ArcGIS.Carto.IMap           map        = activeView.FocusMap;

            ESRI.ArcGIS.Geometry.IEnvelope mapaoi = activeView.Extent;

            // Set up export object and tile pixel coordinates
            int tileSizeX = 256;
            int tileSizeY = 256;

            // set up exporter with transparent background
            ESRI.ArcGIS.Output.IExportPNG pngexport = new ESRI.ArcGIS.Output.ExportPNGClass();
            ESRI.ArcGIS.Display.IColor    tcolor    = new ESRI.ArcGIS.Display.RgbColorClass();
            // Warning: 254,254,254 will be set to transparent; don't use in any of map styling
            ((IRgbColor)tcolor).Red   = 254;
            ((IRgbColor)tcolor).Green = 254;
            ((IRgbColor)tcolor).Blue  = 254;
            ((ExportPNG)pngexport).BackgroundColor = tcolor;
            pngexport.TransparentColor             = tcolor;
            ESRI.ArcGIS.Output.IExport export = (ESRI.ArcGIS.Output.IExport)pngexport;

            ESRI.ArcGIS.esriSystem.tagRECT exportRECT;
            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = tileSizeX;
            exportRECT.bottom = tileSizeY;
            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;

            map.DelayDrawing(true);

            // Turn off all layers
            for (int i = 0; i < map.LayerCount; i++)
            {
                map.get_Layer(i).Visible = false;
            }

            // Calculate total number of tiles needed
            GlobalMercator mercator = new GlobalMercator();

            GlobalMercator.Coords tempmins;
            GlobalMercator.Coords tempmaxs;
            Double numTiles = 0;

            for (int tz = minzoom; tz <= maxzoom; tz++)
            {
                tempmins  = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                tempmaxs  = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);
                numTiles += ((tempmaxs.y - tempmins.y) + 1) * ((tempmaxs.x - tempmins.x) + 1);
            }
            numTiles *= map.LayerCount;

            ESRI.ArcGIS.esriSystem.IStatusBar statusBar = ArcMap.Application.StatusBar;
            statusBar.set_Message(0, "Rendering " + numTiles.ToString() + " tiles");

            // Create a CancelTracker
            ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();

            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();

            // Set the properties of the Step Progressor
            System.Int32 int32_hWnd = ArcMap.Application.hWnd;
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
            stepProgressor.MinRange  = 0;
            stepProgressor.MaxRange  = (int)numTiles;
            stepProgressor.StepValue = 1;
            stepProgressor.Message   = "Calculating " + numTiles.ToString() + " tiles";

            // Create the ProgressDialog. This automatically displays the dialog
            ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast

            // Set the properties of the ProgressDialog
            progressDialog2.CancelEnabled = true;
            progressDialog2.Description   = "Rendering " + numTiles.ToString() + " map tiles";
            progressDialog2.Title         = "Creating map tiles...";
            progressDialog2.Animation     = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile;
            System.Boolean boolean_Continue = true;

            int tileCount = 0;

            for (int lyrnum = 0; lyrnum < map.LayerCount; lyrnum++)
            {
                // Turn on the layer of interest
                ESRI.ArcGIS.Carto.ILayer layer = map.get_Layer(lyrnum);
                layer.Visible = true;

                // Set extents
                //ESRI.ArcGIS.Geometry.IEnvelope layeraoi = layer.AreaOfInterest;
                ESRI.ArcGIS.Geometry.IEnvelope aoi = new ESRI.ArcGIS.Geometry.EnvelopeClass();

                // Create layer directory if it doesn't exist
                DirectoryInfo dir = new DirectoryInfo(exportDir + "\\" + layer.Name);
                if (!dir.Exists)
                {
                    dir.Create();
                }

                DateTime startTime = DateTime.Now;

                // Loop through zoom levels, rows, cols
                for (int tz = minzoom; tz <= maxzoom; tz++)
                {
                    GlobalMercator.Coords mins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz);
                    GlobalMercator.Coords maxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz);

                    // Create zoom directory if it doesn't exist
                    DirectoryInfo dir2 = new DirectoryInfo(dir.FullName + "\\" + tz);
                    if (!dir2.Exists)
                    {
                        dir2.Create();
                    }

                    for (int tx = (int)mins.x; tx <= (int)maxs.x; tx++)
                    {
                        // Create X directory if it doesn't exist
                        DirectoryInfo dir3 = new DirectoryInfo(dir2.FullName + "\\" + tx);
                        if (!dir3.Exists)
                        {
                            dir3.Create();
                        }

                        for (int ty = (int)mins.y; ty <= (int)maxs.y; ty++)
                        {
                            // Flip y-axis for output tile name
                            int invertTy = (int)((Math.Pow(2, tz) - 1) - ty);

                            tileCount += 1;

                            // TODO Calculate time and set new message
                            // TimeSpan timeElapsed = TimeSpan.FromTicks(DateTime.Now.Subtract(startTime).Ticks); // * ((double)tileCount - (numTiles + 1)) / (numTiles + 1));
                            // double timeRemaining = (timeElapsed.TotalSeconds / (tileCount / numTiles)) - timeElapsed.TotalSeconds;
                            //(" + ((int)timeRemaining).ToString() +" remaining)";

                            stepProgressor.Message = layer.Name + "\\" + tz + "\\" + tx + "\\" + invertTy +
                                                     ".png (" + tileCount + " of " + numTiles + ")";


                            export.ExportFileName = dir3.FullName + "\\" + invertTy + ".png";

                            GlobalMercator.Bounds bnd = mercator.TileBounds(tx, ty, tz);
                            aoi.PutCoords(bnd.minx, bnd.miny, bnd.maxx, bnd.maxy);
                            aoi.SpatialReference = map.SpatialReference; // TODO aoi spatial reference == mercator?
                            // Use FullExtent instead of Extent to make the extent independent of the activeView ratio
                            activeView.FullExtent = aoi;

                            // Export
                            System.Int32 hDC = export.StartExporting();
                            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
                            export.FinishExporting();
                            export.Cleanup();

                            stepProgressor.Position = tileCount;

                            //Check if the cancel button was pressed. If so, break out of row
                            boolean_Continue = trackCancel.Continue();
                            if (!boolean_Continue)
                            {
                                break;
                            }
                        }
                        //Check if the cancel button was pressed. If so, break out of col
                        boolean_Continue = trackCancel.Continue();
                        if (!boolean_Continue)
                        {
                            break;
                        }
                    }
                    //Check if the cancel button was pressed. If so, break out of layers
                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                    {
                        break;
                    }

                    // Write log
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(exportDir + "\\log.txt", true))
                    {
                        file.WriteLine(layer.Name + ", zoom " + tz + ", numtiles " + tileCount + ":" +
                                       mins.x + " " + mins.y + " " + maxs.x + " " + maxs.y);
                    }
                }
                // Turn it off
                layer.Visible = false;
            }

            map.DelayDrawing(false);

            // Turn ON all layers
            for (int i = 0; i < map.LayerCount; i++)
            {
                map.get_Layer(i).Visible = true;
            }

            // restore extent
            activeView.FullExtent = mapaoi;
            activeView.Refresh();

            // Done
            trackCancel    = null;
            stepProgressor = null;
            progressDialog2.HideDialog();
            progressDialog2 = null;
        }
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            //基本功能
            if (e.button == 1)
            {
                this.axMapControl1.Extent = this.axMapControl1.TrackRectangle();
            }
            else if (e.button == 2)
            {
                this.axMapControl1.Extent = this.axMapControl1.FullExtent;
            }
            else if (e.button == 4)
            {
                this.axMapControl1.Pan();
            }

            switch (mTool)
            {
            case "Position":
                //获取当前视图
                ESRI.ArcGIS.Carto.IActiveView pActiveView = this.axMapControl1.ActiveView;
                axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
                //获取鼠标点
                ESRI.ArcGIS.Geometry.IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
                IMap      pMap      = axMapControl1.Map;
                IGeometry pGeometry = null;
                //选择方法
                switch (this.mQueryModel)
                {
                case 0:         //矩形查询
                    pGeometry = this.axMapControl1.TrackRectangle();
                    break;

                case 1:         //线查询
                    pGeometry = this.axMapControl1.TrackLine();
                    break;

                case 2:         //点查询
                    ESRI.ArcGIS.Geometry.ITopologicalOperator pTopo;
                    ESRI.ArcGIS.Geometry.IGeometry            pBuffer;
                    pGeometry = pPoint;
                    pTopo     = pGeometry as ESRI.ArcGIS.Geometry.ITopologicalOperator;
                    //根据点位创建缓冲区,缓冲半径设为0.005,可自行修改
                    pBuffer   = pTopo.Buffer(0.005);
                    pGeometry = pBuffer.Envelope;
                    break;

                case 3:         //圆查询
                    pGeometry = this.axMapControl1.TrackCircle();
                    break;
                }
                ISelectionEnvironment pSelectionEnv = new SelectionEnvironment(); //新建选择环境
                IRgbColor             pColor        = new RgbColor();
                pColor.Red = 255;
                pSelectionEnv.DefaultColor = pColor;                 //设置高亮显示的颜色
                pMap.SelectByShape(pGeometry, pSelectionEnv, false); //选择图形
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                break;

            default:
                break;
            }
        }