Custom Rendering and GPX Tracks

338 views
Skip to first unread message

EotS

unread,
Jan 30, 2017, 7:34:43 PM1/30/17
to Osmand
I have read everything I can in this group regarding custom rendering, but I'm not finding how I would do this for my application.

I have two different GPX tracks that I'm always building on as I add or discover new trails.

Their names are:
DNR-v4.5.gpx
ShortcutsAndOffTrail-v2.1


As you see, I keep version control on them.

How do I tell the custom renderer to always color DNR blue?  Can I use a wildcard so it'll always color DNR-v*** blue regardless of version, or should I just stop using version control on the osmand gpx files?

Also, I would like my tracks in ShortcutsAndOffTrail to be red dashed lines.

Can someone post some code to show me how to do this?

Thanks!

P Wat

unread,
Jan 31, 2017, 3:34:50 AM1/31/17
to Osmand
Hi EotS. You might find a solution here https://groups.google.com/forum/#!topic/osmand/LnR2qaM9Jg0 .
Jan van Bekkum's code can be adapted to display alternative styles of line/colour, etc.
Paul W

David

unread,
Feb 6, 2017, 6:27:00 PM2/6/17
to Osmand
Osmand will follow the collor code in the gpx file, just add the apropriate code to the file, at least it works for me in gpx files with only placemarks in it.
David

P Wat

unread,
Feb 11, 2017, 3:16:12 PM2/11/17
to Osmand
David
That sounds good - Please explain how (to this IT-capable non-coder) to do it.
Thanks
Paul W

Harry van der Wolf

unread,
Feb 12, 2017, 7:48:40 AM2/12/17
to osmand
Are you sure about this?
EotS wants to display his DNR track in blue and his Shortcuts track in red. When you define a custom render for your gpx tracks, it will render all tracks in the same color/format. AFAIK you can't differentiate between separate tracks in one view.

Harry

--
You received this message because you are subscribed to the Google Groups "Osmand" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osmand+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

P Wat

unread,
Feb 12, 2017, 9:51:57 AM2/12/17
to Osmand
Hi Harry
Thanks for chipping in.
You're absolutely correct. If that's how it works, I don't need it.
When I need different coloured tracks I'll use ViewRanger.  It is easy there, (but not nearly so good in most other respcts, of course!)
ATB
Paul W

nickjoh...@gmail.com

unread,
Feb 17, 2017, 6:57:06 AM2/17/17
to Osmand
Hi Paul,

As David says, OsmAnd can display GPX tracks and routes using a colour specified in the GPX file itself.

This is useful as you don't need to keep selecting your desired colour when you display the file in OsmAnd.

To do this:

1. Open a GPX file in a text editor (such as Notepad) on your computer.
2. The file will start with something like this:

<?xml version="1.0"?>
<gpx creator="GPS Visualizer http://www.gpsvisualizer.com/" version="1.0" xmlns="http://www.topografix.com/GPX/1/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">

After the <gpx> tag, or after the <metadata> tag if it exists, insert this:

<extensions>
  <color>#BBF5F532</color>
</extensions>

3. As you can see, the colour is specified inside the <color> tag. Use one of the many online colour picking tools such as http://html-color-codes.info/ to get the code for your colour and edit appropriately.

*However*, take note--by default, the colour won't be transparent, so the rendered track in OsmAnd will be opaque and will obscure details beneath it. To do this, you specify an alpha value for the colour--that's the BB in the example above. That's about 50% transparent (it's in hex, so it ranges from 00 which is opaque to FF which is fully transparent).

To be clear, let's say you pick #31F642 (light green) as your colour. You would change this to #BB31F642 (i.e. add BB at the start) to make the track appear semi-transparent in OsmAnd.

4. Copy the updated track to your phone. If the track is currently displayed, untick it from My Places and then re-add it.

Good luck,

Nick

EotS

unread,
Feb 17, 2017, 4:43:53 PM2/17/17
to Osmand
That seems strange.  You can have several different tracks as separate files, and then you can go to "my places" and color each of them.  The only problem is, it loses the colors anytime one of the files is updated.

