Hello
I am trying to create a MapTool that allows the user to find a location based on a string road reference.
The user can enter the road reference in a textblock in an Embeddable Control, and hit enter or click a search button, and the maptool will then send a request to an API that returns the coordinates of the road reference.
The coordinates is then used to make a mappoint that is added to the map as a graphic. And I also want these graphics to be disposed when the maptool is closed.
I have bound a ICommand in the EmbeddableControls viewmodel, to the textblock and search button which in turn run a method in Module1 which handles the search-request to the road-reference API.
I can add the graphic to the MapView via MapView.Active.AddOverlay, however this creates a problem as the graphic will not be disposed automatically when the tool is deactivated.
Preferably I would rather use the active maptools AddOverlay method to add the graphics there, but I can’t figure out how to get access to the tools AddOverlay-method in Module1 or the viewmodel. I have tried to store the maptool-instance in both Module1 and the viewmodel for the embeddable control, but this has not worked.
Is there some other way to get access to the active maptool in a module or the viewmodel? I am in no way experienced with C#, so my attempts on solving this is more akin to throwing spaghetti at the wall and seeing what sticks.
Any help on this is much appreciated as I am thoroughly stuck in a rut.
Kind regards
Tor
Solved! Go to Solution.
You can use the AddOverlay and AddOverlayAsync methods that are available for the MapView class: ProConcepts Map Exploration · Esri/arcgis-pro-sdk Wiki (github.com)
AddOverlay Method (MappingExtensions)—ArcGIS Pro
Or you can look at the attached sample that stores a reference to the MapTool in the Module class and uses the MapTools AddOverlay method. However, when you switch the tool the map point on the map will disappear. The tool looks like this:
You can use the AddOverlay and AddOverlayAsync methods that are available for the MapView class: ProConcepts Map Exploration · Esri/arcgis-pro-sdk Wiki (github.com)
AddOverlay Method (MappingExtensions)—ArcGIS Pro
Or you can look at the attached sample that stores a reference to the MapTool in the Module class and uses the MapTools AddOverlay method. However, when you switch the tool the map point on the map will disappear. The tool looks like this:
This worked like a charm. Thanks a bunch Wolf, this makes it so much easier to work with graphics when I gain access to the MapTool overlay instead.
You had asked about clearing the graphics layer on closing the tool. I use a clearGraphics() overlay function that is called when the user clicks the Close button on the form Or changes to another tool. You can catch the Deactivate event by adding this code in your primary namespace (i.e., the same module where you will find the OnToolActivateAsync() procedure).
protected override Task OnToolDeactivateAsync(bool hasMapViewChanged)
{
clearGraphics();
return base.OnToolDeactivateAsync(hasMapViewChanged);
}