Restricting map zoom levels in Maplibre

  • How can I restrict the zoom levels in my Maplibre map using Wikiocity Maps JS? I want to prevent users from zooming in too close or zooming out too far.

  • You can set the min and max zoom either before or after initializing the map.

    Before:

    use the minZoom and maxZoom options while initializing the Maplibre map through the MglOptions global variable. More information in the docs at Map Settings - MapLibre.

    //settings

    MglOptions = {

    minZoom: 5,

    maxZoom: 18

    };

    //initialize map code

    var map = ...

    After:

    Another option is to use map.setMinZoom(minZoomLevel) and map.setMaxZoom(maxZoomLevel) methods after initializing the map. For example:

    //after map initialization

    map.setMinZoom(5);

    map.setMaxZoom(18);

    This way, you can dynamically update the allowed zoom levels during runtime if needed.

    Hope this helps!

Register or Login to Post

< /div>