Skip to content

Commit c496d66

Browse files
authored
Merge pull request #19 from makbn/release/1.9.4
Release/1.9.4
2 parents c89b356 + d6b808f commit c496d66

31 files changed

+415
-277
lines changed

.github/workflows/github-action-build.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ jobs:
88
steps:
99
# This step uses the `actions/checkout` action to download a copy of your repository on the runner.
1010
- uses: actions/checkout@v3
11-
# This step uses the `actions/setup-java` action to configure the Eclipse Temurin (Java) 17 JDK by Eclipse Adoptium.
1211
- name: Set up JDK 17
1312
uses: actions/setup-java@v3
1413
with:
@@ -20,7 +19,7 @@ jobs:
2019

2120
publish:
2221
needs: [ "build" ]
23-
if: contains(github.ref_name, 'dev/')
22+
if: contains(github.ref_name, 'release/')
2423
permissions:
2524
contents: read
2625
packages: write

LICENSE

-25
This file was deleted.

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ Java wrapper for Leaflet, JavaScript library for mobile-friendly interactive map
1313

1414
## Getting start
1515

16+
Since you are working on JavaFX application you know you need to have the JavaFX runtime.
17+
Read more about installing JavaFx:
18+
* https://openjfx.io/openjfx-docs/#introduction
19+
20+
To run the [Leaflet example](src/test/java/io/github/makbn/jlmap/Leaflet.java) class you need to set the module path
21+
as VM options:
22+
23+
```java
24+
--module-path [PATH_TO_JAVA_FX_LIB_FOLDER]
25+
--add-exports javafx.web/com.sun.javafx.webkit=ALL-UNNAMED
26+
--add-modules=javafx.graphics,javafx.web
27+
```
28+
29+
There is an issue with JavaFX v17.X javafx.web engine and OSM tiles, I tried JavaFX v19.0.2.1 and it works fine!
30+
1631
First, you need to initialize an instance of `JLMapView`:
1732

