in SupportingScripts/Runtime/Scripts/MapRenderer/MapPin/MapPinLayer.cs [188:288]
private void UpdateMapPinsInView(object sender, EventArgs args)
{
Profiler.BeginSample("UpdateMapPinsInView");
if (_mapPinSpatialIndex != null)
{
EnsureContainerGameObjectIsCreated();
_containerGo.gameObject.SetActive(true);
List<MapPin> mapPinsInView;
List<ClusterMapPin> clusterMapPinsInView;
if (MapRenderer.MapShape == MapShape.Block)
{
_mapPinSpatialIndex.GetPinsInView(
MapRenderer.MercatorBoundingBox,
MapRenderer.ZoomLevel,
_clusterMapPinPrefab,
_containerGo.transform,
out mapPinsInView,
out clusterMapPinsInView);
}
else // Cylinder.
{
_mapPinSpatialIndex.GetPinsInView(
MapRenderer.MercatorBoundingBox,
MapRenderer.MercatorBoundingCircle,
MapRenderer.ZoomLevel,
_clusterMapPinPrefab,
_containerGo.transform,
out mapPinsInView,
out clusterMapPinsInView);
}
// Update visible MapPins' position and other properties.
{
MapPin.SynchronizeLayers(mapPinsInView, MapRenderer);
MapPin.SynchronizeLayers(clusterMapPinsInView, MapRenderer);
MapRenderer.TrackAndPositionPinnables(mapPinsInView);
MapRenderer.TrackAndPositionPinnables(clusterMapPinsInView);
MapPin.UpdateScales(mapPinsInView, MapRenderer);
MapPin.UpdateScales(clusterMapPinsInView, MapRenderer);
}
// Disable MapPins that are no longer visible.
{
_mapPinsInViewThisFrame.Clear();
_mapPinsInViewThisFrame.UnionWith(mapPinsInView);
foreach (var previousActiveMapPin in _activeMapPins)
{
if (previousActiveMapPin != null && !_mapPinsInViewThisFrame.Contains(previousActiveMapPin))
{
MapRenderer.UntrackPinnable(previousActiveMapPin);
previousActiveMapPin.gameObject.SetActive(false);
}
}
_clusterMapPinsInViewThisFrame.Clear();
_clusterMapPinsInViewThisFrame.UnionWith(clusterMapPinsInView);
foreach (var previousActiveClusterMapPin in _activeClusterMapPins)
{
if (previousActiveClusterMapPin != null && !_clusterMapPinsInViewThisFrame.Contains(previousActiveClusterMapPin))
{
MapRenderer.UntrackPinnable(previousActiveClusterMapPin);
previousActiveClusterMapPin.gameObject.SetActive(false);
}
}
// Filter out pins that have not been fully positioned, i.e. are still awaiting an elevation sample.
// As a side effect, this will also enable any pins once any initial async op used to position them has completed.
_mapPinsInViewThisFrame.RemoveWhere(
(MapPin mapPin) =>
{
mapPin.gameObject.SetActive(mapPin.HasBeenFullyPositioned);
return !mapPin.HasBeenFullyPositioned;
});
_clusterMapPinsInViewThisFrame.RemoveWhere(
(ClusterMapPin clusterMapPin) =>
{
clusterMapPin.gameObject.SetActive(clusterMapPin.HasBeenFullyPositioned);
return !clusterMapPin.HasBeenFullyPositioned;
});
// Assign collections to layer properties.
{
_activeMapPins.Clear();
_activeMapPins.UnionWith(_mapPinsInViewThisFrame);
_mapPinsInViewThisFrame.Clear();
_activeClusterMapPins.Clear();
_activeClusterMapPins.UnionWith(_clusterMapPinsInViewThisFrame);
_clusterMapPinsInViewThisFrame.Clear();
}
}
}
Profiler.EndSample();
}