You are here: > ESRI Forums > arcgis engine forums > Thread Replies

ArcGIS Engine Forums

ArcGIS Engine: ArcObjects .NET API forum

How to get the current extent of MapControl   Peter Li Apr 25, 2006
Re: How to get the current extent of MapCon...   Rudy Lambert Apr 25, 2006
Re: How to get the current extent of MapCon...   Peter Li Apr 25, 2006
Re: How to get the current extent of MapCon...   Peter Li Apr 25, 2006
Re: How to get the current extent of MapCon...   Rudy Lambert Apr 26, 2006
Re: How to get the current extent of MapCon...   Peter Li Apr 26, 2006
Re: How to get the current extent of MapCon...   mustafa kosece May 22, 2006
Re: How to get the current extent of MapCon...   Peter Li May 23, 2006
Re: How to get the current extent of MapCon...   Carl Sun Aug 25, 2006
Re: How to get the current extent of MapCon...   Peter Li Aug 25, 2006
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject How to get the current extent of MapControl 
Author Peter Li 
Date Apr 25, 2006 
Message Hi,

I have experienced the following unsolved problem:

From axMapControl1, the following event method can be used and coded: axMapControl1_OnExtentUpdated.

I have put some codes and tried to get the current extent of MapControl when there is an event coming from zoom in/out of ESRI ToolbarControl.

//But it always gets a previous extent:
IEnvelope currentExtent = axMapControl1.Extent;


However, I always get the previous extent of MapControl after zoom in/out.

Anyone have an idea how to get current extent of MapControl by using the event method in MapControl: axMapControl1_OnExtentUpdated?

Thanks,

Peter 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author Rudy Lambert 
Date Apr 25, 2006 
Message You should be able to use the OnBeforeScreenDraw event (Note Map1 is name of control).

 
 
Private Sub Map1_OnBeforeScreenDraw(ByVal sender As Object, ByVal e As ESRI.ArcGIS.MapControl.IMapControlEvents2_OnBeforeScreenDrawEvent) Handles Map1.OnBeforeScreenDraw
         Try
            Dim moRect As ESRI.ArcGIS.Geometry.IEnvelope
            moRect = New ESRI.ArcGIS.Geometry.Envelope
            moRect = Map1.Extent
            
			'''display moRect.Width here
            '''display Map1.MapScale here
           
        Catch
			'''catch error here
        End Try
    End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author Peter Li 
Date Apr 25, 2006 
Message Thanks a lot. It looks working now. But there is no descriptions about which event has current extent, which one has previous extent in ESRI's interfaces and their methods that may confuse people.


Regards,

Peter 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author Peter Li 
Date Apr 25, 2006 
Message However, this method axMapControl1_OnBeforeScreenDraw is not what I need, it is not better than axMapControl1_OnExtentUpdated, because it always repeats the same calculation and redraws the graphics when the map is hidden and shown by any other window. That event has different behaviour from axMapControl1_OnExtentUpdated. So how could we get current extent from axMapControl1_OnExtentUpdated?

Thanks,

Peter
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author Rudy Lambert 
Date Apr 26, 2006 
Message Hi Peter,

It depends on what you want to do. I use the OnBeforeScreenDraw event to display the current extents and map scale to the user in a status panel. For what its worth, I think its better than OnExtentUpdated because the map scale will change as a response to things such as resizing your form. OnExtentUpdated doesn't do that. For example, paste the code in you application and as you resize the form containing the map control. You will find that the map scale doesn't change. Paste the same code in the OnBeforeScreenDraw event and both values will change.

Again, I guess it depends on what you have in mind. 
 
Private Sub Map1_OnExtentUpdated(ByVal sender As Object, ByVal e As ESRI.ArcGIS.MapControl.IMapControlEvents2_OnExtentUpdatedEvent) Handles Map1.OnExtentUpdated
         Try

            Dim moRect As ESRI.ArcGIS.Geometry.IEnvelope
            moRect = New ESRI.ArcGIS.Geometry.Envelope
            moRect = Map1.Extent
            me.Text = cstr(moRect.Width) & "..." & CStr(Int(Map1.MapScale))


        Catch

            Me.Text = Err.Description
        End Try

    End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author Peter Li 
Date Apr 26, 2006 
Message Thanks for your reply.

But it is too sensitive and always recalculate (that wastes time if using an algorithm for obtaining those graphics) and redraws the graphics using axMapControl1_OnBeforeScreenDraw, even though the extent of MapControl has no change (not only depending on ESRI ToolbarControl, but also other events, like window is hidden and shown).

However, axMapControl1_OnExtentUpdated is applied only based on the extent change (mainly from ESRI ToolbarControl). If the window of MapControl is hidden and shown by other, the graphics won't be recalculated and redraw, instead of displaying the graphics by MapControl.

But the problem is that I couldn't get correct current extent from axMapControl1_OnExtentUpdated.

Thanks,

Peter 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author mustafa kosece 
Date May 22, 2006 
Message maybe, you use iactiveview.extent,also all extents are in iactiveview.extentstack . you can easily get and use extents 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author Peter Li 
Date May 23, 2006 
Message Using axMapControl1_OnExtentUpdated, we always get the previous extent, the current one is not on stack as checked by the following codes:

IActiveView pAView = axMapControl1.ActiveView;
IExtentStack pExtentStack = pAView.ExtentStack;

int i1 = 0,
iExtCount = pExtentStack.Count;
IEnvelope pEnvTmp = new EnvelopeClass();
for (i1=0; i1<=iExtCount; i1++)
{
pEnvTmp = pExtentStack.get_Item(i1);
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author Carl Sun 
Date Aug 25, 2006 
Message In your OnExtentUpdated handler, use following code to get current extent of map control: 
 
IDisplayTransformation pTrans = e.displayTransformation as IDisplayTransformation;
IEnvelope pEnv = pTrans.FittedBounds;
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: How to get the current extent of MapControl 
Author Peter Li 
Date Aug 25, 2006 
Message thanks. Only the fittedbounds work now.