Topic: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

So my app has to draw line behind a marker when the marker is constantly moving, so new points are added to the line segments, I'm currently using

lineSegment?.Dispose();
lineSegment?.DestroyInstance();
lineSegment = new OnlineMapsDrawingLine(listPoints, Color.red, 2); 

and every time the function call is happens so i get new points and draw new lines from scratch, I'm guess I've done something horribly wrong here cause the garbage collection is through the roof, is there a better way to handle the addition of new points in an existing line segment or how to handle this scenario, I'm using online maps v3 can provide more details if necessary.

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

Hi.

In Online Maps v3, the line keeps a reference to the original list, and you don't need to constantly destroy and recreate the line.
The map will automatically see the changes.
You only need to cause the map to redraw.

In Online Maps v4, for performance reasons, the line no longer keeps a reference to the original list, and you need to call the SetPoints method when points change.

Kind Regards,
Infinity Code Team.

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

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

Thanks for the help, its working now, thank again have a nice day

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

@Alex Vertax https://forum.infinity-code.com/viewtop … 9837#p9837 thanks for the solution it works nice, i ran a test by making the app run for like 8hours, the vertex count went up to 89k (line points passed 35k) the apps FPS dropped after this from 30fps to 10fps, but when i disabled the OnlineMapsDrawingElementManager script the fps climbed back up(not the lines), is there any optimization that i can do for this kind of drops ?

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

Drawing API is very heavy, and if you have 35k points, you need to help the map.
For example, you can optimize the points in your list by removing those that are on the same line or the distance between them is less than some threshold.
You can also divide the line into chunks (e.g. 100 points each), calculate the chunk's bounding box, and if it does not overlap with the map, disable the drawing element.

Kind Regards,
Infinity Code Team.

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

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

Thanks for the update, will look into you suggestion.

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

@Alex so follow up on this topic, now I'm trying to make the lines as a static mesh once it goes beyond some threshold and maintaining only the given threshold as points instead of 10000s of entries and instantiate into a 3d marker, but i'm facing some other issue, when i instantiate into a 3d marker the size at which it initializes changes and when i'm zooming in and out the size varies widely, somehow i tried to adjust it by using marker.sizeType = OnlineMapsMarker3D.SizeType.realWorld; but still i.e when the map is zoomed in or zoomed out while instantiating is spawns with different scale, is there a build in way to spawn the object with same size or do i have to calculate the zoom value and then manipulate the scale ?

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

Please show me your code. I'll check it out.

Kind Regards,
Infinity Code Team.

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

9 (edited by culkinnivas.sekar 2025-07-04 05:07:18)

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

I've attached the code for the following, pardon my haphazard code, i am still testing different iterations, in the script the function DrawRedLine() is what used to draw the trail of the object attached, and when the segmentsThreshold value is reached it will try to make a mesh out of the points it gathers and then resets the dronePathPoints for new lines meanwhile the newly created mesh is put as a gameobject and marked as marker in CreateOrUpdateMarker() function, my question is related to this function where I'm using OnlineMapsMarker3DManager.CreateItemFromExistGameObject(centerLatLon.x, centerLatLon.y, meshObject); to mark it as a marker and it does it properly but when i zoom in or out while the marker is being created it scale changes, it might be the problem how i create the mesh itself.




PS as i was typing this i figured the line was already drawn as a mesh i could use that to create a marker than a new gameobject, ill try figuring it out

Post's attachments

Attachment icon DrawTrailOfDrone.cs 16.17 kb, 7 downloads since 2025-07-04 

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

When marker3D.sizeType == OnlineMapsMarker3D.SizeType.realWorld, transform.scale is Vector3.one at zoom 20, and decreases by half for each previous zoom level.
In your CreateOrUpdateMarker method, you need to calculate and set marker.scale.
Something like:

marker.scale = (1 << (20 - map.zoom)) / map.zoomFactor;

P.S. This is theoretical code that I wrote directly on the forum, and I haven't tested it.

Kind Regards,
Infinity Code Team.

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

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

@Alex, I understand the part you explained, but my issue is kind of different. The problem seems to be when I draw the recreate the mesh after the threshold is met. Since it's a 2D map, zooming in or out affects the mesh line width—even though I use the same logic "width logic with zoom factor" for creating the mesh.

If i was not clear ill write it down here,
1. how to hijack the logic of how the line is drawn/works in correlation of map to leverage the same for the mesh I'm creating?
or 2. how to get the line mesh data without the zoom value interfering (cause i dont know how the line is behaving when the map zoom is happening)?
or 3. how should i approach this scenario of optimization of more points on the map, cause the data is crucial for future ?

I've attached a sample showing how the output varies at different zoom levels. Let me know if I should clarify further.

Post's attachments

Attachment icon Screenshot 2025-07-07 123847.png 1.59 mb, 1 downloads since 2025-07-07 

Re: Drawing lines using "OnlineMapsDrawingLine" constantly how to handle ?

Please check the attached scripts.
This is probably the fastest way of drawing lines that I can do.

P.S. This method kicks out all the slow things, optimizing the drawing to the max.
If you need clipping outside the map, implement it with a shader.

Post's attachments

Attachment icon FastLineDrawer.cs 8.4 kb, 5 downloads since 2025-07-08 

Attachment icon TestFastLineDrawer.cs 1.07 kb, 5 downloads since 2025-07-08 

Kind Regards,
Infinity Code Team.

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