jt5301
jt5301

Reputation: 43

Why does the click event on bing maps get triggered on a different element in Firefox vs. on Chrome / Edge?

I noticed that when I click anywhere in bing maps, the element that listens for the click / gets returned to me is different on Chrome / Edge browsers than on Firefox. For example: I found this basic React app online that can serve as a tool - https://bingmaps-react.netlify.app/ (but you can repro this on a create-react-app + import bing maps using Microsoft.Maps) In devtools, I added this console log to trace what element will listen for a click(

document.addEventListener('click', function(event) { console.log('Element clicked:', event.target); })

on chrome / edge, this element gets returned: enter image description here But on firefox this gets returned: enter image description here

Looking at the elements tab, firefox returns the first element, while chrome returns the inner grandchild: enter image description here It kinda looks like maybe the browsers handle z-index differently? if so, does anyone have any thoughts on how i can make firefox return the same event that chrome / edge does?

Thank you!

Upvotes: 0

Views: 62

Answers (1)

rbrundritt
rbrundritt

Reputation: 18003

It's anyone's guess why Firefox would do this. Nothing to do with Bing Maps as this is the generic event listener of the browser, searching through all elements in the pages DOM. It does seem very odd that Firefox would trigger the event on the parent div (MicrosoftMap) rather than on the canvas which is the top visual item. Note that there are a ton of things browsers do differently. It used to be a bigger issue back in the internet explorer days. Chrome and Edge use the same underlying engine for rendering/JavaScript, so they will act nearly identically.

Note, if you want an event to fire when a user clicks on the map, there are several ways to do this in a consistent way.

All that said, if you are developing a new app with Bing maps, you should only be doing that if your company already has a license for Bing Maps and are well aware that Bing Maps is retiring in 2028 (unlicensed accounts will retire in June of 2025). https://www.microsoft.com/en-us/maps/bing-maps/discontinued-services?msockid=191627acbb23650b07c93534ba316400

Upvotes: 0

Related Questions