How do you change the hover text on the Polygon tool in Mapbox GL JS?

Viewed 378

mapbox/mapbox-gl-draw lets you add a Polygon tool to your Mapbox map. I have that working in a ReactJS project. Now I want to change the text that appears when I hover the Polygon tool button. How do I do that?

Polygon tool, when hovered

I found the line in the mapbox-gl-draw code that assigns this hover text to the button's title attribute. So I could fork mapbox-gl-draw, just to change that line. But I would prefer not to have to do that.

This is the part of my code where I am adding the polygon control:

const draw = new MapboxDraw({
  displayControlsDefault: false,
  controls: {
    polygon: true
  },
  modes,
  userProperties: true
})
1 Answers

What about something like this?

document.querySelector(".mapbox-gl-draw_ctrl-draw-btn.mapbox-gl-draw_polygon").setAttribute("title", "your own tooltip")
Related