How to Suppress the Map Click Event When Clicking on a Symbol or Polygon

Ken Bowman 211 Reputation points
2024-08-02T20:01:40.88+00:00

Hi,

I have click events on both the map and on several layers. For example, you can click on a symbol in a layer and information related to the symbol (e.g. a dealership) shows in a popup. If there is no symbol where you click, I show a popup with general information regarding the area. However, both map and layer events fire when clicking a symbol, with the map's click event firing before the layer's. How can I suppress the map's click event when clicking on a symbol?

Thanks,

Ken

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

Accepted answer
  1. rbrundritt 18,061 Reputation points Microsoft Employee
    2024-08-04T02:10:50.5066667+00:00

    First make sure you add your events in the order you want them to fire (layer events before map events). Then, in the event arg there is a preventDefault function. Simply call this function in your layer event handler. For example:

    function layerClickedEventHandler(eventArg) {
        //Don't allow the event to bubble up to the next attached item. 
        eventArg.preventDefault();
    }
    
    1 person 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.