This Operations Dashboard for ArcGIS sample demonstrates how to implement a custom map tool that allows a user to zoom to an extent that they draw on the map. It also includes a custom toolbar to allow cancelation and prevent other tools use in the meantime.
Operations Dashboard for ArcGIS samples are supported only in Visual Studio 2012. A live preview is not available.
To run this sample, open the solution in Visual Studio 2012, set the Start Action and Start Options debug options in the Project Properties as described in the Testing add-ins help topic, and then build and run the project.
<UserControlx:Class="ZoomExtentMapToolCS.ZoomExtentMapTool"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"xmlns:opsDash="clr-namespace:ESRI.ArcGIS.OperationsDashboard;assembly=ESRI.ArcGIS.OperationsDashboard"mc:Ignorable="d"><Grid><Buttonx:Name="ZoomButton"Style="{StaticResource ToolbarButtonStyle}"ToolTip="Click on the map and drag a rectangle to zoom to."Click="Button_Click"><ImageSource="/ZoomExtentMapToolCS;component/Images/ZoomBox16.png"Stretch="None"/></Button></Grid></UserControl>
// Copyright 2013 ESRI// // All rights reserved under the copyright laws of the United States// and applicable international laws, treaties, and conventions.// // You may freely redistribute and use this sample code, with or// without modification, provided you include the original copyright// notice and use restrictions.// // See the use restrictions http://help.arcgis.com/en/sdk/10.0/usageRestrictions.htm.// using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel.Composition;
using System.Runtime.Serialization;
using ESRI.ArcGIS.OperationsDashboard;
using client = ESRI.ArcGIS.Client;
namespace ZoomExtentMapToolCS
{
[Export("ESRI.ArcGIS.OperationsDashboard.MapTool")]
[ExportMetadata("DisplayName", "Zoom to extent C#")]
[ExportMetadata("Description", "Custom zoom to extent map tool sample C#")]
[ExportMetadata("ImagePath", "/ZoomExtentMapToolCS;component/Images/ZoomBox16.png")]
[DataContract]
publicpartialclass ZoomExtentMapTool : UserControl, IMapTool
{
// This map tool uses a custom toolbar to help implement cancelation.private CancelationToolbar _cancelToolbar = null;
public ZoomExtentMapTool()
{
InitializeComponent();
}
#region IMapTool
// IMapTool MapWidget property just saves a reference to the map that the tool is hosted in.public MapWidget MapWidget { get; set; }
publicvoid OnActivated()
{
// No actions required when this tool is activated.
}
publicvoid OnDeactivated()
{
// Clean up any objects if still set.if (_cancelToolbar != null)
{
_cancelToolbar = null;
}
}
publicbool CanConfigure
{
// No configuration required for this tool.get { returnfalse; }
}
publicbool Configure(System.Windows.Window owner)
{
// Not implemented as CanConfigure returned false.thrownew NotImplementedException();
}
#endregionprivatevoid Button_Click(object sender, RoutedEventArgs e)
{
// When the user clicks the map tool button, begin installing zoom code.// Ensure the tool has a valid map to work with.if ((MapWidget != null) && (MapWidget.Map != null))
{
// Provide a way for the user to cancel the operation, by installing a temporary toolbar.// This also prevents other tools from being used in the meantime.
_cancelToolbar = new CancelationToolbar(MapWidget);
MapWidget.SetToolbar(_cancelToolbar);
}
}
}
}
' Copyright 2013 ESRI' ' All rights reserved under the copyright laws of the United States' and applicable international laws, treaties, and conventions.' ' You may freely redistribute and use this sample code, with or' without modification, provided you include the original copyright' notice and use restrictions.' ' See the use restrictions http://help.arcgis.com/en/sdk/10.0/usageRestrictions.htm.' Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading
Imports System.Threading.Tasks
Imports System.Windows
Imports System.Windows.Controls
Imports System.ComponentModel.Composition
Imports System.Runtime.Serialization
Imports ESRI.ArcGIS.OperationsDashboard
Imports client = ESRI.ArcGIS.Client
''' <summary>''' A MapTool is an extension to ArcGIS Operations Dashboard which can be configured to appear in the toolbar ''' of the map widget, providing a custom map tool.''' </summary>
<Export("ESRI.ArcGIS.OperationsDashboard.MapTool"),
ExportMetadata("DisplayName", "Zoom to extent VB.Net"),
ExportMetadata("Description", "Custom zoom to extent map tool sample VB.Net"),
ExportMetadata("ImagePath", "/ZoomExtentMapToolVB;component/Images/ZoomBox16.png"),
DataContract()>
PublicClass ZoomExtentMapTool
Inherits UserControl
Implements IMapTool
' This map tool uses a custom toolbar to help implement cancelation.Private _cancelToolbar As CancelationToolbar = Nothing' IMapTool MapWidget property just saves a reference to the map that the tool is hosted in.PublicProperty MapWidget As MapWidget Implements IMapTool.MapWidget
PublicSub OnActivated() Implements IMapTool.OnActivated
' No actions required when this tool is activated.EndSubPublicSub OnDeactivated() Implements IMapTool.OnDeactivated
' Clean up any objects if still set.If (Not _cancelToolbar IsNothing) Then
_cancelToolbar = NothingEndIfEndSubPublicReadOnlyProperty CanConfigure AsBooleanImplements IMapTool.CanConfigure
Get' No configuration required for this tool.ReturnFalseEndGetEndPropertyPublicFunction Configure(owner As Window) AsBooleanImplements IMapTool.Configure
' Not implemented as CanConfigure returned false.ThrowNew NotImplementedException()
EndFunctionPrivateSub Button_Click(sender AsObject, e As RoutedEventArgs)
' When the user clicks the map tool button, begin installing zoom code.' Ensure the tool has a valid map to work with.If ((Not MapWidget IsNothing) AndAlso (Not MapWidget.Map IsNothing)) Then' Provide a way for the user to cancel the operation, by installing a temporary toolbar.' This also prevents other tools from being used in the meantime.
_cancelToolbar = New CancelationToolbar(MapWidget)
MapWidget.SetToolbar(_cancelToolbar)
EndIfEndSubEndClass