It seems as though you should be able to color each track how you wish (and better yet, make some of them dashed or dotted lines.)  Can someone chime in and let me know if this is even possible?


On Sunday, February 12, 2017 at 7:48:40 AM UTC-5, Harry van der Wolf wrote:
Are you sure about this?
EotS wants to display his DNR track in blue and his Shortcuts track in red. When you define a custom render for your gpx tracks, it will render all tracks in the same color/format. AFAIK you can't differentiate between separate tracks in one view.

Harry
2017-02-11 21:16 GMT+01:00 'P Wat' via Osmand <osm...@googlegroups.com>:
David
That sounds good - Please explain how (to this IT-capable non-coder) to do it.
Thanks
Paul W

--
You received this message because you are subscribed to the Google Groups "Osmand" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osmand+un...@googlegroups.com.

EotS

unread,
Feb 17, 2017, 4:51:45 PM2/17/17
to Osmand
Ah, thanks nickjob - I hadn't refreshed the page before my last reply.  I'll give your approach a try.  Is it your understanding that each separate gpx file can have it's own color specified?  And can I specify the line to be dotted or dashed?

EotS

unread,
Feb 17, 2017, 6:25:50 PM2/17/17
to Osmand
Update:  Thanks to nickjob's excellent instructions, I was able to successfully color the different gpx files.  So the answer is yes, as long as they're separate gpx files, you can have multiple colors for your tracks.  Very easy trick, thanks!
Now, the next question is can I create dashed and dotted lines?  I'm doing some digging, and I've found some code that I can use for Androids - the snippet I'm studying looks like this:

 <shape
       android:shape="line" >
       <stroke
           android:dashGap="1dp"
           android:dashWidth="1.5dp"
           android:width="1dp"
           android:color="#FFcdcdcd" />

            <size android:height="2dp" />

    </shape>

I'm going to see if I can adapt this to osmand with some trial and error.  If anyone has some guidance, it would be much appreciated!



P Wat

unread,
Feb 17, 2017, 6:34:18 PM2/17/17
to Osmand
Hi EotS
You might find something useful here https://groups.google.com/d/topic/osmand/LnR2qaM9Jg0/discussion . (Jan Van Bekkum's code).
It definitely works for creating a dotted route line.  I use it now for almost all land-based routes.
Let us know if it works for tracks.
Paul W

EotS

unread,
Feb 17, 2017, 7:06:14 PM2/17/17
to Osmand
Thanks, I was reading that thread on your earlier mention of it.  It uses the custom rendering approach, and I never did get that to work.

Using nickjob's simple approach, I was able to simply add color to the gpx file directly, and it worked easily.  I was hoping I could do the same thing for a dashed or dotted line.

I did find the pathEffect value.  I tried adding it right into the gpx file extensions section as:

<pathEffect>5_5_2_2</pathEffect>


 But it does not work that way.

nickjoh...@gmail.com

unread,
Feb 18, 2017, 11:50:13 AM2/18/17
to Osmand
Hi,

Glad you found the instructions useful.

Unfortunately, I don't think you can customise the line thickness or style in the GPX file itself. OsmAnd doesn't support it.

As per the code (see https://github.com/osmandapp/Osmand/blob/61aaf7146e50b983831da7e2c1c496a402e2fbf3/OsmAnd/src/net/osmand/plus/GPXUtilities.java), the only item currently supported in <extensions> is <color>.

I don't think it would be too hard to add another item in there to specify the thickness and/or style.

Nick
Message has been deleted

EotS

unread,
Feb 21, 2017, 12:19:55 PM2/21/17
to Osmand
I'm trying to use the renderer now, but I cannot find any documentation showing how the tags and values used in the renderer correspond to the fields in the gpx files.

Can anyone point me to a gpx modifiying example that shows both the gpx file and the renderer, so I can see this?   

Mirco Zorzo

unread,
Mar 2, 2017, 2:42:33 AM3/2/17
to Osmand
Nice thread, like it.
Reply all
Reply to author
Forward
0 new messages