Select to view content in your preferred language

Getting coordinates using button accessed via right-click context menu

717
1
03-06-2024 03:11 PM
JMagson
Emerging Contributor

I want a button that is accessed when you right-click on the map with the explorer or selection tool.

This needs to get the coordinates of where on the map was right-clicked.

Currently, I can only get the coordinates from the centre of the map view like this:

{
protected override void OnClick()
{

// Get the current map view
var mapView = MapView.Active;

if (mapView == null)
{
Console.WriteLine("No active map view found.");
return;
}

// Get the extent of the map view
var extent = mapView.Extent;

// Get the center of the extent (which represents the point where the context menu was opened)
var mapPoint = extent.Center;

// Print the map coordinates
Console.WriteLine($"Map Coordinates: X={mapPoint.X}, Y={mapPoint.Y}");

 

I know you can get the coordinates using a map tool by clicking on the map. But it seems you cannot add map tool to the context menu of selection/explorer tool, unless I am mistaken. i acheived a work around by creating a button that opens the map tool.

However, I would prefer a method to get the coordinates using the button so that the user does not need to click on the map again.

 

Is there any inbuilt method to do this in SDK?

 

 

 

0 Kudos
1 Reply
sjones_esriau
Esri Contributor

Hi,

Here's an old editing sample that uses the right-click coordinate to find a feature.

https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Editing/ReplaceSketch
(take a look in ReplaceSketch.cs)

The command is added to the sketch context menu via config.daml.

0 Kudos