Pan and zoom commands


Purpose
This sample provides a set of sample panning and zooming commands and tools that can be used in conjunction with the MapControl, PageLayoutControl and ToolbarControl. The sample assumes previous experience in creating custom tools and commands.

How to use

If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Include the header file of the command you wish to use.
  2. Create an instance of the command and place it on the toolbar in an ArcGIS Controls application using AoToolbarAddTool. See Additional information below for an example.
  3. Run the ArcGIS Controls application. Click on the tool you added to the ToolbarControl and then try it by clicking with it in either the MapControl or PageLayoutControl.

Additional information

This sample includes the following commands and tools:
  • FixedZoomIn, FixedZoomOut Command's: The IEnvelope::Expand method is used to scale the size of the IActiveView::Extent in order to zoom in/out on the FocusMap by a fixed amount.
  • ZoomIn, ZoomOut Tool's: An INewEnvelopeFeedback object is used to track an IEnvelope in the OnMouseDown, OnMouseMove and OnMouseUp events which is then set to the IActiveView::Extent property of the FocusMap. If the ESC key is pressed the track is cancelled.
  • FullExtent Command: The IActiveView::Extent property is set to the FullExtent of all the data layers present in the FocusMap.
  • GoBackToPrevious (UndoExt), GoToNextExtent (RedoExt) Command's: The IActiveView::Extent property is set to the previous/next extent held in the IActiveView::ExtentStack of the FocusMap.
  • Pan Tool: The IScreenDisplay::PanStart/PanMoveTo methods are used within the OnMouseDown and OnMouseMove events to start and move a pan, and the IScreenDisplay::PanStop method is used within the OnMouseUp event to set the IActiveView::Extent property of the FocusMap to the new visible bounds.
  • PanDown, PanLeft, PanUp, PanRight Command's: The IActiveView::Extent property of the FocusMap is centered on a Point to the left/right/top/bottom of the current extent's center.
 
To add a command or tool onto the toolbar you will use AoToolbarAddTool. The following example shows how to add the ZoomIn command:
 
// ipToolbarControl is a ToolbarControl defined and created earlier in the code
ZoomIn* zoomIn = new ZoomIn;
AoToolbarAddTool(ipToolbarControl, zoomIn, esriCommandStyleIconOnly);


FixedZoomIn.cpp Implementation of FixedZoomIn command.
FixedZoomIn.h Header file for FixedZoomIn command.
FixedZoomOut.cpp Implementation of FixedZoomOut command.
FixedZoomOut.h Header file for FixedZoomOut command.
FullExt.cpp Implementation of FullExtent command.
FullExt.h Header file for FullExtent command.
Pan.cpp Implementation of Pan command.
Pan.h Header file for Pan command.
PanDown.cpp Implementation of PanDown command.
PanDown.h Header file for PanDown command.
PanLeft.cpp Implementation of PanLeft command.
PanLeft.h Header file for PanLeft command.
PanRight.cpp Implementation of PanRight command.
PanRight.h Header file for PanRight command.
PanUp.cpp Implementation of PanUp command.
PanUp.h Header file for PanUp command.
RedoExt.cpp Implementation of RedoExt command (same as NextExtent command).
RedoExt.h Header file for RedoExt command (same as NextExtent command).
UndoExt.cpp Implementation of UndoExt command (same as PrevExtent command).
UndoExt.h Header file for UndoExt command (same as PrevExtent command).
ZoomIn.cpp Implementation of ZoomIn command.
ZoomIn.h Header file for ZoomIn command.
ZoomOut.cpp Implementation of ZoomOut command.
ZoomOut.h Header file for ZoomOut command.
Download the Motif_CPP files

Download the files for all languages




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime