Say I have multiple arrays of points. How can I draw them all with minimal code?

Lets say I have two arrays forming an array themself in json form in resources.xml:

[[array1],[array2]]

Lets say array 1 represents a path and array 2 represents a different slightly longer path, they are not connected to each other.

As you move along the paths they move relative to your position. 

Now lets say I have more than just two arrays, maybe there’s ten or twenty. I cannot use separate code for each array as that takes up space in the code. Is there a way to draw multiple arrays of coordinates at once relative to your position using minimal code without connecting them into one array?

  • Either do a cycle over the arrays, and draw each path from the beginning to the end, then do the same to the next path,...

    Or do 2 nested loops:

    var i = 0;

    var hadDrawn = true;

    while (hadDrawn) {

        hadDrawn = false:

        for (path in paths) {

            if (path.size() > i) {

                draw(path[i]);

                hadDrawn = true;

             }

        }

        i++;

    }

  • Thanks, I can convert them like this yes?

    (Code to convert geographical coords to screen coords and adjust them to your position)

    save the converted points to an array

    (for loop){

    var array= arr.add(converted points)
    }


    var path = array

    correct?

  • You'll have an imaginary box on your screen with a x, y, width and height and the upper left corner, you set what it's lat and on is, and the same with the lower right corner.  As you go through your array, you use the locations of upper left, lowere right, and what you want to plot, along with the width and height of the box, to calculate where that point is on the screen in screen coordinates.

    Here's an app of mine that draws breadcrumb trails, based on an array of lat/lon locations that does just that.

    https://apps.garmin.com/en-US/apps/d741d7b4-8b26-401c-a5bd-0ac91891575d

    I also do about the same in Hike2+ for devices without MapTrackView. 

    https://apps.garmin.com/en-US/apps/116a5b59-29ae-4397-a70e-907d7e5f8e44

    With Chart I save a lat/lon every minute and if memory permits, I save up to 600 locations,  before I start reusing some memory.  And something I learned when I wrote it, is drawing the 600 points would trip the watchdog timer, so I walk the array to draw 200 points at most.  If I have 200 I draw each, 201-400, every other one, 401-600, every 3rd one, 

  • Lovely jubbly, thankyou for the information and the tip about the watchdog, I may limit what I draw to a certain area within my location, I plan to organise the arrays by location using scratch code i’ve made.