Using Maptool from ViewModel through XAML's button instead of config.daml with tool loadOnClick ="true"

2176
7
Jump to solution
07-20-2021 12:28 PM
LY90
by
New Contributor II

I have been trying to implement a custom sketch tool and use it from my dockpane. 

I came cross an example from ArcGIS-pro's community sample "Map-Exploration/IdentifyWithSketchTool" , custom identify tool link:https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Map-Exploration/IdentifyWithSke...

I see it got activated by from config.daml's <tool> tag with attribute loadOnClick="true"

I'm essentially want to achieve the same behavior from my dockpane's viewmodel using a button, how can I do that? 

Thanks! 

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I attached a sample with a tool that is instantiated from a dockpane and reports the selection results on the dockpane:

Wolf_0-1626820210998.png

 

View solution in original post

7 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I assume that your dockpane code and your map tool are in the same add-in.  In this case the JIT loading/pre-loading that you refer to above (https://github.com/Esri/arcgis-pro-sdk/wiki/ProGuide-Buttons#preload-a-button ) is not relevant.  Just implement your map tool (using the Button item template from the SDK) and try to use it from the button on the Pro ribbon (the default button added by the SDK template).  If the tool works as expected you can then add a button to your XAML and follow the implementation for reusing Pro buttons in MVVM:  ProGuide Reusing Pro Commands · Esri/arcgis-pro-sdk Wiki (github.com)  

If the tool works from your dockpane you can remove the map tool reference from config.daml in case you don't need the map tool's button to be shown on the Pro ribbon.

 

0 Kudos
LY90
by
New Contributor II

Thanks for replying Wolf, 

Good point, it seems I completely misunderstood the loadOnClick="true", thanks for your califrication. 

Is it possible to use the custom MapTool directly from my Viewmodel? 

For example: 

My dockpane xaml has code: 

<Button Grid.Row="1" Content="Identify Feature" Command="{Binding IdentifyCommand}"/>

My Viewmodel has Icommand implementation:

protected IdentifyDockpaneViewModel()
{
   IdentifyCommand = new RelayCommand(IdentifyClick);   
}

public ICommand IdentifyCommand { get; private set; }

private async Task IdentifyClick()
{
CustomIdentify identifyTool = new CustomIdentify ();
... (Some code goes here)
}

 

It seems the instance would get initiated successfully at line 10 above, but OnSketchCompleteAsync method never got called .. Did I miss something important here?.. 

thanks! 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I attached a sample with a tool that is instantiated from a dockpane and reports the selection results on the dockpane:

Wolf_0-1626820210998.png

 

LY90
by
New Contributor II

Awesome, Thanks a lot for the code sample @Wolf ! 

0 Kudos
LY90
by
New Contributor II

@Wolf  

Hi Wolf, some additional questions on this topic.. 

1: How do I toggle off the sketch? 

2: Do I always need to have the button from the daml and reference it? Can I just have it from viewmodel?

 

Thanks! 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

for 1: 
you can reset the current tool to the default tool when you're done.  In the sample code that would look like this:

public void UpdateStatusFromAnyThread (string msg)
{
  RunOnUiThread(() =>
  {
	SelectionResult = msg;
        // reset the current tool to the default (explore) tool
	FrameworkApplication.SetCurrentToolAsync("esri_mapping_exploreTool");
  });
}

for 2:

You can remove the ribbon reference, but not the maptool definition, so your config.daml can look like this:

<groups>
  <!-- comment this out if you have no controls on the Addin tab to avoid
        an empty group-->
  <group id="DockPaneWithTool_Group1" caption="Group 1" appearsOnAddInTab="true">
	<!-- NOT NEEDED in the UI 
    <tool refID="DockPaneWithTool_MySelectionTool" size="large" />
	-->
    <button refID="DockPaneWithTool_MyDockpane_ShowButton" size="large" />
  </group>
</groups>

but make sure that you don't remove the <tool ... > tag.

 

LY90
by
New Contributor II

thanks Wolf! 

0 Kudos