Skip to content

Commit ec5797a

Browse files
committed
Fixes several minor issues
1 parent f56d776 commit ec5797a

File tree

9 files changed

+84
-29
lines changed

9 files changed

+84
-29
lines changed

graphhopper-teavm/pom.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
</goals>
8484
<phase>process-classes</phase>
8585
<configuration>
86-
<minifying>true</minifying>
86+
<minifying>false</minifying>
8787
<targetDirectory>${project.build.directory}</targetDirectory>
88-
<runtimeCopy>MERGE</runtimeCopy>
88+
<runtime>MERGED</runtime>
8989
<targetFileName>graphhopper-client-0.3.min.js</targetFileName>
9090
<classAliases>
9191
<item>
@@ -103,11 +103,25 @@
103103
<className>com.graphhopper.teavm.ClientSideGraphHopper</className>
104104
<methodName>route</methodName>
105105
<descriptor>(II)Lcom.graphhopper.routing.Path;</descriptor>
106+
<types>
107+
<item>com.graphhopper.teavm.ClientSideGraphHopper</item>
108+
</types>
106109
</item>
107110
<item>
108111
<className>com.graphhopper.teavm.ClientSideGraphHopper</className>
109112
<methodName>findNode</methodName>
110113
<descriptor>(DD)I</descriptor>
114+
<types>
115+
<item>com.graphhopper.teavm.ClientSideGraphHopper</item>
116+
</types>
117+
</item>
118+
<item>
119+
<className>com.graphhopper.teavm.ClientSideGraphHopper</className>
120+
<methodName>load</methodName>
121+
<descriptor>(Lorg.teavm.jso.JSArray;)V</descriptor>
122+
<types>
123+
<item>com.graphhopper.teavm.ClientSideGraphHopper</item>
124+
</types>
111125
</item>
112126
</methodAliases>
113127
</configuration>

