Handle user points of interest
This commit is contained in:
parent
dbf1479da4
commit
e2d2f6a23d
5 changed files with 150 additions and 83 deletions
|
@ -37,5 +37,10 @@
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-text</artifactId>
|
||||||
|
<version>1.8</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -26,6 +26,7 @@ import btools.mapaccess.MatchedWaypoint;
|
||||||
import btools.mapaccess.OsmPos;
|
import btools.mapaccess.OsmPos;
|
||||||
import btools.util.CompactLongMap;
|
import btools.util.CompactLongMap;
|
||||||
import btools.util.FrozenLongMap;
|
import btools.util.FrozenLongMap;
|
||||||
|
import org.apache.commons.text.StringEscapeUtils;
|
||||||
|
|
||||||
public final class OsmTrack
|
public final class OsmTrack
|
||||||
{
|
{
|
||||||
|
@ -39,6 +40,8 @@ public final class OsmTrack
|
||||||
|
|
||||||
public boolean showspeed;
|
public boolean showspeed;
|
||||||
|
|
||||||
|
public List<OsmNodeNamed> pois = new ArrayList<OsmNodeNamed>();
|
||||||
|
|
||||||
private static class OsmPathElementHolder
|
private static class OsmPathElementHolder
|
||||||
{
|
{
|
||||||
public OsmPathElement node;
|
public OsmPathElement node;
|
||||||
|
@ -534,13 +537,23 @@ public final class OsmTrack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for( int i=0; i<=pois.size() - 1; i++ )
|
||||||
|
{
|
||||||
|
OsmNodeNamed poi = pois.get(i);
|
||||||
|
sb.append( " <wpt lon=\"" ).append( formatILon( poi.ilon ) ).append( "\" lat=\"" )
|
||||||
|
.append( formatILat( poi.ilat ) ).append( "\">\n" )
|
||||||
|
.append( " <name>" ).append( StringEscapeUtils.escapeXml10(poi.name) ).append( "</name>\n" )
|
||||||
|
.append( " </wpt>\n" );
|
||||||
|
}
|
||||||
|
|
||||||
if ( exportWaypoints )
|
if ( exportWaypoints )
|
||||||
{
|
{
|
||||||
for( int i=0; i<=matchedWaypoints.size() - 1; i++ )
|
for( int i=0; i<=matchedWaypoints.size() - 1; i++ )
|
||||||
{
|
{
|
||||||
sb.append( " <wpt lon=\"" ).append( formatILon( matchedWaypoints.get(i).waypoint.ilon ) ).append( "\" lat=\"" )
|
MatchedWaypoint wt = matchedWaypoints.get(i);
|
||||||
.append( formatILat( matchedWaypoints.get(i).waypoint.ilat ) ).append( "\">\n" )
|
sb.append( " <wpt lon=\"" ).append( formatILon( wt.waypoint.ilon ) ).append( "\" lat=\"" )
|
||||||
.append( " <name>" ).append( matchedWaypoints.get(i).name ).append( "</name>\n" );
|
.append( formatILat( wt.waypoint.ilat ) ).append( "\">\n" )
|
||||||
|
.append( " <name>" ).append( StringEscapeUtils.escapeXml10(wt.name) ).append( "</name>\n" );
|
||||||
if(i == 0)
|
if(i == 0)
|
||||||
{
|
{
|
||||||
sb.append( " <type>from</type>\n" );
|
sb.append( " <type>from</type>\n" );
|
||||||
|
@ -637,40 +650,27 @@ public final class OsmTrack
|
||||||
sb.append( " </LineString>\n" );
|
sb.append( " </LineString>\n" );
|
||||||
sb.append( " </Placemark>\n" );
|
sb.append( " </Placemark>\n" );
|
||||||
sb.append( " </Folder>\n" );
|
sb.append( " </Folder>\n" );
|
||||||
if ( exportWaypoints )
|
if ( exportWaypoints || !pois.isEmpty() )
|
||||||
{
|
{
|
||||||
|
if (!pois.isEmpty()) {
|
||||||
sb.append( " <Folder>\n" );
|
sb.append( " <Folder>\n" );
|
||||||
sb.append( " <name>start</name>\n" );
|
sb.append(" <name>poi</name>\n");
|
||||||
sb.append( " <Placemark>\n" );
|
for (int i = 0; i < pois.size(); i++) {
|
||||||
sb.append( " <name> " + matchedWaypoints.get(0).name + "</name>\n" );
|
OsmNodeNamed poi = pois.get(i);
|
||||||
sb.append( " <Point>\n" );
|
createPlaceMark(sb, poi.name, poi.ilat, poi.ilon);
|
||||||
sb.append( " <coordinates>" + formatILon(matchedWaypoints.get(0).waypoint.ilon) + "," + formatILat(matchedWaypoints.get(0).waypoint.ilat) + "</coordinates>\n" );
|
|
||||||
sb.append( " </Point>\n" );
|
|
||||||
sb.append( " </Placemark>\n" );
|
|
||||||
sb.append( " </Folder>\n" );
|
|
||||||
if (matchedWaypoints.size() > 2) {
|
|
||||||
sb.append( " <Folder>\n" );
|
|
||||||
sb.append( " <name>via</name>\n" );
|
|
||||||
for( int i=1; i<=matchedWaypoints.size() - 2; i++ )
|
|
||||||
{
|
|
||||||
sb.append( " <Placemark>\n" );
|
|
||||||
sb.append( " <name> " + matchedWaypoints.get(i).name + "</name>\n" );
|
|
||||||
sb.append( " <Point>\n" );
|
|
||||||
sb.append( " <coordinates>" + formatILon(matchedWaypoints.get(i).waypoint.ilon) + "," + formatILat(matchedWaypoints.get(i).waypoint.ilat) + "</coordinates>\n" );
|
|
||||||
sb.append( " </Point>\n" );
|
|
||||||
sb.append( " </Placemark>\n" );
|
|
||||||
}
|
|
||||||
sb.append( " </Folder>\n" );
|
|
||||||
}
|
}
|
||||||
sb.append( " <Folder>\n" );
|
sb.append(" </Folder>\n");
|
||||||
sb.append( " <name>end</name>\n" );
|
}
|
||||||
sb.append( " <Placemark>\n" );
|
|
||||||
sb.append( " <name> " + matchedWaypoints.get(matchedWaypoints.size() - 1).name + "</name>\n" );
|
if (exportWaypoints)
|
||||||
sb.append( " <Point>\n" );
|
{
|
||||||
sb.append( " <coordinates>" + formatILon(matchedWaypoints.get(matchedWaypoints.size() - 1).waypoint.ilon) + "," + formatILat(matchedWaypoints.get(matchedWaypoints.size() - 1).waypoint.ilat) + "</coordinates>\n" );
|
int size = matchedWaypoints.size();
|
||||||
sb.append( " </Point>\n" );
|
createFolder(sb, "start", matchedWaypoints.subList(0, 1));
|
||||||
sb.append( " </Placemark>\n" );
|
if (matchedWaypoints.size() > 2) {
|
||||||
sb.append( " </Folder>\n" );
|
createFolder(sb, "via", matchedWaypoints.subList(1, size - 1));
|
||||||
|
}
|
||||||
|
createFolder(sb, "end", matchedWaypoints.subList(size - 1, size));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sb.append( " </Document>\n" );
|
sb.append( " </Document>\n" );
|
||||||
sb.append( "</kml>\n" );
|
sb.append( "</kml>\n" );
|
||||||
|
@ -678,6 +678,25 @@ public final class OsmTrack
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createFolder(StringBuilder sb, String type, List<MatchedWaypoint> waypoints) {
|
||||||
|
sb.append( " <Folder>\n" );
|
||||||
|
sb.append( " <name>" + type + "</name>\n" );
|
||||||
|
for (int i = 0; i < waypoints.size(); i++) {
|
||||||
|
MatchedWaypoint wp = waypoints.get(i);
|
||||||
|
createPlaceMark(sb, wp.name, wp.waypoint.ilat, wp.waypoint.ilon);
|
||||||
|
}
|
||||||
|
sb.append( " </Folder>\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createPlaceMark(StringBuilder sb, String name, int ilat, int ilon) {
|
||||||
|
sb.append(" <Placemark>\n");
|
||||||
|
sb.append(" <name>" + StringEscapeUtils.escapeXml10(name) + "</name>\n");
|
||||||
|
sb.append(" <Point>\n");
|
||||||
|
sb.append(" <coordinates>" + formatILon(ilon) + "," + formatILat(ilat) + "</coordinates>\n");
|
||||||
|
sb.append(" </Point>\n");
|
||||||
|
sb.append(" </Placemark>\n");
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> iternity;
|
public List<String> iternity;
|
||||||
|
|
||||||
public String formatAsGeoJson()
|
public String formatAsGeoJson()
|
||||||
|
@ -773,45 +792,40 @@ public final class OsmTrack
|
||||||
|
|
||||||
sb.append( " ]\n" );
|
sb.append( " ]\n" );
|
||||||
sb.append( " }\n" );
|
sb.append( " }\n" );
|
||||||
if ( exportWaypoints )
|
if ( exportWaypoints || !pois.isEmpty())
|
||||||
{
|
{
|
||||||
sb.append( " },\n" );
|
sb.append( " },\n" );
|
||||||
for( int i=0; i<=matchedWaypoints.size() - 1; i++ )
|
for( int i=0; i<=pois.size() - 1; i++ )
|
||||||
{
|
{
|
||||||
sb.append( " {\n" );
|
OsmNodeNamed poi = pois.get(i);
|
||||||
sb.append( " \"type\": \"Feature\",\n" );
|
addFeature(sb, "poi", poi.name, poi.ilat, poi.ilon);
|
||||||
sb.append( " \"properties\": {\n" );
|
if (i < matchedWaypoints.size() - 1) {
|
||||||
sb.append( " \"name\": \"" + matchedWaypoints.get(i).name + "\",\n" );
|
sb.append(",");
|
||||||
if(i == 0)
|
|
||||||
{
|
|
||||||
sb.append( " \"type\": \"from\"\n" );
|
|
||||||
}
|
|
||||||
else if (i == matchedWaypoints.size() - 1)
|
|
||||||
{
|
|
||||||
sb.append( " \"type\": \"to\"\n" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sb.append( " \"type\": \"via\"\n" );
|
|
||||||
{
|
|
||||||
}
|
|
||||||
sb.append( " },\n" );
|
|
||||||
sb.append( " \"geometry\": {\n" );
|
|
||||||
sb.append( " \"type\": \"Point\",\n" );
|
|
||||||
sb.append( " \"coordinates\": [\n" );
|
|
||||||
sb.append( " " + formatILon(matchedWaypoints.get(i).waypoint.ilon) + ",\n" );
|
|
||||||
sb.append( " " + formatILat(matchedWaypoints.get(i).waypoint.ilat) + "\n" );
|
|
||||||
sb.append( " ]\n" );
|
|
||||||
sb.append( " }\n" );
|
|
||||||
if (i < matchedWaypoints.size() - 1) {
|
|
||||||
sb.append( " },\n" );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sb.append( " }\n" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
sb.append( " \n" );
|
||||||
|
}
|
||||||
|
if (exportWaypoints) {
|
||||||
|
for (int i = 0; i <= matchedWaypoints.size() - 1; i++) {
|
||||||
|
String type;
|
||||||
|
if (i == 0) {
|
||||||
|
type = "from";
|
||||||
|
} else if (i == matchedWaypoints.size() - 1) {
|
||||||
|
type = "to";
|
||||||
|
} else {
|
||||||
|
type = "via";
|
||||||
|
}
|
||||||
|
|
||||||
|
MatchedWaypoint wp = matchedWaypoints.get(i);
|
||||||
|
addFeature(sb, type, wp.name, wp.waypoint.ilat, wp.waypoint.ilon);
|
||||||
|
if (i < matchedWaypoints.size() - 1) {
|
||||||
|
sb.append(",");
|
||||||
|
}
|
||||||
|
sb.append(" \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sb.append( " }\n" );
|
sb.append( " }\n" );
|
||||||
}
|
}
|
||||||
sb.append( " ]\n" );
|
sb.append( " ]\n" );
|
||||||
sb.append( "}\n" );
|
sb.append( "}\n" );
|
||||||
|
@ -819,6 +833,23 @@ public final class OsmTrack
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addFeature(StringBuilder sb, String type, String name, int ilat, int ilon) {
|
||||||
|
sb.append( " {\n" );
|
||||||
|
sb.append( " \"type\": \"Feature\",\n" );
|
||||||
|
sb.append( " \"properties\": {\n" );
|
||||||
|
sb.append( " \"name\": \"" + StringEscapeUtils.escapeJson(name) + "\",\n" );
|
||||||
|
sb.append( " \"type\": \"" + type + "\"\n" );
|
||||||
|
sb.append( " },\n" );
|
||||||
|
sb.append( " \"geometry\": {\n" );
|
||||||
|
sb.append( " \"type\": \"Point\",\n" );
|
||||||
|
sb.append( " \"coordinates\": [\n" );
|
||||||
|
sb.append( " " + formatILon(ilon) + ",\n" );
|
||||||
|
sb.append( " " + formatILat(ilat) + "\n" );
|
||||||
|
sb.append( " ]\n" );
|
||||||
|
sb.append( " }\n" );
|
||||||
|
sb.append( " }" );
|
||||||
|
}
|
||||||
|
|
||||||
private int getVNode( int i )
|
private int getVNode( int i )
|
||||||
{
|
{
|
||||||
MessageData m1 = i+1 < nodes.size() ? nodes.get(i+1).message : null;
|
MessageData m1 = i+1 < nodes.size() ? nodes.get(i+1).message : null;
|
||||||
|
@ -841,18 +872,18 @@ public final class OsmTrack
|
||||||
|
|
||||||
public String getFormattedTime2()
|
public String getFormattedTime2()
|
||||||
{
|
{
|
||||||
int seconds = (int)(getTotalSeconds() + 0.5);
|
int seconds = (int)(getTotalSeconds() + 0.5);
|
||||||
int hours = seconds/3600;
|
int hours = seconds/3600;
|
||||||
int minutes = (seconds - hours * 3600) / 60;
|
int minutes = (seconds - hours * 3600) / 60;
|
||||||
seconds = seconds - hours * 3600 - minutes * 60;
|
seconds = seconds - hours * 3600 - minutes * 60;
|
||||||
String time = "";
|
String time = "";
|
||||||
if (hours != 0)
|
if (hours != 0)
|
||||||
time = "" + hours + "h ";
|
time = "" + hours + "h ";
|
||||||
if (minutes != 0)
|
if (minutes != 0)
|
||||||
time = time + minutes + "m ";
|
time = time + minutes + "m ";
|
||||||
if (seconds != 0)
|
if (seconds != 0)
|
||||||
time = time + seconds + "s";
|
time = time + seconds + "s";
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFormattedEnergy()
|
public String getFormattedEnergy()
|
||||||
|
|
|
@ -21,7 +21,7 @@ import btools.util.CheapRuler;
|
||||||
|
|
||||||
public final class RoutingContext
|
public final class RoutingContext
|
||||||
{
|
{
|
||||||
public void setAlternativeIdx( int idx )
|
public void setAlternativeIdx(int idx )
|
||||||
{
|
{
|
||||||
alternativeIdx = idx;
|
alternativeIdx = idx;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,8 @@ public final class RoutingContext
|
||||||
bikerPower = expctxGlobal.getVariableValue( "bikerPower", 100.f );
|
bikerPower = expctxGlobal.getVariableValue( "bikerPower", 100.f );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<OsmNodeNamed> poipoints;
|
||||||
|
|
||||||
public List<OsmNodeNamed> nogopoints = null;
|
public List<OsmNodeNamed> nogopoints = null;
|
||||||
private List<OsmNodeNamed> keepnogopoints = null;
|
private List<OsmNodeNamed> keepnogopoints = null;
|
||||||
|
|
||||||
|
|
|
@ -446,6 +446,7 @@ public class RoutingEngine extends Thread
|
||||||
totaltrack.appendTrack( seg );
|
totaltrack.appendTrack( seg );
|
||||||
lastTracks[i] = seg;
|
lastTracks[i] = seg;
|
||||||
}
|
}
|
||||||
|
if (routingContext.poipoints != null) totaltrack.pois = routingContext.poipoints;
|
||||||
totaltrack.matchedWaypoints = matchedWaypoints;
|
totaltrack.matchedWaypoints = matchedWaypoints;
|
||||||
return totaltrack;
|
return totaltrack;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package btools.server.request;
|
package btools.server.request;
|
||||||
|
|
||||||
|
import btools.mapaccess.OsmNode;
|
||||||
import btools.router.OsmNodeNamed;
|
import btools.router.OsmNodeNamed;
|
||||||
import btools.router.OsmNogoPolygon;
|
import btools.router.OsmNogoPolygon;
|
||||||
import btools.router.OsmTrack;
|
import btools.router.OsmTrack;
|
||||||
|
@ -25,10 +26,11 @@ import java.util.List;
|
||||||
* format = [kml|gpx|geojson] (optional, default gpx)
|
* format = [kml|gpx|geojson] (optional, default gpx)
|
||||||
* trackname = name used for filename and format specific trackname (optional, default brouter)
|
* trackname = name used for filename and format specific trackname (optional, default brouter)
|
||||||
* exportWaypoints = 1 to export them (optional, default is no export)
|
* exportWaypoints = 1 to export them (optional, default is no export)
|
||||||
|
* pois = lon,lat,name|... (optional)
|
||||||
*
|
*
|
||||||
* Example URLs:
|
* Example URLs:
|
||||||
* {@code http://localhost:17777/brouter?lonlats=8.799297,49.565883|8.811764,49.563606&nogos=&profile=trekking&alternativeidx=0&format=gpx}
|
* {@code http://localhost:17777/brouter?lonlats=8.799297,49.565883|8.811764,49.563606&nogos=&profile=trekking&alternativeidx=0&format=gpx}
|
||||||
* {@code http://localhost:17777/brouter?lonlats=1.1,1.2|2.1,2.2|3.1,3.2|4.1,4.2&nogos=-1.1,-1.2,1|-2.1,-2.2,2&profile=shortest&alternativeidx=1&format=kml&trackname=Ride}
|
* {@code http://localhost:17777/brouter?lonlats=1.1,1.2|2.1,2.2|3.1,3.2|4.1,4.2&nogos=-1.1,-1.2,1|-2.1,-2.2,2&profile=shortest&alternativeidx=1&format=kml&trackname=Ride&pois=1.1,2.1,Barner Bar}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ServerHandler extends RequestHandler {
|
public class ServerHandler extends RequestHandler {
|
||||||
|
@ -62,6 +64,9 @@ public class ServerHandler extends RequestHandler {
|
||||||
|
|
||||||
rc.setAlternativeIdx(Integer.parseInt(params.get( "alternativeidx" )));
|
rc.setAlternativeIdx(Integer.parseInt(params.get( "alternativeidx" )));
|
||||||
|
|
||||||
|
List<OsmNodeNamed> poisList = readPoisList();
|
||||||
|
rc.poipoints = poisList;
|
||||||
|
|
||||||
List<OsmNodeNamed> nogoList = readNogoList();
|
List<OsmNodeNamed> nogoList = readNogoList();
|
||||||
List<OsmNodeNamed> nogoPolygonsList = readNogoPolygons();
|
List<OsmNodeNamed> nogoPolygonsList = readNogoPolygons();
|
||||||
|
|
||||||
|
@ -226,6 +231,29 @@ public class ServerHandler extends RequestHandler {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<OsmNodeNamed> readPoisList()
|
||||||
|
{
|
||||||
|
// lon,lat,name|...
|
||||||
|
String pois = params.get( "pois" );
|
||||||
|
if ( pois == null ) return null;
|
||||||
|
|
||||||
|
String[] lonLatNameList = pois.split("\\|");
|
||||||
|
|
||||||
|
List<OsmNodeNamed> poisList = new ArrayList<OsmNodeNamed>();
|
||||||
|
for (int i = 0; i < lonLatNameList.length; i++)
|
||||||
|
{
|
||||||
|
String[] lonLatName = lonLatNameList[i].split(",");
|
||||||
|
|
||||||
|
OsmNodeNamed n = new OsmNodeNamed();
|
||||||
|
n.ilon = (int)( ( Double.parseDouble(lonLatName[0]) + 180. ) *1000000. + 0.5);
|
||||||
|
n.ilat = (int)( ( Double.parseDouble(lonLatName[1]) + 90. ) *1000000. + 0.5);
|
||||||
|
n.name = lonLatName[2];
|
||||||
|
poisList.add(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
return poisList;
|
||||||
|
}
|
||||||
|
|
||||||
private List<OsmNodeNamed> readNogoList()
|
private List<OsmNodeNamed> readNogoList()
|
||||||
{
|
{
|
||||||
// lon,lat,radius|...
|
// lon,lat,radius|...
|
||||||
|
|
Loading…
Reference in a new issue