Skip to content

Commit bd8d901

Browse files
committed
add comments to public methods of MapboxMap and MapboxMapVisualizer classes
1 parent 7cea2cf commit bd8d901

File tree

2 files changed

+127
-3
lines changed

2 files changed

+127
-3
lines changed

Runtime/Mapbox/BaseModule/Map/MapboxMap.cs

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99

1010
namespace Mapbox.BaseModule.Map
1111
{
12+
/// <summary>
13+
/// The primary object responsible for controlling and rendering the map.
14+
/// </summary>
15+
/// <remarks>
16+
/// - <see cref="MapInformation"/>: Contains information about the map location,
17+
/// detail level, and basic camera controls.
18+
/// - <see cref="MapVisualizer"/>: Handles styling and visualization of the specified location.
19+
/// - <see cref="MapService"/>: Manages interactions with the Mapbox API and data handling.
20+
/// </remarks>
1221
[Serializable]
1322
public sealed class MapboxMap
1423
{
@@ -28,6 +37,10 @@ public MapboxMap(IMapInformation information, UnityContext unityContext, MapServ
2837
MapService = mapMapService;
2938
}
3039

40+
/// <summary>
41+
/// Initialization method which organizes caches and object pool craeting, meta data loading etc.
42+
/// </summary>
43+
/// <returns></returns>
3144
public IEnumerator Initialize()
3245
{
3346
if (Status != InitializationStatus.WaitingForInitialization)
@@ -40,15 +53,30 @@ public IEnumerator Initialize()
4053

4154
Status = InitializationStatus.Initialized;
4255
Initialized();
43-
4456
}
4557

58+
/// <summary>
59+
/// Map update method, which we currently use per-frame, to recalculate the tile cover and run map visualizer on it.
60+
/// </summary>
4661
public void MapUpdated()
4762
{
4863
MapService.TileCover(MapInformation, TileCover);
4964
MapVisualizer.Load(TileCover);
5065
}
5166

67+
/// <summary>
68+
/// Provides a controlled method for jumping to specific locations on the map.
69+
/// Unlike standard frame-by-frame map updates, this method ensures precise
70+
/// control over the transition process.
71+
/// </summary>
72+
/// <param name="callback">An optional callback method to execute upon completion.</param>
73+
/// <remarks>
74+
/// - Uses the location already in the settings, useful for initial map load then runtime location changes.
75+
/// - Triggers events at the start and end of the loading process, useful for showing
76+
/// or hiding a loading screen.
77+
/// - Suspends per-frame map updates during the loading phase and resumes them
78+
/// once loading is complete.
79+
/// </remarks>
5280
public void LoadMapView(Action callback)
5381
{
5482
Status = InitializationStatus.LoadingView;
@@ -64,11 +92,25 @@ public void LoadMapView(Action callback)
6492
}));
6593
}
6694

67-
public void LoadMapView(Action callback, LatitudeLongitude coordinates)
95+
/// <summary>
96+
/// Provides a controlled method for jumping to specific locations on the map.
97+
/// Unlike standard frame-by-frame map updates, this method ensures precise
98+
/// control over the transition process.
99+
/// </summary>
100+
/// <param name="targetLocation">The destination coordinates as a <see cref="LatitudeLongitude"/> instance.</param>
101+
/// <param name="callback">An optional callback method to execute upon completion.</param>
102+
/// <remarks>
103+
/// - Takes a LatitudeLongitude for new map location.
104+
/// - Triggers events at the start and end of the loading process, useful for showing
105+
/// or hiding a loading screen.
106+
/// - Suspends per-frame map updates during the loading phase and resumes them
107+
/// once loading is complete.
108+
/// </remarks>
109+
public void LoadMapView(Action callback, LatitudeLongitude targetLocation)
68110
{
69111
Status = InitializationStatus.LoadingView;
70112
LoadViewStarting();
71-
MapInformation.SetInformation(coordinates);
113+
MapInformation.SetInformation(targetLocation);
72114
Runnable.Instance.StartCoroutine(LoadMapViewCoroutine(() =>
73115
{
74116
MapService.TileCover(MapInformation, TileCover);
@@ -80,6 +122,23 @@ public void LoadMapView(Action callback, LatitudeLongitude coordinates)
80122
}));
81123
}
82124

125+
/// <summary>
126+
/// Provides a controlled method for jumping to specific locations on the map.
127+
/// Unlike standard frame-by-frame map updates, this method ensures precise
128+
/// control over the transition process.
129+
///
130+
/// </summary>
131+
/// <param name="targetLocation">The destination coordinates as a <see cref="LatitudeLongitude"/> instance.</param>
132+
/// <param name="callback">An optional callback method to execute upon completion.</param>
133+
/// <returns>
134+
/// An <see cref="IEnumerator"/> that can be used for coroutine-based execution.
135+
/// This allows the loading process to be handled asynchronously.
136+
/// </returns>
137+
/// <remarks>
138+
/// - Returns an IEnumerator to let developers create and control their own coroutine.
139+
/// - Does not pause per-frame updates.
140+
/// - Does not trigger start and finished events.
141+
/// </remarks>
83142
public IEnumerator LoadMapViewCoroutine(Action callback)
84143
{
85144
var tileCover = new TileCover();
@@ -88,6 +147,14 @@ public IEnumerator LoadMapViewCoroutine(Action callback)
88147
callback();
89148
}
90149

