mapbox / mapbox-unity-sdk

Mapbox Unity SDK - https://www.mapbox.com/unity/
Other
725 stars 210 forks source link

Setting the Map Extent Options to CameraBounds at runtime doesn't work #1904

Open mmoussa opened 1 year ago

mmoussa commented 1 year ago

I'm trying to set the map extent options to Camera Bounds at runtime, and I'm running into the following error:

NullReferenceException: Object reference not set to an instance of an object
Mapbox.Unity.Map.TileProviders.QuadTreeTileProvider.OnInitialized () (at Assets/Mapbox/Unity/Map/TileProviders/QuadTreeTileProvider.cs:50)
Mapbox.Unity.Map.TileProviders.AbstractTileProvider.Initialize (Mapbox.Unity.Map.Interfaces.IMap map) (at Assets/Mapbox/Unity/Map/TileProviders/AbstractTileProvider.cs:34)
Mapbox.Unity.Map.AbstractMap.OnTileProviderChanged () (at Assets/Mapbox/Unity/Map/AbstractMap.cs:1013)
Mapbox.Unity.Map.AbstractMap.SetExtent (Mapbox.Unity.Map.MapExtentType extentType, Mapbox.Unity.Map.ExtentOptions extentOptions) (at Assets/Mapbox/Unity/Map/AbstractMap.cs:1166)

image

Here's the code I'm trying:

CameraBoundsTileProviderOptions options = new CameraBoundsTileProviderOptions();
options.camera = mapCamera;
mapManager.SetExtent(MapExtentType.CameraBounds, options);

It seems like the camera that's passed in is reset to null inside OnTileProviderChanged (or the options are reset to the default).

smahalgavaiya commented 1 year ago

Hi if you want to change the camera only in runtime simply use
CameraBoundsTileProviderOptions cameraBoundsOptions = abstractMap.Options.extentOptions.defaultExtents.cameraBoundsOptions; cameraBoundsOptions.camera = mapCamera; image Also check the CameraBoundsTileProviderOptions script it has public Camera camera; public int visibleBuffer; public int disposeBuffer; variables