Skip to content

Max/Min Zoom

Note

You can find the full source code of this example in MaxMinZoomActivity.kt of the MapLibreAndroidTestApp.

This example shows how to configure a maximum and a minimum zoom level.

maplibreMap.setMinZoomPreference(3.0)
maplibreMap.setMaxZoomPreference(5.0)

Bonus: Add Click Listener

As a bonus, this example also shows how you can define a click listener to the map.

maplibreMap.addOnMapClickListener {
    if (this::maplibreMap.isInitialized) {
        maplibreMap.setStyle(Style.Builder().fromUri(TestStyles.AMERICANA))
    }
    true
}

You can remove a click listener again with MapLibreMap.removeOnMapClickListener. To use this API you need to assign the click listener to a variable, since you need to pass the listener to that method.

.openmaptiles_caption at 0x7f5d7ca77b00>