Mixed-zoom is a feature that loads map regions in which areas that are close to the player contain a high level of detail, while areas that are further away contain progressively lower levels of detail.
The resulting scenes contain vector tiles rendered at distance-dependent zoom levels, with a horizon in the far distance. It means you can render maps that span thousands of meters or more, while using considerably less processing — which translates to a better in-game experience for players.
How it works
Mixed-zoom uses a simple map loading mechanism that uses the
Google.Maps.Loading.MapLoader
component. The Google.Maps.Loading.MixedZoom
component allows you to set additional parameters for mixed-zoom. The following
sample code demonstrates how to use mixed-zoom.
using Google.Maps;
using Google.Maps.Loading;
using UnityEngine;
[RequireComponent(typeof(MapLoader), typeof(MixedZoom))]
public class MixedZoomMapLoader : MonoBehaviour {
private MapLoader MapLoader;
public void Start() {
MapLoader = GetComponent<MapLoader>();
MapLoader.Init(new GameObjectOptions() { ... });
}
public void Update() {
MapLoader.Load();
MapLoader.UnloadUnused();
}
}
Script parameters
This section lists the parameters for the Map Loader script component, and the Mixed Zoom script component. The following image shows these script components in the Unity Inspector.
The Map Loader script component
- Maps Service
- The instance of the entry point to the Maps SDK for Unity, used to load the map.
- Zoom
- The zoom level used to load the map in the foreground.
- Region Shape
- An enumeration with the following two values:
- Circle: Loads a circle around the camera position. This is intended to be used when the player has panning control over the camera.
- Viewport: Loads only the portion of the map that's visible to the camera.
- Horizon
- The maximum distance from the camera position for loading the map.
- Unload Unused Seconds
- When
MapLoader.UnloadUnused()
is called, unloads parts of the map that haven't been loaded or rendered in this many seconds.
The Mixed Zoom script component
- Foreground Distance
- Up to this distance from the camera, the map is loaded at the zoom level specified in
Map Loader
. - Falloff Distance
- Beyond the foreground distance, the distance between zoom levels doubles, starting with the falloff distance. See the following diagram for details:
Caveats
When using mixed-zoom, the Maps SDK for Unity switches between active and
inactive GameObjects in OnPreRender()
, depending on which objects are the most
appropriate to render for the current camera position.