How to disable event to propagate in Bing Maps v8?

tamasoz 21 Reputation points
2023-04-05T16:43:30.6833333+00:00

I am trying to temporarily disable user's panning ability in a mapping application using Bing Maps v8 (JavaScript). This code sort of works, but I see in the debugger console that I get an error saying "preventDefault is not a function". The code does work and panning is indeed not happening (nor any other mousedown event) - but the exception is always thrown. Any advice would be appreciated!


disableHandlerId = Microsoft.Maps.Events.addHandler(map, 'mousedown', function (mouseEvent) {

                mouseEvent.preventDefault();

            });
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
587 questions
Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
245 questions
{count} votes

1 answer

Sort by: Most helpful
  1. rbrundritt 15,226 Reputation points Microsoft Employee
    2023-04-05T17:44:30.12+00:00

    To temporarily disable panning you can set the disablePanning option of the map accordingly. This would be much easier that trying to block events within the map, especially since there are several ways to pan a map (mouse, touch, keyboard).

    For example:

    map.setOptions({
        disablePanning: true
    });
    
    map.setOptions({
    		disablePanning: false
    	});
    

    As a quick test, here is some code that would disable panning for 5 seconds after the map loads, then reenable it:

    var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
    map.setOptions({
        disablePanning: true
    });
    
    setTimeout(() => {
    	map.setOptions({
    		disablePanning: false
    	});
    }, 5000);
    
    1 person found this answer helpful.
    0 comments No comments