Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display only + and - in the mapbox navigation control

Tags:

mapbox

I am using the following code line to show a navigation control on my map:

  map.addControl(new mapboxgl.NavigationControl());

It displays the Zoom in + and Zoom out - options which are great but it also shows the tilt map option underneath the zoom in and zoom out buttons. I want to remove this and only show Zoom in and Zoom out option. It seems like something simple to fix but I wasn't able to come up with an anser in my research.

like image 313
Emad Khan Avatar asked Nov 16 '25 01:11

Emad Khan


2 Answers

They added the feature to disable the compass. https://docs.mapbox.com/mapbox-gl-js/api/markers/#navigationcontrol

EDIT: you can write it like this

var nav = new mapboxgl.NavigationControl({
        showCompass: false,
        showZoom: true
      });

map.addControl(nav, "top-left");
like image 75
monchisan Avatar answered Nov 17 '25 20:11

monchisan


Looks like the Mapbox GL JS team is planning on adding the ability to the mapboxgl.Navigation() function to disable the compass, but for now, disabling it in the CSS is the preferred way to do it:

.mapboxgl-ctrl-compass {
    display: none !important;
}
like image 28
David Birks Avatar answered Nov 17 '25 22:11

David Birks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!