After successfully implementing a Mapbox map on my website, I encountered a challenge. I wanted to add a button on top of the mapview, but couldn't figure out how to do so using HTML as it always ended up below the map. To overcome this obstacle, I found a solution by creating a programmatic button in JavaScript.
function setupMap(center){
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: center,
zoom: 14
});
const nav = new mapboxgl.NavigationControl();
map.addControl(nav);
var button = document.body.appendChild(document.createElement('button'));
button.style = 'z-index:10;position:absolute;top:10px;right:10px;';
button.textContent = 'Calculate Consumption';
Now I am looking to customize the style of the button. Is there a way to achieve this? Alternatively, is there a method to place a standard HTML button on top of the map?