LeafletJS: How to remove the zoom control

后端 未结 7 1209
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 11:32

I\'m trying to remove the zoom controls (+/-) on a LeafletJS map.

I\'m using the MapBox.js version of Leaflet but most of the operations are the same as Leaflet. I

相关标签:
7条回答
  • 2020-12-28 12:03

    you can remove the control zoomControl in this way:

    map.removeControl(map.zoomControl);
    
    0 讨论(0)
  • 2020-12-28 12:05

    If you want to dynamically turn on and off zooming you can do something like this:

    map.touchZoom.disable();
    map.doubleClickZoom.disable();
    map.scrollWheelZoom.disable();
    map.boxZoom.disable();
    map.keyboard.disable();
    $(".leaflet-control-zoom").css("visibility", "hidden");
    
    0 讨论(0)
  • 2020-12-28 12:06
    map.scrollWheelZoom.disable();
    
    0 讨论(0)
  • 2020-12-28 12:07

    To dynamically remove then add back the zoom control:

    var map = L.mapbox.map('map');
    
    if( wantToRemove ) {
        map.removeControl( map.zoomControl ); 
    } else {
        map.addControl( map.zoomControl );
    }
    
    0 讨论(0)
  • 2020-12-28 12:16

    This worked for me:

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

    With mapbox try:

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

    See map creation and the zoomControl option in the Leaflet documentation.

    0 讨论(0)
  • 2020-12-28 12:19

    You can just use

    map.zoomControl.remove();

    0 讨论(0)
提交回复
热议问题