Select to view content in your preferred language

Draw a rectangle and gather coordinates from custom usercontrol within addin

5068
11
Jump to solution
08-10-2021 03:06 AM
SebastianKrings
Frequent Contributor

Hi,

I have an AddIn where the user gets a dialog to do some Stuff.
Within this dialog the user shall be able to click a button.

On Click the user shall be able to draw a rectangle directly on the map. After MouseRelease the coordinates of the drawn rectangle are gathered and shown in the dialog.

I found this sample which does almost what I want:

https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Map-Exploration/MapToolIdentify...

@Wolf : found another thread you told that you posted that sample. My you can help me out?

 

The problem with this and all other samples I found so far about MapTool or SketchTool is that they all are added directly to the AddIn-Tab. As said I want to be able to have the click inside on of my custom usercontrols. I tried adding the corresponding XML of the MapTool to my userControl (instead of button which is there as placeholder).

 

 

<UserControl x:Class="MyProject.MyControl"
[....]>

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MyProject;component\Application\Styles\Standard.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
	<StackPanel Orientation="Horizontal">
		<Label Content="{x:Static resx:UiResources.DataSelection_SpatialFilter_Radio_Window}" />
		<Button
			Style="{DynamicResource Esri_Button}"
			Command="{Binding CoordinatesByRectangleCommand}"
			ToolTip="Draw Rectangle and gather the coordinates."/>

		<tool id="MapToolIdentifyWithDockpane_MapToolIdentify" caption="Identify Features" className="MapToolIdentifyWithDockpane" loadOnClick="true" smallImage="Images\GenericButtonRed16.png" largeImage="Images\GenericButtonRed32.png" condition="esri_mapping_mapPane" keytip="z2">
			<tooltip heading="Identify Features">
				Identify features on the current map using a circular sketch.
				<disabledText />
			</tooltip>
		</tool>
	</StackPanel>
</UserControl>

 

 

The thing is, that my VS cannot resolve symbol tool.

 

It is very difficult to find any documentary about MapTools so I am unsure whether it even is possible to call a MapTool like I wish here.

 

If not, maybe there is another way to achieve getting the coordinates from a button-click within my custom usercontrol?

 

Hopefully there are some helping minds.
Thanks.

0 Kudos
11 Replies
SebastianKrings
Frequent Contributor

Looks like this works to restore the mapexplore als default.

        protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
        {
            [...]

            var cmd = FrameworkApplication.GetPlugInWrapper("esri_mapping_exploreTool") as ICommand;
            if ((cmd != null) && cmd.CanExecute(null))    // --> CanExecute results to false
            {
                cmd.Execute(null);
            }

            return true;
        }

 

Is that fine or is there a better way to perfom?

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Use FrameworkApplication.SetCurrentToolAsync to set the current tool using the tool's daml id.  

 

// pass the tool's daml id as parameter
FrameworkApplication.SetCurrentToolAsync("esri_mapping_exploreTool");