When map div has content at init, layer mouseenter zone gets offset
- We have a map div which has some noscript text at init ("JavaScript must be enabled")
- We create a MapBoxGL JS map in that div, overwriting the noscript
- We add a GeoJSON as a circle layer
- We use a mouseenter event to trigger a popup as recommended in the docs
In MapBoxGL 1.9.0, I couldn't hover over the marker; the mouseenter/mouseover zone is shifted down ~15 pixels, apparently due to that initial noscript text. I have a demo here: https://mggg.github.io/covid-flows/index_mb.html?4
Before trying removing that noscript, I downgraded to 1.8.0 and the map worked again. It did not assume an empty div or remove the noscript text. So 1.9.0 appears to be handling these divs differently.
If you set the display of the "no-script" div to none, it fixes the issue. Add the following code when you know JavaScript is available before loading your map that does this:
document.getElementsByClassName('no-script')[0].style.display = 'none';
Better yet, replace your no-script div with the <noscript> HTML tag. https://www.w3schools.com/TAGs/tag_noscript.asp
Probably caused by this change https://github.com/mapbox/mapbox-gl-js/commit/bf9ea51187df6404b7b3c8b1f3a1c7ed3ca7e08d#diff-ef8efc27e1b6b3798b0808ef2909f0dd
I had a similar problem. Took me a while to find this ticket, but left me to find the solution. In my case, the problem was a that was in the map container div. I think I'd also assumed anything in the map div would get replaced.
So (in the interest of adding keywords for other people running into this issue and search for it), if your click region is not matching up/overlapping to visible circle (or the like) in your layer... check what's in the main DIV in your code.
I just had this problem as well. I would look into removing any classes from your map div. My map div had a boostrap class and my solution was to wrap the map div with another div to add the bootstrap class back in.
original: <div class="col-md-9" id="map" > </div>
fix: <div class="col-md-9">
<div id="map"></div>
</div>
@adriancotter So (in the interest of adding keywords for other people running into this issue and search for it), if your click region is not matching up/overlapping to visible circle (or the like) in your layer... check what's in the main DIV in your code.
I'm experiencing this issue where my click region for circles is a handful of pixels to the right of the actual circle as shown below. Crosshair id default pointer and pointer is mouseenter.


I'm using Mapbox gl js in a react app framework. Anyone have any helpful thoughts on how to correct this?
Hey @dcdenu4 what is the raw html of the page, before the JS comes into play... and what is the root element for the map. I assume the HTML you shared here is the rendered HTML. The issue for everyone on this ticket has been either some element placed within the map root element, or css on that root element.
@adriancotter
The issue for everyone on this ticket has been either some element placed within the map root element, or css on that root element.
Interesting, the root element for the map is a bootstrap Col component where the map is added by reference. I then have some sub components that I overlay onto the map. I'll try to isolate and simplify the structure to see if I can get an expected base case. Thanks.
return (
<Col className="map-container" ref={mapContainer} >
<VerticalMenu
changeVisibilityState={changeVisibilityState}
changeScaleState={changeScaleState}
geocoderNational={geocoderNational}
geocoderAdmin={geocoderAdmin}
/>
I have been working from the mapbox and react tutorial: https://docs.mapbox.com/help/tutorials/use-mapbox-gl-js-with-react/
yeah @dcdenu4 see @waflorasurveys comment. He was using an earlier version of bootstrap, but he moved the bootstrap classes into a higher element. The VerticalMenu HTML could potentially also be an issue though.
I was able to fix the issue by isolating my map reference in it's own div like others have suggested here. It has brought about some CSS hell though! Thanks @adriancotter for the assist.
return (
//<Col className="map-container" ref={mapContainer} >
<Col className="map-container" >
<div ref={mapContainer}></div>
<VerticalMenu
changeVisibilityState={changeVisibilityState}
changeScaleState={changeScaleState}
geocoderNational={geocoderNational}
geocoderAdmin={geocoderAdmin}
/>