graphhopper-teavm/src/main/java/com/graphhopper/teavm/ClientSideGraphHopper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public class ClientSideGraphHopper {
3232
@PreserveOriginalName
3333
public void load(JSArray<DataEntry> data) {
3434
if (logger.isInfoEnabled()) {
35-
logger.info("Loading GraphGopper directory");
35+
logger.info("Loading GraphHopper directory");
3636
}
3737
long start = System.currentTimeMillis();
3838
loadStorage(data);
3939
if (logger.isInfoEnabled()) {
40-
logger.info("GraphHopper directory loaded in {}ms", System.currentTimeMillis() - start);
40+
logger.info("GraphHopper directory loaded in {} ms", System.currentTimeMillis() - start);
4141
}
4242

4343
if (logger.isInfoEnabled()) {
@@ -57,10 +57,11 @@ public void load(JSArray<DataEntry> data) {
5757
prepare.setGraph(graph);
5858

5959
if (logger.isInfoEnabled()) {
60-
logger.info("GraphHopper initialized in {}ms", System.currentTimeMillis() - start);
60+
logger.info("GraphHopper initialized in {} ms", System.currentTimeMillis() - start);
6161
}
6262
}
6363

64+
@PreserveOriginalName
6465
public BBox getBounds() {
6566
return graph.getBounds();
6667
}

graphhopper-teavm/src/main/java/com/graphhopper/teavm/GraphHopperUI.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public GraphHopperUI(Element element) {
3939
this.element = element;
4040
LeafletMapOptions options = Leaflet.createMapOptions();
4141
map = Leaflet.map(element, options);
42-
Leaflet.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(map);
42+
TileLayerOptions tileOptions = Leaflet.createTileLayerOptions();
43+
tileOptions.setAttribution("&copy; <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a> " +
44+
"contributors");
45+
Leaflet.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", tileOptions).addTo(map);
4346
map.on("click", new LeafletMapEventListener() {
4447
@Override public void occur(LeafletMapEvent event) {
4548
click(event.getLatlng());
@@ -65,7 +68,9 @@ private void click(LatLng latlng) {
6568
if (secondMarker != null) {
6669
map.removeLayer(firstMarker);
6770
map.removeLayer(secondMarker);
68-
map.removeLayer(pathDisplay);
71+
if (pathDisplay != null) {
72+
map.removeLayer(pathDisplay);
73+
}
6974
firstMarker = Leaflet.marker(latlng).addTo(map);
7075
secondMarker = null;
7176
pathDisplay = null;
@@ -77,6 +82,11 @@ private void click(LatLng latlng) {
7782
LatLng second = secondMarker.getLatLng();
7883
int firstNode = graphHopper.findNode(first.getLat(), first.getLng());
7984
int secondNode = graphHopper.findNode(second.getLat(), second.getLng());
85+
if (firstNode < 0 || secondNode < 0) {
86+
pathDisplay = null;
87+
window.alert("One of the provided points is outside of the known region");
88+
return;
89+
}
8090
Path path = graphHopper.route(firstNode, secondNode);
8191
InstructionList instructions = path.calcInstructions();
8292
JSArray<LatLng> array = window.newArray();

graphhopper-teavm/src/main/java/com/graphhopper/teavm/GraphhopperJsonGenerator.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@
55
import java.io.PrintStream;
66
import java.util.Arrays;
77
import com.graphhopper.GraphHopper;
8-
import com.graphhopper.routing.DijkstraBidirection;
9-
import com.graphhopper.routing.Path;
108
import com.graphhopper.routing.util.CarFlagEncoder;
119
import com.graphhopper.routing.util.EncodingManager;
12-
import com.graphhopper.routing.util.FastestWeighting;
13-
import com.graphhopper.routing.util.Weighting;
1410
import com.graphhopper.storage.DataAccess;
1511
import com.graphhopper.storage.GHDirectory;
16-
import com.graphhopper.storage.index.LocationIndex;
17-
import com.graphhopper.util.PointList;
1812

1913
/**
2014
*
@@ -29,21 +23,6 @@ public static void main(String[] args) throws IOException {
2923
gh.setEncodingManager(new EncodingManager(new CarFlagEncoder()));
3024
gh.set3D(true);
3125
gh.importOrLoad();
32-
LocationIndex locTree = gh.getLocationIndex();
33-
int fromNode = locTree.findID(55.762523, 37.408784);
34-
int toNode = locTree.findID(55.784806, 37.708047);
35-
System.out.println("Source node: " + fromNode);
36-
System.out.println("Target node: " + toNode);
37-
38-
Weighting weighting = new FastestWeighting(gh.getEncodingManager().getSingle());
39-
DijkstraBidirection algo = new DijkstraBidirection(gh.getGraph(), gh.getEncodingManager().getSingle(),
40-
weighting);
41-
Path path = algo.calcPath(fromNode, toNode);
42-
PointList points = path.calcPoints();
43-
for (int i = 0; i < points.size(); ++i) {
44-
System.out.println(points.getLat(i) + "; " + points.getLon(i));
45-
}
46-
System.out.println("Distance: " + path.getDistance());
4726

4827
GHDirectory dir = (GHDirectory)gh.getGraph().getDirectory();
4928
byte[] buffer = new byte[1024];

graphhopper-teavm/src/main/java/com/graphhopper/teavm/Main.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ public static void main(String[] args) {
1919
mapElement.setAttribute("style", "width: 800px; height: 480px");
2020
body.appendChild(mapElement);
2121

22-
GraphHopperUI ui = new GraphHopperUI(mapElement);
2322
@SuppressWarnings("unchecked")
2423
JSArray<DataEntry> data = (JSArray<DataEntry>)JS.get(JS.getGlobal(), JS.wrap("graphhopperData"));
24+
if (JS.isUndefined(data)) {
25+
window.alert("Can't initialize GraphHopper. gh-directory.js was not found.");
26+
return;
27+
}
28+
GraphHopperUI ui = new GraphHopperUI(mapElement);
2529
ui.load(data);
2630
}
2731
}

graphhopper-teavm/src/main/java/com/graphhopper/teavm/leaflet/Leaflet.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,18 @@ public static TileLayer tileLayer(String urlTemplate) {
5959
return api().tileLayer(urlTemplate);
6060
}
6161

62+
public static TileLayer tileLayer(String urlTemplate, TileLayerOptions options) {
63+
return api().tileLayer(urlTemplate, options);
64+
}
65+
6266
public static LeafletMapOptions createMapOptions() {
6367
return root.newMapOptions();
6468
}
6569

70+
public static TileLayerOptions createTileLayerOptions() {
71+
return root.newTileLayerOptions();
72+
}
73+
6674
public static <T extends JSObject> JSArray<T> createArray() {
6775
return root.newArray();
6876
}

graphhopper-teavm/src/main/java/com/graphhopper/teavm/leaflet/LeafletAPI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ public interface LeafletAPI extends JSObject {
2828
Marker marker(LatLng latLng);
2929

3030
TileLayer tileLayer(String urlTemplate);
31+
32+
TileLayer tileLayer(String urlTemplate, TileLayerOptions options);
3133
}

graphhopper-teavm/src/main/java/com/graphhopper/teavm/leaflet/LeafletRoot.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
interface LeafletRoot extends JSGlobal {
1111
@JSConstructor("Object")
1212
LeafletMapOptions newMapOptions();
13+
14+
@JSConstructor("Object")
15+
TileLayerOptions newTileLayerOptions();
1316
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.graphhopper.teavm.leaflet;
2+
3+
import org.teavm.jso.JSObject;
4+
import org.teavm.jso.JSProperty;
5+
6+
/**
7+
*
8+
* @author Alexey Andreev
9+
*/
10+
public interface TileLayerOptions extends JSObject {
11+
@JSProperty
12+
int getMinZoom();
13+
14+
@JSProperty
15+
void setMinZoom(int minZoom);
16+
17+
@JSProperty
18+
int getMaxZoom();
19+
20+
@JSProperty
21+
void setMaxZoom(int maxZoom);
22+
23+
@JSProperty
24+
int getTileSize();
25+
26+
@JSProperty
27+
void setTileSize(int tileSize);
28+
29+
@JSProperty
30+
String getAttribution();
31+
32+
@JSProperty
33+
void setAttribution(String attribution);
34+
}

0 commit comments

Comments
 (0)