24
24
import com .graphhopper .util .*;
25
25
import com .graphhopper .util .shapes .GHPoint ;
26
26
import java .util .ArrayList ;
27
+ import java .util .HashSet ;
27
28
28
29
import java .util .List ;
30
+ import java .util .Map .Entry ;
31
+ import java .util .Set ;
29
32
30
33
import org .json .JSONArray ;
31
34
import org .json .JSONObject ;
@@ -46,9 +49,28 @@ public class GraphHopperWeb implements GraphHopperAPI
46
49
private boolean instructions = true ;
47
50
private boolean calcPoints = true ;
48
51
private boolean elevation = false ;
52
+ private final Set <String > ignoreSet ;
49
53
50
54
public GraphHopperWeb ()
51
55
{
56
+ // some parameters are supported directly via Java API so ignore them when writing the getHints map
57
+ ignoreSet = new HashSet <String >();
58
+ ignoreSet .add ("calc_points" );
59
+ ignoreSet .add ("calcpoints" );
60
+ ignoreSet .add ("instructions" );
61
+ ignoreSet .add ("elevation" );
62
+ ignoreSet .add ("key" );
63
+
64
+ // some parameters are in the request:
65
+ ignoreSet .add ("algorithm" );
66
+ ignoreSet .add ("locale" );
67
+ ignoreSet .add ("point" );
68
+ ignoreSet .add ("vehicle" );
69
+
70
+ // some are special and need to be avoided
71
+ ignoreSet .add ("points_encoded" );
72
+ ignoreSet .add ("pointsencoded" );
73
+ ignoreSet .add ("type" );
52
74
}
53
75
54
76
public void setDownloader ( Downloader downloader )
@@ -109,7 +131,6 @@ public GHResponse route( GHRequest request )
109
131
+ "Use calcPoints=false and instructions=false to disable point and instruction calculation" );
110
132
111
133
boolean tmpElevation = request .getHints ().getBool ("elevation" , elevation );
112
- String tmpKey = request .getHints ().get ("key" , key );
113
134
114
135
String url = routeServiceUrl
115
136
+ "?"
@@ -125,12 +146,20 @@ public GHResponse route( GHRequest request )
125
146
if (!request .getVehicle ().isEmpty ())
126
147
url += "&vehicle=" + request .getVehicle ();
127
148
128
- if (!tmpKey .isEmpty ())
129
- url += "&key=" + tmpKey ;
130
- int altMax = request . getHints (). getInt ( "alternative_route.max_num" , 0 );
131
- if ( altMax != 0 )
149
+ if (!key .isEmpty ())
150
+ url += "&key=" + key ;
151
+
152
+ for ( Entry < String , String > entry : request . getHints (). toMap (). entrySet () )
132
153
{
133
- url += "&alternative_route.max_num=" + altMax ;
154
+ String urlKey = entry .getKey ();
155
+ String urlValue = entry .getValue ();
156
+
157
+ // use lower case conversion for check only!
158
+ if (ignoreSet .contains (urlKey .toLowerCase ()))
159
+ continue ;
160
+
161
+ if (urlValue != null && !urlValue .isEmpty ())
162
+ url += "&" + WebHelper .encodeURL (urlKey ) + "=" + WebHelper .encodeURL (urlValue );
134
163
}
135
164
136
165
String str = downloader .downloadAsString (url , true );
0 commit comments