2

I have a quick question about how you can remove the zoom control from the MapBox Map.

Below is the current code I have.

I have placed "zoomControl: false" inside the styleLayer section, but it doesn't seem to work...

Can someone help me solve this issue?

<script>
    L.mapbox.accessToken = 'pk.eyJ1IjoidGhsZWUxMTIyIiwiYSI6ImNpeWdyd2tycDAzZTUzMm12eDcybjJocTgifQ.r1njnGgI95MNlwVBTm1slw';
    var map = L.mapbox.map('map') 
        .setView([14.43232, 14.4165], 3);

    // Use styleLayer to add a Mapbox style created in Mapbox Studio
          L.mapbox.styleLayer('mapbox://styles/thlee1122/ciyhpbj15003d2sluqt6ylrqa', {zoomControl: false}).addTo(map);

    map.dragging.disable();
    map.touchZoom.disable();
    map.doubleClickZoom.disable();
    map.scrollWheelZoom.disable();

</script>

2 Answers 2

2

zoomControl is an option of L.mapbox

var map = L.mapbox.map('map', 'mapbox.streets', { zoomControl: false })

https://www.mapbox.com/mapbox.js/api/v2.4.0/l-mapbox-map/

http://leafletjs.com/reference-1.0.3.html#map-option

2
  • Thank you very much for your answer. I tried your solution, but it doesn't seem to work... I am getting "Uncaught TypeError: Cannot read property '0' of undefined" error in the console. When I click on that error, it takes me to "tile_layer.js" file, which I did not create. I think it comes with leaflet or mapbox package. It says below is the part where I am getting error: _setTileJSON: function(json) { util.strict(json, 'object'); this.options.format = this.options.format || json.tiles[0].match(formatPattern)[1]; Could you please help me with this?
    – Tae
    Jan 28, 2017 at 23:33
  • 1
    sorry, I missed the 2nd arg before the options (I'm not too sure what you have to put in your case)
    – YaFred
    Jan 28, 2017 at 23:46
1

Because you are using styleLayer to add a Mapbox style created in Mapbox Studio you have to add "null" to the call before passing options.

var map = L.mapbox.map('map', null, { zoomControl:false });

L.mapbox.styleLayer('mapbox://styles/xxxxx').addTo(map);
1
  • Thanks for this awesome answer!
    – jbramble76
    May 27, 2020 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.