1833
```java

src/main/java/io/github/makbn/jlmap/JLMapCallbackHandler.java

+38-15
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ private void initClassMap() {
5151
* @param param5 additional param
5252
*/
5353
@SuppressWarnings("unchecked")
54-
public void functionCalled(String functionName, Object param1, Object param2, Object param3, Object param4,
55-
Object param5) {
56-
log.debug(String.format("functionName: %s \tparam1: %s \tparam2: %s \tparam3: %s param4: %s \tparam5: %s%n"
54+
public void functionCalled(String functionName, Object param1, Object param2,
55+
Object param3, Object param4, Object param5) {
56+
log.debug(String.format("function: %s \tparam1: %s \tparam2: %s " +
57+
"\tparam3: %s param4: %s \tparam5: %s%n"
5758
, functionName, param1, param2, param3, param4, param5));
5859
try {
5960
//get target class of Leaflet layer in JL Application
@@ -80,21 +81,42 @@ public void functionCalled(String functionName, Object param1, Object param2, Ob
8081
return;
8182

8283
//call listener and exit loop
83-
if (callListenerOnObject(functionName, (JLObject<JLObject<?>>) jlObject, param1, param2, param3, param4, param5))
84+
if (callListenerOnObject(functionName,
85+
(JLObject<JLObject<?>>) jlObject, param1,
86+
param2, param3, param4, param5))
8487
return;
8588
}
8689
}
87-
} else if (param1.equals("main_map") && mapView.getMapListener().isPresent()) {
90+
} else if (param1.equals("main_map")
91+
&& mapView.getMapListener().isPresent()) {
8892
switch (functionName) {
89-
case "move" -> mapView.getMapListener().get().onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE, gson.fromJson(String.valueOf(param4), JLLatLng.class),
90-
gson.fromJson(String.valueOf(param5), JLBounds.class), Integer.parseInt(String.valueOf(param3))));
91-
case "movestart" -> mapView.getMapListener().get().onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE_START, gson.fromJson(String.valueOf(param4), JLLatLng.class),
92-
gson.fromJson(String.valueOf(param5), JLBounds.class), Integer.parseInt(String.valueOf(param3))));
93-
case "moveend" -> mapView.getMapListener().get().onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE_END, gson.fromJson(String.valueOf(param4), JLLatLng.class),
94-
gson.fromJson(String.valueOf(param5), JLBounds.class), Integer.parseInt(String.valueOf(param3))));
95-
case "click" -> mapView.getMapListener().get().onAction(new ClickEvent(gson.fromJson(String.valueOf(param3), JLLatLng.class)));
96-
97-
case "zoom" -> mapView.getMapListener().get().onAction(new ZoomEvent(OnJLMapViewListener.Action.ZOOM, Integer.parseInt(String.valueOf(param3))));
93+
case "move" -> mapView.getMapListener()
94+
.get()
95+
.onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE,
96+
gson.fromJson(String.valueOf(param4), JLLatLng.class),
97+
gson.fromJson(String.valueOf(param5), JLBounds.class),
98+
Integer.parseInt(String.valueOf(param3))));
99+
case "movestart" -> mapView.getMapListener()
100+
.get()
101+
.onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE_START,
102+
gson.fromJson(String.valueOf(param4), JLLatLng.class),
103+
gson.fromJson(String.valueOf(param5), JLBounds.class),
104+
Integer.parseInt(String.valueOf(param3))));
105+
case "moveend" -> mapView.getMapListener()
106+
.get()
107+
.onAction(new MoveEvent(OnJLMapViewListener.Action.MOVE_END,
108+
gson.fromJson(String.valueOf(param4), JLLatLng.class),
109+
gson.fromJson(String.valueOf(param5), JLBounds.class),
110+
Integer.parseInt(String.valueOf(param3))));
111+
case "click" -> mapView.getMapListener()
112+
.get()
113+
.onAction(new ClickEvent(gson.fromJson(String.valueOf(param3),
114+
JLLatLng.class)));
115+
116+
case "zoom" -> mapView.getMapListener()
117+
.get()
118+
.onAction(new ZoomEvent(OnJLMapViewListener.Action.ZOOM,
119+
Integer.parseInt(String.valueOf(param3))));
98120
default -> log.error(functionName + " not implemented!");
99121
}
100122
}
@@ -103,7 +125,8 @@ public void functionCalled(String functionName, Object param1, Object param2, Ob
103125
}
104126
}
105127

106-
private boolean callListenerOnObject(String functionName, JLObject<JLObject<?>> jlObject, Object... params) {
128+
private boolean callListenerOnObject(
129+
String functionName, JLObject<JLObject<?>> jlObject, Object... params) {
107130
switch (functionName) {
108131
case "move" -> {
109132
jlObject.getOnActionListener()

src/main/java/io/github/makbn/jlmap/JLMapController.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,33 @@ public JLGeoJsonLayer getGeoJsonLayer() {
6060

6161
/**
6262
* Sets the view of the map (geographical center).
63-
* @param latLng Represents a geographical point with a certain latitude and longitude.
63+
* @param latLng Represents a geographical point with a certain latitude
64+
* and longitude.
6465
*/
6566
public void setView(JLLatLng latLng){
6667
checkMapState();
6768
getWebView().getEngine()
68-
.executeScript(String.format("jlmap.panTo([%f, %f]);", latLng.getLat(), latLng.getLng()));
69+
.executeScript(String.format("jlmap.panTo([%f, %f]);",
70+
latLng.getLat(), latLng.getLng()));
6971
}
7072

7173
/**
7274
* Sets the view of the map (geographical center) with animation duration.
7375
* @param duration Represents the duration of transition animation.
74-
* @param latLng Represents a geographical point with a certain latitude and longitude.
76+
* @param latLng Represents a geographical point with a certain latitude
77+
* and longitude.
7578
*/
7679
public void setView(JLLatLng latLng, int duration){
7780
checkMapState();
7881
getWebView().getEngine()
79-
.executeScript(String.format("setLatLng(%f, %f,%d);", latLng.getLat(), latLng.getLng(), duration));
82+
.executeScript(String.format("setLatLng(%f, %f,%d);",
83+
latLng.getLat(), latLng.getLng(), duration));
8084
}
8185

8286
private void checkMapState() {
83-
if(getWebView() == null || getWebView().getEngine().getLoadWorker().getState() != Worker.State.SUCCEEDED){
87+
if (getWebView() == null ||
88+
getWebView().getEngine()
89+
.getLoadWorker().getState() != Worker.State.SUCCEEDED) {
8490
throw JLMapNotReadyException.builder().build();
8591
}
8692
}

src/main/java/io/github/makbn/jlmap/JLMapView.java

+32-23
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@
4444
@Log4j2
4545
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
4646
public class JLMapView extends JLMapController {
47+
48+
@Builder
49+
public JLMapView(@NonNull JLProperties.MapType mapType,
50+
@NonNull JLLatLng startCoordinate, boolean showZoomController) {
51+
super(JLMapOption.builder()
52+
.startCoordinate(startCoordinate)
53+
.mapType(mapType)
54+
.additionalParameter(Set.of(new JLMapOption.Parameter("zoomControl",
55+
Objects.toString(showZoomController))))
56+
.build());
57+
this.webView = new WebView();
58+
this.jlMapCallbackHandler = new JLMapCallbackHandler(this);
59+
initialize();
60+
}
61+
4762
@Getter
4863
WebView webView;
4964
JLMapCallbackHandler jlMapCallbackHandler;
@@ -55,16 +70,9 @@ public class JLMapView extends JLMapController {
5570
@Nullable
5671
OnJLMapViewListener mapListener;
5772

58-
@Builder
59-
private JLMapView(@NonNull JLProperties.MapType mapType, @NonNull JLLatLng startCoordinate, boolean showZoomController) {
60-
super(JLMapOption.builder()
61-
.startCoordinate(startCoordinate)
62-
.mapType(mapType)
63-
.additionalParameter(Set.of(new JLMapOption.Parameter("zoomControl", Objects.toString(showZoomController))))
64-
.build());
65-
this.webView = new WebView();
66-
this.jlMapCallbackHandler = new JLMapCallbackHandler(this);
67-
initialize();
73+
private void removeMapBlur() {
74+
Transition gt = new MapTransition(webView);
75+
gt.play();
6876
}
6977

7078
private void initialize() {
@@ -132,20 +140,21 @@ private void checkForBrowsing(WebEngine engine) {
132140
}
133141
}
134142

135-
private void removeMapBlur() {
136-
Transition gt = new Transition() {
137-
{
138-
setCycleDuration(Duration.millis(2000));
139-
setInterpolator(Interpolator.EASE_IN);
140-
}
143+
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
144+
private static class MapTransition extends Transition {
145+
WebView webView;
141146

142-
@Override
143-
protected void interpolate(double frac) {
144-
GaussianBlur eff = ((GaussianBlur) webView.getEffect());
145-
eff.setRadius(JLProperties.START_ANIMATION_RADIUS * (1 - frac));
146-
}
147-
};
148-
gt.play();
147+
public MapTransition(WebView webView) {
148+
this.webView = webView;
149+
setCycleDuration(Duration.millis(2000));
150+
setInterpolator(Interpolator.EASE_IN);
151+
}
152+
153+
@Override
154+
protected void interpolate(double frac) {
155+
GaussianBlur eff = ((GaussianBlur) webView.getEffect());
156+
eff.setRadius(JLProperties.START_ANIMATION_RADIUS * (1 - frac));
157+
}
149158
}
150159

151160
private void setBlurEffectForMap() {

src/main/java/io/github/makbn/jlmap/JLProperties.java

-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.github.makbn.jlmap;
22

33
import io.github.makbn.jlmap.model.JLMapOption;
4-
import lombok.AccessLevel;
5-
import lombok.experimental.FieldDefaults;
64

75
import java.util.Collections;
86
import java.util.Set;
@@ -29,22 +27,6 @@ public MapType(String name) {
2927
public static final MapType OSM_MAPNIK = new MapType("OpenStreetMap.Mapnik");
3028
public static final MapType OSM_HOT = new MapType("OpenStreetMap.HOT");
3129
public static final MapType OPEN_TOPO = new MapType("OpenTopoMap");
32-
public static final MapType STADIA_ALIDADE_SMOOTH_LIGHT = new MapType("Stadia.AlidadeSmooth");
33-
public static final MapType STADIA_ALIDADE_SMOOTH_DARK = new MapType("Stadia.AlidadeSmoothDark");
34-
public static final MapType STADIA_OSM_BRIGHT = new MapType("Stadia.OSMBright");
35-
public static final MapType STADIA_WATERCOLOR = new MapType("Stadia.StamenWatercolor");
36-
public static final MapType STADIA_STAMEN_TONER_LITE = new MapType("Stadia.StamenTonerLite");
37-
public static final MapType STADIA_STAMEN_TERRAIN = new MapType("Stadia.StamenTerrain");
38-
39-
public static final MapType OPNV_KARTE = new MapType("OPNVKarte");
40-
public static final MapType THUNDERFOREST_CYCLE = new MapType("Thunderforest.OpenCycleMap");
41-
public static final MapType THUNDERFOREST_TRANSPORT = new MapType("Thunderforest.Transport");
42-
public static final MapType THUNDERFOREST_SPINAL = new MapType("Thunderforest.SpinalMap");
43-
44-
public static final MapType JAWG_TERRAIN = new MapType("Jawg.Terrain");
45-
public static final MapType JAWG_LIGHT = new MapType("Jawg.Light");
46-
public static final MapType JAWG_DARK = new MapType("Jawg.Dark");
47-
public static final MapType JAWG_MATRIX = new MapType("Jawg.Matrix");
4830

4931
public static MapType getDefault() {
5032
return OSM_MAPNIK;

src/main/java/io/github/makbn/jlmap/exception/JLMapNotReadyException.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
/**
66
* JLMap Exception which is thrown when changing the map before it gets ready!
7-
* Leaflet map gets fully ready after the {{@link javafx.concurrent.Worker.State}} of {{@link javafx.scene.web.WebEngine}}
8-
* changes to {{@link javafx.concurrent.Worker.State#SUCCEEDED}}
7+
* Leaflet map gets fully ready after the {@link javafx.concurrent.Worker.State}
8+
* of {@link javafx.scene.web.WebEngine} changes to
9+
* {@link javafx.concurrent.Worker.State#SUCCEEDED}
10+
*
911
* @author Mehdi Akbarian Rastaghi (@makbn)
1012
*/
11-
public class JLMapNotReadyException extends JLException{
13+
public class JLMapNotReadyException extends JLException {
1214
private static final String MAP_IS_NOT_READY_YET = "Map is not ready yet!";
1315

1416
@Builder

src/main/java/io/github/makbn/jlmap/layer/JLControlLayer.java

+22-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
/**
1010
* Represents the Control layer on Leaflet map.
11+
*
1112
* @author Mehdi Akbarian Rastaghi (@makbn)
1213
*/
1314
public class JLControlLayer extends JLLayer implements LeafletControlLayerInt {
14-
public JLControlLayer(WebEngine engine, JLMapCallbackHandler callbackHandler) {
15+
public JLControlLayer(WebEngine engine,
16+
JLMapCallbackHandler callbackHandler) {
1517
super(engine, callbackHandler);
1618
}
1719

@@ -32,12 +34,15 @@ public void setZoom(int level) {
3234

3335
@Override
3436
public void setZoomAround(JLLatLng latLng, int zoom) {
35-
engine.executeScript(String.format("getMap().setZoomAround(L.latLng(%f, %f), %d)", latLng.getLat(), latLng.getLng(), zoom));
37+
engine.executeScript(
38+
String.format("getMap().setZoomAround(L.latLng(%f, %f), %d)",
39+
latLng.getLat(), latLng.getLng(), zoom));
3640
}
3741

3842
@Override
3943
public void fitBounds(JLBounds bounds) {
40-
engine.executeScript(String.format("getMap().fitBounds(%s)", bounds.toString()));
44+
engine.executeScript(String.format("getMap().fitBounds(%s)",
45+
bounds.toString()));
4146
}
4247

4348
@Override
@@ -47,22 +52,27 @@ public void fitWorld() {
4752

4853
@Override
4954
public void panTo(JLLatLng latLng) {
50-
engine.executeScript(String.format("getMap().panTo(L.latLng(%f, %f))", latLng.getLat(), latLng.getLng()));
55+
engine.executeScript(String.format("getMap().panTo(L.latLng(%f, %f))",
56+
latLng.getLat(), latLng.getLng()));
5157
}
5258

5359
@Override
5460
public void flyTo(JLLatLng latLng, int zoom) {
55-
engine.executeScript(String.format("getMap().flyTo(L.latLng(%f, %f), %d)", latLng.getLat(), latLng.getLng(), zoom));
61+
engine.executeScript(
62+
String.format("getMap().flyTo(L.latLng(%f, %f), %d)",
63+
latLng.getLat(), latLng.getLng(), zoom));
5664
}
5765

5866
@Override
5967
public void flyToBounds(JLBounds bounds) {
60-
engine.executeScript(String.format("getMap().flyToBounds(%s)", bounds.toString()));
68+
engine.executeScript(String.format("getMap().flyToBounds(%s)",
69+
bounds.toString()));
6170
}
6271

6372
@Override
6473
public void setMaxBounds(JLBounds bounds) {
65-
engine.executeScript(String.format("getMap().setMaxBounds(%s)", bounds.toString()));
74+
engine.executeScript(String.format("getMap().setMaxBounds(%s)",
75+
bounds.toString()));
6676
}
6777

6878
@Override
@@ -77,11 +87,14 @@ public void setMaxZoom(int zoom) {
7787

7888
@Override
7989
public void panInsideBounds(JLBounds bounds) {
80-
engine.executeScript(String.format("getMap().panInsideBounds(%s)", bounds.toString()));
90+
engine.executeScript(String.format("getMap().panInsideBounds(%s)",
91+
bounds.toString()));
8192
}
8293

8394
@Override
8495
public void panInside(JLLatLng latLng) {
85-
engine.executeScript(String.format("getMap().panInside(L.latLng(%f, %f))", latLng.getLat(), latLng.getLng()));
96+
engine.executeScript(
97+
String.format("getMap().panInside(L.latLng(%f, %f))",
98+
latLng.getLat(), latLng.getLng()));
8699
}
87100
}

0 commit comments

Comments
 (0)