Topic: UI marker labels
Hi, I use the following code to position labels above my markers.
I also have an option for the users to scale the markers to be bigger or smaller to the map.
I realise that when I run on standalone of device with different aspect ratio, the labels are not right above the marker. Some times labels are very far up from the markers.
How to deal with different marker scales and different screen ratio to display correctly all marker labels right above the marker?
Here is the code:
private void OnUpdateLate()
{
OnlineMapsMarker tooltipMarker = OnlineMapsTooltipDrawerBase.tooltipMarker as OnlineMapsMarker;
if (tooltipMarker != null)
{
if (tooltip == null)
{
tooltip = Instantiate(tooltipPrefab) as GameObject;
(tooltip.transform as RectTransform).SetParent(container.transform);
}
Vector2 screenPosition = OnlineMapsControlBase.instance.GetScreenPosition(tooltipMarker.position);
screenPosition.y += tooltipMarker.height;
Vector2 point;
Camera cam = container.renderMode == RenderMode.ScreenSpaceOverlay ? null : container.worldCamera;
RectTransformUtility.ScreenPointToLocalPointInRectangle(container.transform as RectTransform, screenPosition, cam, out point);
(tooltip.transform as RectTransform).localPosition = point;
tooltip.GetComponentInChildren<Text>().text = tooltipMarker.label;
}
else
{
OnlineMapsUtils.Destroy(tooltip);
tooltip = null;
}
}