1 (edited by digitalmkt 2022-09-26 15:12:29)

Topic: Line Renderer Exact Position on the Map.

Hi Alex, We did some stress test trying to find the limit of markers rendered on a map instance, and we reach the limit of around 1000 to 1024 markers on a single map with an acceptable frame rate dropping. After that number (1024) the app throw a timeout exception on mobile devices tested. Just to let you know, one of our clients has approximately 51k waypoints in 48 hiking tracks.

The plan is to have the waypoints painting the tracks on the map with a quite accurate detail because the hiking tracks are placed in the middle of nowhere in the countryside, justified the number of waypoints. We've planned dividing the tracks in stages with up to 1000 waypoins each and put it all together in a cluster or group, but it's not worth because we're just moving the problem ahead to the backend team.

We decided to follow with LineRenderer that solved our problem without compromising the frame rate too much, adding the possibility of having more control over the line colors, width and simplify positions i.e. The LineRenderer solution fits very well in this case.

The problem we found it's the same as here: https://forum.infinity-code.com/viewtopic.php?id=1570.

How to place the LineRenderer exactly on the map? Noticing that this is also mirrored.

Attached you´ll find the LineRenderer Inspector with the positions values after converted, the pink line rendered anywhere on the world, and the map with the red line rendered with OnlineMapsDrawingLine, where the LineRenderer should appear

The code we're using:

    private void GetData()
    {
        _tracks = File.ReadAllText(m_JsonPath);
        Tracks _waypoints = JsonUtility.FromJson<Tracks>(_tracks);
        Debug.Log("waypoints Loaded" + _waypoints);

        int length = 0;
        length = _waypoints.points.Length;
        Debug.Log("Lenght is: " + length);

        LineRenderer lineRenderer = map.AddComponent<LineRenderer>();
        lineRenderer.useWorldSpace = true;
        lineRenderer.widthCurve = AnimationCurve.Constant(0, length, 2);
        lineRenderer.positionCount = length;
        lineRenderer.startWidth = 2.0f;
        lineRenderer.endWidth = 2.0f;
        lineRenderer.numCapVertices = capEnds;
        lineRenderer.numCornerVertices = capCurves;
        Debug.Log("Line Renderer");

        List<Vector2> linepoints = new List<Vector2>();

        foreach (Waypoints tracks_ in _waypoints.points)
        {
            Debug.Log("lat: " + tracks_.longitude + " Long:" + tracks_.latitude);

            float longx = float.Parse(tracks_.longitude);
            float laty = float.Parse(tracks_.latitude);
            string name = tracks_.stageId;

            linepoints.Add(new Vector2 (longx, laty));
        }

        for (int i = 0; i < linepoints.Count; i++)
        {
            Debug.Log("Where we´re drawing the line:" + linepoints[i].ToString());
            Vector3 p = OnlineMapsTileSetControl.instance.GetWorldPosition(linepoints[i].x, linepoints[i].y);
            Debug.Log("Where we´re drawing the line after convertion: " + p.x.ToString() + " " + p.z.ToString());
            lineRenderer.SetPosition(i, new Vector3(p.x, 1, p.z));
          
        }

    }

Thanks in advance.

Post's attachments

Attachment icon linerenderer.png 828.55 kb, 5 downloads since 2022-09-23 

Re: Line Renderer Exact Position on the Map.

Hello.

When you have a huge number of markers, you need to help the map display them.
It can be clustering, segmentation or other ways.
The forum has an example of how to make the map work with a million markers at the same time.

I checked the Line Renderer and it works correctly on my side.
Screenshot attached. I manually moved the Drawing API line up so you can see they are in the same position.
Script used:

using UnityEngine;

public class TestLineRenderer:MonoBehaviour
{
    private static Vector2[] points =
    {
        new Vector2(0, 0),
        new Vector2(1, 1),
        new Vector2(2, -1),
        new Vector2(3, -2),
        new Vector2(3, 2),
    };

    private void Start()
    {
        OnlineMaps map = OnlineMaps.instance;

        LineRenderer lineRenderer = map.gameObject.AddComponent<LineRenderer>();
        lineRenderer.useWorldSpace = true;
        lineRenderer.startColor = lineRenderer.endColor = Color.blue;
        lineRenderer.positionCount = points.Length;
        lineRenderer.startWidth = 2.0f;
        lineRenderer.endWidth = 2.0f;

        for (int i = 0; i < points.Length; i++)
        {
            Vector3 p = OnlineMapsTileSetControl.instance.GetWorldPosition(points[i].x, points[i].y);
            lineRenderer.SetPosition(i, new Vector3(p.x, 1, p.z));

        }

        OnlineMapsDrawingLine line = new OnlineMapsDrawingLine(points, Color.red, 3);
        OnlineMapsDrawingElementManager.AddItem(line);
    }
}
Post's attachments

Attachment icon img1.png 338.73 kb, 5 downloads since 2022-09-24 

Kind Regards,
Infinity Code Team.

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

Re: Line Renderer Exact Position on the Map.

Hi Alex, thanks for the prompt reply.
Yes, the LineRenderer is working fine, but the line is placed far away from the map original position in scene (0,0,0). After converting the coords (long,lat) to vector2 I've got the x,y position looking like this:

    private static Vector2[] points =
    {
        new Vector2(108159.1, -926569.9),
        new Vector2(108166.1, -926568.6),
        new Vector2(108178, -926564.8),
        new Vector2(108190.1, -926559.8),
        new Vector2(108198.7, -926555.1),
         ...
    };

Am I missing some conversion method to be applied, so the lines can be rendered excatly on the map?

Thanks for your attention.

Paulo

Re: Line Renderer Exact Position on the Map.

Unfortunately, it's hard for me to say what's wrong in your case.
I have a premonition that this is something very simple and not directly related to the map.

If you send me your project by email (support@infinity-code.com), I will check it and give you advice on how to fix it.
To make it clear:
I don't need your work project.
Any temporary project where the problem will occur is enough for me.

Kind Regards,
Infinity Code Team.

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

Re: Line Renderer Exact Position on the Map.

Hi Alex, thank you very much. Package sent to the email indicated above.

Re: Line Renderer Exact Position on the Map.

Thank you Alex,

For those who are interested in the solution is everything related to the parser by just adding OnlineMapsUtils.numberFormat when parsing to float:

foreach (Waypoints tracks_ in _waypoints.points)
        {
            //Debug.Log("lat: " + tracks_.longitude + " Long:" + tracks_.latitude);

            float longx = float.Parse(tracks_.longitude, OnlineMapsUtils.numberFormat);
            float laty = float.Parse(tracks_.latitude, OnlineMapsUtils.numberFormat);
            string name = tracks_.stageId;

            linepoints.Add(new Vector2 (longx, laty));
        }