Complete voice hints and add times to GeoJSON
This commit is contained in:
parent
1e542d19b7
commit
3565f39914
1 changed files with 36 additions and 3 deletions
|
@ -19,8 +19,11 @@ import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import btools.mapaccess.MatchedWaypoint;
|
import btools.mapaccess.MatchedWaypoint;
|
||||||
import btools.mapaccess.OsmPos;
|
import btools.mapaccess.OsmPos;
|
||||||
|
@ -710,6 +713,8 @@ public final class OsmTrack
|
||||||
|
|
||||||
public String formatAsGeoJson()
|
public String formatAsGeoJson()
|
||||||
{
|
{
|
||||||
|
int turnInstructionMode = voiceHints != null ? voiceHints.turnInstructionMode : 0;
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder( 8192 );
|
StringBuilder sb = new StringBuilder( 8192 );
|
||||||
|
|
||||||
sb.append( "{\n" );
|
sb.append( "{\n" );
|
||||||
|
@ -731,7 +736,20 @@ public final class OsmTrack
|
||||||
sb.append( " \"voicehints\": [\n" );
|
sb.append( " \"voicehints\": [\n" );
|
||||||
for( VoiceHint hint: voiceHints.list )
|
for( VoiceHint hint: voiceHints.list )
|
||||||
{
|
{
|
||||||
sb.append( " [" ).append( hint.indexInTrack ).append( ',' ).append( hint.getCommand() ).append( ',' ).append( hint.getExitNumber() ).append( "],\n" );
|
sb.append( " [" );
|
||||||
|
sb.append( hint.indexInTrack );
|
||||||
|
sb.append( ',' ).append( hint.getCommand() );
|
||||||
|
sb.append( ',' ).append( hint.getExitNumber() );
|
||||||
|
sb.append( ',' ).append( hint.distanceToNext );
|
||||||
|
sb.append( ',' ).append( (int) hint.angle );
|
||||||
|
|
||||||
|
// not always include geometry because longer and only needed for comment style
|
||||||
|
if ( turnInstructionMode == 4 ) // comment style
|
||||||
|
{
|
||||||
|
sb.append( ",\"" ).append( hint.formatGeometry() ).append( "\"" );
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append( "],\n" );
|
||||||
}
|
}
|
||||||
sb.deleteCharAt( sb.lastIndexOf( "," ) );
|
sb.deleteCharAt( sb.lastIndexOf( "," ) );
|
||||||
sb.append( " ],\n" );
|
sb.append( " ],\n" );
|
||||||
|
@ -746,7 +764,7 @@ public final class OsmTrack
|
||||||
{
|
{
|
||||||
sb.append( " [" ).append( sp.get(i) ).append( i> 0 ? "],\n" : "]\n" );
|
sb.append( " [" ).append( sp.get(i) ).append( i> 0 ? "],\n" : "]\n" );
|
||||||
}
|
}
|
||||||
sb.append( " ]\n" );
|
sb.append( " ],\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // ... otherwise traditional message list
|
else // ... otherwise traditional message list
|
||||||
|
@ -758,9 +776,24 @@ public final class OsmTrack
|
||||||
sb.append( " [\"" ).append( m.replaceAll( "\t", "\", \"" ) ).append( "\"],\n" );
|
sb.append( " [\"" ).append( m.replaceAll( "\t", "\", \"" ) ).append( "\"],\n" );
|
||||||
}
|
}
|
||||||
sb.deleteCharAt( sb.lastIndexOf( "," ) );
|
sb.deleteCharAt( sb.lastIndexOf( "," ) );
|
||||||
sb.append( " ]\n" );
|
sb.append( " ],\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( getTotalSeconds() > 0 ) {
|
||||||
|
sb.append( " \"times\": [" );
|
||||||
|
DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance( Locale.ENGLISH );
|
||||||
|
decimalFormat.applyPattern( "0.###" );
|
||||||
|
for ( OsmPathElement n : nodes ) {
|
||||||
|
sb.append( decimalFormat.format( n.getTime() ) ).append( "," );
|
||||||
|
}
|
||||||
|
sb.deleteCharAt( sb.lastIndexOf( "," ) );
|
||||||
|
sb.append( "]\n" );
|
||||||
|
} else {
|
||||||
|
sb.deleteCharAt( sb.lastIndexOf( "," ) );
|
||||||
|
}
|
||||||
|
|
||||||
sb.append( " },\n" );
|
sb.append( " },\n" );
|
||||||
|
|
||||||
if ( iternity != null )
|
if ( iternity != null )
|
||||||
{
|
{
|
||||||
sb.append( " \"iternity\": [\n" );
|
sb.append( " \"iternity\": [\n" );
|
||||||
|
|
Loading…
Reference in a new issue