Topic: Draw Line from GPX

Hi Alex,

Am having trouble drawing a line on a tileset map from points in a GPX file. File is parsed fine, I pass the

OnlineMapsGPXObject.TrackSegment.points

into

OnlineMapsDrawingLine

and I even get a

true

returned for

path.visible

but there remains no line drawn across the tileset? Here's the code I'm using ...

if(File.Exists(pathToGPX))
        {
            // Load data from file into string
            string data = File.ReadAllText(pathToGPX, Encoding.UTF8);

            // Attempt to load data as GPX object
            gpx = OnlineMapsGPXObject.Load(data);

            foreach(OnlineMapsGPXObject.Track route in gpx.tracks)
            {
                Debug.LogFormat("Bike Track - {0}",route.name);
                foreach(OnlineMapsGPXObject.TrackSegment segment in route.segments)
                {
                    Debug.LogFormat("Route {0}, points {1}",route.name,segment.points.ToString());

                    for(int i=0; i<segment.points.Count;i++) Debug.LogFormat("Waypoint - {0},{1}",segment.points[i].lat, segment.points[i].lon);

                    OnlineMapsDrawingLine path = new OnlineMapsDrawingLine(segment.points, Color.red);

                    api.AddDrawingElement(path);
//                    api.Redraw();

                    Debug.Log("path is visible?? "+path.visible);
                }

Am I missing something really obvious / stupid??  Help please ;-)

Re: Draw Line from GPX

Ok, so found out what was going on so thought I'd post here in case its of use to anyone else -- The points in the GPX file are stored as {lat,long} but the list of Vectors required for OnlineMapsDrawingLine need to be {long,lat} ;-)

Re: Draw Line from GPX

Hello.

segment.points - is List <OnlineMapsGPXObject.Waypoint>.
OnlineMapsDrawingLine uses IEnumerable, where elements is Vector2, float or double.

The correct way:

OnlineMaps.instance.AddDrawingElement(new OnlineMapsDrawingLine(segment.points.Select(p => new Vector2((float)p.lon, (float)p.lat)), Color.red));

or

OnlineMaps.instance.AddDrawingElement(new OnlineMapsDrawingLine(segment.points.SelectMany(p => new [] {p.lon, p.lat}), Color.red));
Kind Regards,
Infinity Code Team.

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

4 (edited by nigel.moore 2016-09-15 12:39:28)

Re: Draw Line from GPX

Thanks Alex, sorted it now :-)

I am trying to capture user interaction (clicks initially) along the line that's being drawn and get some information back such as name of line and location along the path - is this possible? Also I can't seem to implement a tooltip for a line either, is this also possible?

Thanks

Re: Draw Line from GPX

Hello.

In the current version - no, the line has not HitTest method, and all events and tooltips will be ignored.
If you really need events for the line, we can try to implement it.

Kind Regards,
Infinity Code Team.

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

Re: Draw Line from GPX

Thanks for the reply. It would be really really great if this functionality could be implemented smile

Re: Draw Line from GPX

Hello.

We have implemented this feature, and the next update (v2.5.0.8 beta, will be available this week through the built-in update system) will contain it.

Kind Regards,
Infinity Code Team.

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

Re: Draw Line from GPX

Wow, excellent thanks :-)