Mapbox-gl-native: Camera min-/max-zoom restricted by location plugin

Created on 14 Oct 2018  路  10Comments  路  Source: mapbox/mapbox-gl-native

When using the latest mapbox version 6.6.0 and the location plugin (CameraMode.None), the zoom level bounds are restricted by some hardcoded values (or anything else). As soon as I comment out the location plugin, the zoom levels are fine.

Reference to my location plugin init method:

val engine = LocationEngineProvider(context).obtainBestLocationEngineAvailable()
engine.priority = LocationEnginePriority.HIGH_ACCURACY
engine.fastestInterval = 1000
engine.addLocationEngineListener(this)
locationEngine = engine

mapboxMap.locationComponent.activateLocationComponent(context!!, engine)
mapboxMap.locationComponent.cameraMode = CameraMode.NONE
mapboxMap.locationComponent.renderMode = RenderMode.NORMAL

Steps to reproduce

  1. Create a MapView
  2. Initalise the Location Plugin using the CameraMode.None and RenderMode.Normal
  3. Try to zoom beyond level 2.0 or 18.0

Expected behavior

You can zoom to whatever valid zoom level you want, unless you've added min/max values to your settings.

Actual behavior

The zoom only works between 2.0 and 18.0.

Configuration

Mapbox SDK versions: 6.6.0

Android

Most helpful comment

@Mordag
The issue stems from the following in LocationComponent:

  private void updateMapWithOptions(final LocationComponentOptions options) {
    mapboxMap.setPadding(
      options.padding()[0], options.padding()[1], options.padding()[2], options.padding()[3]
    );

    mapboxMap.setMaxZoomPreference(options.maxZoom());
    mapboxMap.setMinZoomPreference(options.minZoom());
  }

This is done for any kind of LocationComponent configuration while it should only be applied with using a specific Camera/Render mode.

As seen in the code above, you can workaround this by initialising your LocationLayerOptions with other values as the default. This should unblock you for now until we have a fix in place. Lmk if this didn't provide the expected result.

All 10 comments

Thank you for the report @Mordag. These restrictions shouldn't apply if you haven't enabled a specific CameraMode/RenderMode.

cc @LukasPaczos @danesfeder

@tobrun Can I provide you with more information somehow to help fix this bug?

@Mordag
The issue stems from the following in LocationComponent:

  private void updateMapWithOptions(final LocationComponentOptions options) {
    mapboxMap.setPadding(
      options.padding()[0], options.padding()[1], options.padding()[2], options.padding()[3]
    );

    mapboxMap.setMaxZoomPreference(options.maxZoom());
    mapboxMap.setMinZoomPreference(options.minZoom());
  }

This is done for any kind of LocationComponent configuration while it should only be applied with using a specific Camera/Render mode.

As seen in the code above, you can workaround this by initialising your LocationLayerOptions with other values as the default. This should unblock you for now until we have a fix in place. Lmk if this didn't provide the expected result.

@tobrun I've tried to use the LocationComponentOptions, but it breaks more stuff than it fixes:

...
val options = mapboxMap.locationComponent.locationComponentOptions
val newOptions = options.toBuilder().minZoom(MIN_ZOOM).maxZoom(MAX_ZOOM).build()
mapboxMap.locationComponent.activateLocationComponent(context!!, engine, newOptions)
...

It fixes the minZoom/maxZoom bug but creates issues with the map style and other things. It seems like that toBuilder() does not copy the existing values correctly.

Update:
It seems like there is another bug using LocationComponentOptions. As soon as I start using these options, the onCameraMove was not called anymore.

It fixes the minZoom/maxZoom bug but creates issues with the map style and other things. It seems like that toBuilder() does not copy the existing values correctly.

Could you be more concretely here about which values?

Items to look into:

  • [ ] only setMin/max config for specific Camera/Render mode
  • [ ] look into toBuilder copying values
  • [ ] OnCameraMove not being called

It fixes the minZoom/maxZoom bug but creates issues with the map style and other things. It seems like that toBuilder() does not copy the existing values correctly.

Could you be more concretely here about which values?

For example my clusters are all transparent (instead of having a circle and being black) and no icons appear on the mapview anymore. But those clusters still have their cluster number displayed in the correct font. It seems like it silently crashes while creating certain mapview layers when using that custom LocationComponentOptions impl.

@tobrun Do you have any updates regarding this issue?

@Mordag thank you for the ping, no immediate timeline but definitely on our backlog

This is targeted by https://github.com/mapbox/mapbox-gl-native/pull/13425.

To answer your other questions:

It fixes the minZoom/maxZoom bug but creates issues with the map style and other things. It seems like that toBuilder() does not copy the existing values correctly.

options are not initialized until the component is activated. To modify existing options you should change your logic to:

mapboxMap.locationComponent.activateLocationComponent(context!!, engine)
val options = mapboxMap.locationComponent.locationComponentOptions
val newOptions = options.toBuilder().minZoom(MIN_ZOOM).maxZoom(MAX_ZOOM).build()
mapboxMap.locationComponent.applyStyle(newOptions)

It seems like there is another bug using LocationComponentOptions. As soon as I start using these options, the onCameraMove was not called anymore.

I'm unable to reproduce this behavior, onCameraMove fires just fine for me after reseting the options. Would you mind providing more context?

It seems like it silently crashes while creating certain mapview layers when using that custom LocationComponentOptions impl.

Unfortunately, I'm unable to reproduce those issues as well. Would you mind inspecting your logcat for a stack trace or more leads? Any reproducible example would be really appreciated as well.

If any of the above are still an issue, please feel free to open a new ticket, thanks!

@LukasPaczos Thank you for your answer. I will try to provide you with more information regarding the issue with onCameraMove and the layers in a new issue when I get the time to create an example project for you.

Was this page helpful?
0 / 5 - 0 ratings