Posted By

christianjunk on 02/05/11


Tagged

ArcObjects


Versions (?)

Zoom to selected feature(s)


 / Published in: C#
 

URL: http://forums.esri.com/Thread.asp?c=159&f=1707&t=233785

Here is the sample code you can use to zoom to selected features. Please replace m_hookHelper with valid mapcontrol object.

  1. public void ZoomToSelectedFeatures()
  2. {
  3. ESRI.ArcGIS.Carto.IActiveView pActiveView;
  4. ESRI.ArcGIS.Carto.IMap pMap;
  5. ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumFeature;
  6. ESRI.ArcGIS.Geodatabase.IFeature pFeature;
  7.  
  8. pMap = (IMap)m_hookHelper.FocusMap;
  9. pEnumFeature = (IEnumFeature)pMap.FeatureSelection;
  10. pFeature = pEnumFeature.Next();
  11.  
  12. ESRI.ArcGIS.Geometry.IEnvelope pEnvelope;
  13. pEnvelope = new EnvelopeClass();
  14.  
  15. while (pFeature != null)
  16. {
  17. pEnvelope.Union(pFeature.Shape.Envelope);
  18. pFeature = pEnumFeature.Next();
  19. }
  20.  
  21. pEnvelope.Expand(1.2, 1.2, true);
  22. pActiveView = m_hookHelper.ActiveView;
  23. pActiveView.Extent = pEnvelope;
  24. pActiveView.Refresh();
  25. }

Report this snippet  

You need to login to post a comment.