add GeoJSON track format
This commit is contained in:
parent
3f49938e2a
commit
76c1641899
2 changed files with 46 additions and 1 deletions
|
@ -286,6 +286,43 @@ public final class OsmTrack
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
public String formatAsGeoJson()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(8192);
|
||||
|
||||
sb.append( "{\n" );
|
||||
sb.append( " \"type\": \"FeatureCollection\",\n" );
|
||||
sb.append( " \"features\": [\n" );
|
||||
sb.append( " {\n" );
|
||||
sb.append( " \"type\": \"Feature\",\n" );
|
||||
sb.append( " \"properties\": {\n" );
|
||||
sb.append( " \"creator\": \"BRouter-1.0.2\",\n" );
|
||||
sb.append( " \"name\": \"" ).append( name ).append( "\",\n" );
|
||||
sb.append( " \"track-length\": \"" ).append( distance ).append( "\",\n" );
|
||||
sb.append( " \"filtered ascend\": \"" ).append( ascend ).append( "\",\n" );
|
||||
sb.append( " \"plain-ascend\": \"" ).append( plainAscend ).append( "\",\n" );
|
||||
sb.append( " \"cost\": \"" ).append( cost ).append( "\"\n" );
|
||||
sb.append( " },\n" );
|
||||
sb.append( " \"geometry\": {\n" );
|
||||
sb.append( " \"type\": \"LineString\",\n" );
|
||||
sb.append( " \"coordinates\": [\n" );
|
||||
|
||||
for( OsmPathElement n : nodes )
|
||||
{
|
||||
String sele = n.getSElev() == Short.MIN_VALUE ? "" : ", " + n.getElev();
|
||||
sb.append( " [" ).append(formatPos(n.getILon() - 180000000)).append(", ").append(formatPos(n.getILat() - 90000000)).append(sele).append( "],\n" );
|
||||
}
|
||||
sb.deleteCharAt( sb.lastIndexOf( "," ) );
|
||||
|
||||
sb.append( " ]\n" );
|
||||
sb.append( " }\n" );
|
||||
sb.append( " }\n" );
|
||||
sb.append( " ]\n" );
|
||||
sb.append( "}\n" );
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String formatPos( int p )
|
||||
{
|
||||
boolean negative = p < 0;
|
||||
|
|
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||
* nogos = lon,lat,radius|... (optional, radius in meters)
|
||||
* profile = profile file name without .brf
|
||||
* alternativeidx = [0|1|2|3] (optional, default 0)
|
||||
* format = [kml|gpx] (optional, default gpx)
|
||||
* format = [kml|gpx|geojson] (optional, default gpx)
|
||||
*
|
||||
* Example URLs:
|
||||
* http://localhost:17777/brouter?lonlats=8.799297,49.565883|8.811764,49.563606&nogos=&profile=trekking&alternativeidx=0&format=gpx
|
||||
|
@ -100,6 +100,10 @@ public class ServerHandler extends RequestHandler {
|
|||
else if ("kml".equals(format))
|
||||
{
|
||||
result = track.formatAsKml();
|
||||
}
|
||||
else if ("geojson".equals(format))
|
||||
{
|
||||
result = track.formatAsGeoJson();
|
||||
}
|
||||
else if ("csv".equals(format))
|
||||
{
|
||||
|
@ -141,6 +145,10 @@ public class ServerHandler extends RequestHandler {
|
|||
{
|
||||
result = "application/vnd.google-earth.kml+xml";
|
||||
}
|
||||
else if ( "geojson".equals( format ) )
|
||||
{
|
||||
result = "application/vnd.geo+json";
|
||||
}
|
||||
else if ( "csv".equals( format ) )
|
||||
{
|
||||
result = "text/tab-separated-values";
|
||||
|
|
Loading…
Reference in a new issue