How to detect a click event on Azure Maps geometries

Kevin Cai 40 Reputation points
2023-07-21T19:51:43.89+00:00

How can clicks on geometries drawn in Azure Maps be detected?

It would also be helpful if you could tell me if once I receive the clicked shape, how to enable edit and erase programmatically on that shape.
I couldn't find these in the documentations, thanks in advance!

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
832 questions
{count} votes

Accepted answer
  1. rbrundritt 20,836 Reputation points Microsoft Employee Moderator
    2023-07-21T23:10:30.2466667+00:00

    There are several ways to have an event fire when a geometry is clicked:

    1. Add a click event to the layer that displays the geometry.
    2. Add a click event to the map and look to see what geometries are clicked (you will likely end up with a bunch of the base map geometries mixed in like roads and things that you will have to filter through).

    It sounds like you want to be able to click a geometry and then put it into edit mode or erase it. In that case it is best to use the drawing tools module for Azure Maps and then add your geometry to the data source of the drawing manager. That automatically adds the required events for you. Then you just click the edit or erase button from the drawing tool bar. Here is a code samples for this: https://samples.azuremaps.com/?search=drawing&sample=load-data-into-drawing-manager

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.