Esri / arcobjects-sdk-community-samples

This repo contains the source code samples (.Net c#, .Net vb, and C++) that demonstrate the usage of the ArcObject SDK.
Apache License 2.0
124 stars 194 forks source link

How to zoom to raster resolution? #16

Open yh371174229 opened 4 years ago

yh371174229 commented 4 years ago

I use this code,but it's not perfect solution

            pActiveView.Extent = (pRasterLayer as IGeoDataset).Extent;
            IntPtr pHandle = new IntPtr(pActiveView.ScreenDisplay.hWnd);
            AxMapControl axMapControl1 = Form.FromHandle(pHandle) as AxMapControl;
            int controlWidth = axMapControl1.Width;
            double controlW = Convert.ToDouble(controlWidth);
            IMap pMap = pActiveView.FocusMap;
            pMap.MapScale = (controlW / pRasterLayer.ColumnCount * pMap.MapScale);
            MessageBox.Show(pMap.MapScale.ToString());
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

ArcGIS 10.6.1+C#