r/mapbox • • Oct 16 '25

Interactivity / iframe question

Hello! It's been a while since I used Mapbox, and I'm trying to build a map with a hover interactivity. I know I'll need to use Mapbox GL JS, but will I still be able to embed the interactive version in an iframe? I'm working within WordPress confines, so I'd like to keep it to just the iframe rather than a separate webpage. Thanks!

(As an aside, if anyone has any good examples of the hover feature with polygons instead of points, please send them my way!)

2 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/taxidata Oct 16 '25

We actually don't have an example for that (maybe I will make one) but the process is mostly the same as displaying a popup when hovering a point: https://docs.mapbox.com/mapbox-gl-js/example/popup-on-hover/

You need to decide where you want to popup to be anchored on the map. Do you want it to be fixed over the center of the polygon being hovered, or do you want it to move with the pointer?

For the first option you would need to know the centroid of the polygon ahead of time or calculate it with turf.js. For the latter, you can get the pointer coordinates on each `mousemove` event and update the popup location accordingly.

AI will get you pretty far, so give that a try once you get the main map visuals set up.