Zoom to feature - Arcgis Engine

452
3
08-26-2012 06:07 PM
New Contributor
Hi,

I would like to know if there is any way to find what's the closest zoom level available for a map when geosearching an address.

Setting the zoom level to a static number works fine in most cases, but sometimes the map is blurry.

Thank you.
Reply
0 Kudos
3 Replies
Occasional Contributor II
I assume you're using cached services from ArcGIS server.

Best thing to do is to save the cache levels to an array and the zoom to the closest one.

David
Reply
0 Kudos
New Contributor
Hi David,

Is there any code reference that I can refer to.

Thanks.
Reply
0 Kudos
Occasional Contributor II
I wrote a sample app for a customer and this the part with black magic 😄


        void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
        {
            if (oldScale != m_mapControl.MapScale)
            {
                // Fill with cached map scales
                double[] cachedScales = new double[] { 1500, 15000, 55000, 125000, 350000, 750000, 1500000, 3500000, 13000000, 60000000 };
                double newScale = cachedScales[cachedScales.Length-1];
                // Scale changed!
                // Scale to the closest scale level of cached map service
                for (int i = 1; i<cachedScales.Length; i++) {
                    if (cachedScales >= m_mapControl.MapScale)
                    {
                        if (Math.Abs(cachedScales[i - 1] - m_mapControl.MapScale) <= Math.Abs(cachedScales - m_mapControl.MapScale))
                        {
                            newScale = cachedScales[i - 1];
                        }
                        else {
                            newScale = cachedScales;
                        }

                        break;
                    }
                }

                oldScale = newScale;
                m_mapControl.MapScale = newScale;
                m_mapControl.ActiveView.Refresh();
                oldScale = m_mapControl.MapScale;
               
            }
        }


Reply
0 Kudos