-
Notifications
You must be signed in to change notification settings - Fork 120
ProGuide MapView Interaction
Language: C#
Subject: Map Exploration
Contributor: ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization: Esri, http://www.esri.com
Date: 10/06/2024
ArcGIS Pro: 3.4
Visual Studio: 2022
This guide demonstrates how to create a map tool for zoom in, zoom out. A left-click will center the map on the clicked location and zoom in, and a right-click will center the map on the clicked location and zoom out. It also shows how to override the mouse and keyboard events. Note that the map tool does not use sketching (IsSketchTool
is not set in the constructor). See ProConcepts Map Exploration, MapTool for more information on the MapTool pattern.
Prerequisites
- Download and install the sample data required for this guide as instructed in Arcgis Pro SDK Community Samples Releases.
- Create a new ArcGIS Pro Module Add-in, and name the project MapToolZoom. If you are not familiar with the ArcGIS Pro SDK, you can follow the steps in the ProGuide Build your first add-in to get started.
- Add a new ArcGIS Pro Add-ins | ArcGIS Pro Map Tool item to the add-in project, and name the item MapToolZoomInOut.
Step 1
Modify the Config.daml file tool item as follows:
- Change the caption to "Zoom In/Out".
- Change the tool heading to "Zoom In/Out" and the ToolTip text to "Left click on the map to zoom in, or right-click on the map to zoom out."
...
<tool id="MapToolZoom_MapToolZoomInOut"
caption="Zoom In/Out" className="MapToolZoomInOut"
keytip="TZ" loadOnClick="true"
smallImage="GenericButtonRed16" largeImage="GenericButtonRed32"
condition="esri_mapping_mapPane">
<tooltip heading="Zoom In/Out">
Left click on the map to zoom in, or right-click on the map to zoom out.
<disabledText />
</tooltip>
</tool>
...
Build the sample and validate the UI on the ArcGIS Pro ribbon:
Step 2
The required zoom in/out functionality must be implemented in the MapToolZoomInOut class.
First, remove all stubbed out code in the MapToolZoomInOut constructor since you are not using the sketch functionality of the MapTool base class.
public MapToolZoomInOut()
{
}
Next, add code to support zoom in/out. First, override OnToolMouseDown to signal to the ArcGIS Pro FrameworkApplication that MapToolZoomInOut will handle these mouse events. Then, override HandleMouseDownAsync to implement the actual handler for your mouse-controlled zoom in and out. In the handler, use the map point that was clicked as the new center (looked at) point of your map view, and zoom in or out depending on left or right mouse clicks.
protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
{
// On mouse down, check if the mouse button pressed is:
// the left mouse button to handle zoom in
// or the right mouse button to handle zoom out.
// If it is handle the event.
switch (e.ChangedButton)
{
case MouseButton.Right:
e.Handled = true;
break;
case MouseButton.Left:
e.Handled = true;
break;
}
}
protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
{
// Get the map coordinates from the click point and change the Camera to zoom in or out.
return QueuedTask.Run(() =>
{
var mapClickPnt = MapView.Active.ClientToMap(e.ClientPoint);
ActiveMapView.LookAt(mapClickPnt, TimeSpan.FromSeconds(1));
// zoom out
if (e.ChangedButton == MouseButton.Right)
{
ActiveMapView.ZoomOutFixed(TimeSpan.FromSeconds(1));
}
// zoom in
else if (e.ChangedButton == MouseButton.Left)
{
ActiveMapView.ZoomInFixed(TimeSpan.FromSeconds(1));
}
});
}
In addition to the mouse clicks, We will also support zoom in/out through the cursor keys. Add code to support this by overriding the OnToolKeyDown and HandleKeyDownAsync routines. Override OnToolKeyDown to signal to the ArcGIS Pro FrameworkApplication that MapToolZoomInOut will handle these keys when they are pressed. Override HandleKeyDownAsync to implement the actual handler for the key-controlled zoom in and out. In the handler, zoom in or out depending on the cursor key that was pressed.
protected override void OnToolKeyDown(MapViewKeyEventArgs k)
{
// using key up and down in order to zoom out and in
// if those keys are used we need to mark them as handled
if (k.Key == Key.Up || k.Key == Key.Down)
k.Handled = true;
base.OnToolKeyDown(k);
}
protected override Task HandleKeyDownAsync(MapViewKeyEventArgs k)
{
// only called when 'handled' in OnToolKeyDown
if (k.Key == Key.Up)
{
// Key.Up => zoom out
return ActiveMapView.ZoomOutFixedAsync(TimeSpan.FromSeconds(1));
}
// Key.Down => zoom in
// else if (k.Key == Key.Down)
{
return ActiveMapView.ZoomInFixedAsync(TimeSpan.FromSeconds(1));
}
}
Step 3
Rebuild the add-in. Fix any compilation errors.
Step 4
Debug the add-in. Run the debugger and start ArcGIS Pro. Open the C:\Data\Interacting with Maps\Interacting with Maps.aprx project that contains a 3D map with feature data.
Try the mouse click on the 2D map first. Verify the zoom.
Try the mouse click on key up and down on the 3D scene. Verify the zoom.
Home | API Reference | Requirements | Download | Samples
- Overview of the ArcGIS Pro SDK
- What's New for Developers at 3.4
- Installing ArcGIS Pro SDK for .NET
- Release notes
- Resources
- Pro SDK Videos
- ProSnippets
- ArcGIS Pro API
- ProGuide: ArcGIS Pro Extensions NuGet
Migration
- ProSnippets: Framework
- ProSnippets: DAML
- ProConcepts: Framework
- ProConcepts: Asynchronous Programming in ArcGIS Pro
- ProConcepts: Advanced topics
- ProGuide: Custom settings
- ProGuide: Command line switches for ArcGISPro.exe
- ProGuide: Reusing ArcGIS Pro Commands
- ProGuide: Licensing
- ProGuide: Digital signatures
- ProGuide: Command Search
- ProGuide: Keyboard shortcuts
Add-ins
- ProGuide: Installation and Upgrade
- ProGuide: Your first add-in
- ProGuide: ArcGIS AllSource Project Template
- ProConcepts: Localization
- ProGuide: Content and Image Resources
- ProGuide: Embedding Toolboxes
- ProGuide: Diagnosing ArcGIS Pro Add-ins
- ProGuide: Regression Testing
Configurations
Customization
- ProGuide: The Ribbon, Tabs and Groups
- ProGuide: Buttons
- ProGuide: Label Controls
- ProGuide: Checkboxes
- ProGuide: Edit Boxes
- ProGuide: Combo Boxes
- ProGuide: Context Menus
- ProGuide: Palettes and Split Buttons
- ProGuide: Galleries
- ProGuide: Dockpanes
- ProGuide: Code Your Own States and Conditions
Styling
- ProSnippets: Content
- ProSnippets: Browse Dialog Filters
- ProConcepts: Project Content and Items
- ProConcepts: Custom Items
- ProGuide: Custom Items
- ProGuide: Custom browse dialog filters
- ArcGIS Pro TypeID Reference
- ProSnippets: Editing
- ProConcepts: Editing
- ProConcepts: COGO
- ProConcepts: Annotation Editing
- ProConcepts: Dimension Editing
- ProGuide: Editing Tool
- ProGuide: Sketch Tool With Halo
- ProGuide: Construction Tools with Options
- ProGuide: Annotation Construction Tools
- ProGuide: Annotation Editing Tools
- ProGuide: Knowledge Graph Construction Tools
- ProGuide: Templates
3D Analyst Data
Plugin Datasources
Topology
Linear Referencing
Object Model Diagram
- ProSnippets: Geometry
- ProSnippets: Geometry Engine
- ProConcepts: Geometry
- ProConcepts: Multipatches
- ProGuide: Building Multipatches
Relational Operations
- ProSnippets: Knowledge Graph
- ProConcepts: Knowledge Graph
- ProGuide: Knowledge Graph Construction Tools
Reports
- ProSnippets: Map Authoring
- ProSnippets: Annotation
- ProSnippets: Charts
- ProSnippets: Labeling
- ProSnippets: Renderers
- ProSnippets: Symbology
- ProSnippets: Text Symbols
- ProConcepts: Map Authoring
- ProConcepts: Annotation
- ProConcepts: Dimensions
- ProGuide: Tray buttons
- ProGuide: Custom Dictionary Style
- ProGuide: Geocoding
3D Analyst
CIM
Graphics
Scene
Stream
Voxel
- ProSnippets: Map Exploration
- ProSnippets: Custom Pane with Contents
- ProConcepts: Map Exploration
- ProGuide: Map Pane Impersonation
- ProGuide: TableControl
Map Tools
- ProGuide: Feature Selection
- ProGuide: Identify
- ProGuide: MapView Interaction
- ProGuide: Embeddable Controls
- ProGuide: Custom Pop-ups
- ProGuide: Dynamic Pop-up Menu
Network Diagrams
- ArcGIS Pro API Reference Guide
- ArcGIS Pro SDK (pro.arcgis.com)
- arcgis-pro-sdk-community-samples
- ArcGISPro Registry Keys
- ArcGIS Pro DAML ID Reference
- ArcGIS Pro Icon Reference
- ArcGIS Pro TypeID Reference
- ProConcepts: Distributing Add-Ins Online
- ProConcepts: Migrating to ArcGIS Pro
- FAQ
- Archived ArcGIS Pro API Reference Guides
- Dev Summit Tech Sessions