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;
            }
        }

Re: UI marker labels

Hi.

Most likely your problem is that you are not using the scale of the markers when calculating the tooltip position.

If the problem persists:
Unfortunately, in this case it is difficult for me to understand what exactly is wrong in your case.
If possible send me your project via email or DM in discord. I will check and tell you exactly what is wrong.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: UI marker labels

As you suggested, I modify this part of the code and solve my problem.
Thank you Alex.

              
                // Adjust for the scaled height of the marker
                float scaledHeight = tooltipMarker.height * tooltipMarker.scale;
                screenPosition.y += scaledHeight;