150+
/// <summary>
151+
/// Change the map core settings.
152+
/// If the per-frame updates are enabled, new settings will be applied next frame.
153+
/// </summary>
154+
/// <param name="latlng">Location to show</param>
155+
/// <param name="zoom">Zoom level of the map</param>
156+
/// <param name="pitch">Pitch value of the camera</param>
157+
/// <param name="bearing">Bearing value of the camera</param>
91158
public void ChangeView(LatitudeLongitude? latlng = null, float? zoom = null, float? pitch = null, float? bearing = null)
92159
{
93160
MapInformation.SetInformation(latlng, zoom, pitch, bearing);
@@ -101,10 +168,29 @@ public void OnDestroy()
101168

102169
public void UpdateTileCover() => MapService.TileCover(MapInformation, TileCover);
103170

171+
/// <summary>
172+
/// All modules are initialized, you can get&use any object and/or register to events safely.
173+
/// </summary>
104174
public Action Initialized = () => {};
175+
/// <summary>
176+
/// Load view procedure is starting. Status is set to InitializationStatus.LoadingView and per-frame updates
177+
/// are suspended until this procedure finishes.
178+
/// </summary>
105179
public Action LoadViewStarting = () => { };
180+
/// <summary>
181+
/// Load view procedure is finished. Status is set to InitializationStatus.ReadyForUpdates and per-frame updates
182+
/// will continue.
183+
/// </summary>
106184
public Action LoadViewCompleted = () => { };
185+
/// <summary>
186+
/// Map tile finished loading with targeted detail level data. This tile isn't temporary anymore, it'll be in
187+
/// ActiveTiles list.
188+
/// </summary>
107189
public Action<UnityMapTile> TileLoaded = (tile) => { };
190+
/// <summary>
191+
/// Map tile unloading event fires for tiles that are still in active tiles list but not in the latest tileCover.
192+
/// UnityMapTile object attached to event will be pooled after the event call.
193+
/// </summary>
108194
public Action<UnityMapTile> TileUnloading = (tile) => { };
109195
}
110196
}

Runtime/Mapbox/BaseModule/Map/MapboxMapVisualizer.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
namespace Mapbox.BaseModule.Map
1212
{
13+
/// <summary>
14+
/// The primary object responsible for preparing the data and generating the visuals of the map.
15+
/// </summary>
1316
[Serializable]
1417
public class MapboxMapVisualizer : IMapVisualizer
1518
{
@@ -45,13 +48,25 @@ public virtual IEnumerator Initialize()
4548
yield return LayerModules.Select(x => x.Initialize()).WaitForAll();
4649
}
4750

51+
/// <summary>
52+
/// Prepare data and visuals for given tile cover. It loads the data to memory, generates vector feature visuals
53+
/// and prepare it all to ensure following tile requests will be finished in single frame.
54+
/// So this method doesn't create the tile, it prepares everything inside a tile.
55+
/// </summary>
56+
/// <param name="tileCover"></param>
57+
/// <returns></returns>
4858
public virtual IEnumerator LoadTileCoverToMemory(TileCover tileCover)
4959
{
5060
var hashsetTiles = new HashSet<CanonicalTileId>(tileCover.Tiles.Select(x => x.Canonical));
5161
var coroutines = LayerModules.Select(x => x.LoadTiles(hashsetTiles));
5262
yield return coroutines.WaitForAll();
5363
}
5464

65+
/// <summary>
66+
/// Create the map in given tileCover area. Makes decision to load or unload tiles and handle temporary filler
67+
/// tiles until actual tiles are loaded.
68+
/// </summary>
69+
/// <param name="tileCover"></param>
5570
public virtual void Load(TileCover tileCover)
5671
{
5772
_tileCreatedThisFrame = 0;
@@ -102,6 +117,7 @@ public virtual void Load(TileCover tileCover)
102117

103118
foreach (var tileId in _toRemove)
104119
{
120+
//this tryget is unnecessary, just get it. it cannot not be there.
105121
if (ActiveTiles.TryGetValue(tileId, out var tile))
106122
{
107123
TileUnloading(tile);
@@ -151,6 +167,15 @@ public void OnDestroy()
151167
}
152168
}
153169

170+
/// <summary>
171+
/// Find a LayerModule by given type. LayerModules are kept as ILayerModule and this method queries by concrete
172+
/// so it might cause unexpected issues if there are multiple layer modules of same type. This method will simply
173+
/// return the first one found.
174+
/// </summary>
175+
/// <param name="type"></param>
176+
/// <param name="module"></param>
177+
/// <typeparam name="T"></typeparam>
178+
/// <returns></returns>
154179
public bool TryGetLayerModule<T>(Type type, out T module) where T : ILayerModule
155180
{
156181
module = (T)LayerModules.FirstOrDefault(x => x.GetType() == type);
@@ -283,6 +308,11 @@ protected bool FinalizeTempTile(UnityMapTile unityMapTile)
283308
return tileFinished;
284309
}
285310

311+
/// <summary>
312+
/// Triggers the repositioning for all tiles per module. This is necessary for vector module to move feature visuals
313+
/// if (and only if) map settings are such that camera is static and map&tiles are moving (slippy map).
314+
/// </summary>
315+
/// <param name="mapInformation"></param>
286316
protected void RepositionAllTiles(IMapInformation mapInformation)
287317
{
288318
foreach (var tilePair in ActiveTiles)
@@ -296,7 +326,15 @@ protected void RepositionAllTiles(IMapInformation mapInformation)
296326
}
297327
}
298328

329+
/// <summary>
330+
/// Map tile finished loading with targeted detail level data. This tile isn't temporary anymore, it'll be in
331+
/// ActiveTiles list.
332+
/// </summary>
299333
public event Action<UnityMapTile> TileLoaded = (tile) => { };
334+
/// <summary>
335+
/// Map tile unloading event fires for tiles that are still in active tiles list but not in the latest tileCover.
336+
/// UnityMapTile object attached to event will be pooled after the event call.
337+
/// </summary>
300338
public event Action<UnityMapTile> TileUnloading = (tile) => { };
301339
}
302340
}

0 commit comments

Comments
 (0)