Skip to content

Commit 5ffd156

Browse files
committed
fixed the issue with newer version of javafx. updated javafx to the latest version
Signed-off-by: makbn <mehdi74akbarian@gmail.com>
1 parent 0a2b398 commit 5ffd156

File tree

7 files changed

+102
-5
lines changed

7 files changed

+102
-5
lines changed

jlmap-api/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
<groupId>org.apache.maven.plugins</groupId>
5252
<artifactId>maven-surefire-plugin</artifactId>
5353
<version>3.1.2</version>
54+
<configuration>
55+
<useModulePath>false</useModulePath>
56+
</configuration>
5457
</plugin>
5558
<plugin>
5659
<groupId>org.jacoco</groupId>
@@ -111,5 +114,17 @@
111114
<version>3.27.7</version>
112115
<scope>test</scope>
113116
</dependency>
117+
<dependency>
118+
<groupId>org.mockito</groupId>
119+
<artifactId>mockito-core</artifactId>
120+
<version>5.7.0</version>
121+
<scope>test</scope>
122+
</dependency>
123+
<dependency>
124+
<groupId>org.mockito</groupId>
125+
<artifactId>mockito-junit-jupiter</artifactId>
126+
<version>5.7.0</version>
127+
<scope>test</scope>
128+
</dependency>
114129
</dependencies>
115130
</project>

jlmap-fx/pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
<useModulePath>false</useModulePath>
106106
<argLine>
107107
--add-opens javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
108-
--add-opens javafx.graphics/com.sun.javafx.application=org.testfx.junit5
109108
--add-opens javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED
110109
--add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
111110
--add-opens javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
@@ -116,7 +115,6 @@
116115
--add-opens java.desktop/java.awt.font=ALL-UNNAMED
117116
--add-opens javafx.web/com.sun.javafx.webkit=ALL-UNNAMED
118117
--add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
119-
--add-exports javafx.graphics/com.sun.glass.ui=org.testfx.monocle
120118
-Djava.awt.headless=true
121119
-Dtestfx.robot=glass
122120
-Dtestfx.headless=true
@@ -258,7 +256,7 @@
258256
<dependency>
259257
<groupId>org.testfx</groupId>
260258
<artifactId>openjfx-monocle</artifactId>
261-
<version>jdk-12.0.1+2</version>
259+
<version>17.0.10</version>
262260
<scope>test</scope>
263261
</dependency>
264262
<!-- Additional utility libraries for testing -->

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public JLMapView(@NonNull JLMapProvider jlMapProvider,
8282
.build();
8383
this.layers = new HashMap<>();
8484
this.webView = new WebView();
85+
this.webView.setCache(false);
8586
this.jlWebEngine = new JLJavaFXEngine(webView.getEngine());
8687
this.jlMapCallbackHandler = new JLMapEventHandler();
8788
initialize();

jlmap-fx/src/main/java/io/github/makbn/jlmap/fx/internal/JLFxMapRenderer.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public String render(@NonNull JLMapOption option) {
2323
title(TITLE),
2424
meta().withCharset("utf-8"),
2525
meta().withName("viewport").withContent("width=device-width, initial-scale=1.0"),
26+
script(webViewCompatibilityPatch()),
2627
link()
2728
.withRel("stylesheet")
2829
.withHref(CSS_LEAFLET)
@@ -136,4 +137,27 @@ function eventHandler(functionType, jlType, uuid, param1, param2, param3) {
136137
""";
137138
}
138139

140+
@NonNull
141+
private String webViewCompatibilityPatch() {
142+
//language=js
143+
return """
144+
(function() {
145+
try {
146+
// JavaFX WebView (versions > 19) has GPU compositing bugs with CSS translate3d
147+
// that corrupt tile positioning and cause black rectangles. Forcing Leaflet to
148+
// use 2D CSS transforms avoids the broken compositor path entirely.
149+
window.L_DISABLE_3D = true;
150+
151+
// JavaFX WebView can expose a broken PointerEvent implementation that
152+
// interferes with Leaflet's interaction handling. Force the mouse event path.
153+
if (window.PointerEvent) {
154+
window.PointerEvent = undefined;
155+
}
156+
} catch (e) {
157+
// best-effort only
158+
}
159+
})();
160+
""";
161+
}
162+
139163
}

jlmap-fx/src/test/java/io/github/makbn/jlmap/fx/test/internal/JLFxMapRendererTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,63 @@ void render_shouldIncludeMetaTags() {
224224
assertThat(html).contains("<meta charset=\"utf-8\"");
225225
assertThat(html).contains("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"");
226226
}
227+
228+
@Test
229+
void render_shouldIncludeL_DISABLE_3D_flag() {
230+
// Given
231+
JLMapOption option = createDefaultMapOption();
232+
233+
// When
234+
String html = renderer.render(option);
235+
236+
// Then - L_DISABLE_3D must be present to force 2D CSS transforms in JavaFX WebView
237+
assertThat(html).contains("window.L_DISABLE_3D = true");
238+
}
239+
240+
@Test
241+
void render_shouldIncludePointerEventRemoval() {
242+
// Given
243+
JLMapOption option = createDefaultMapOption();
244+
245+
// When
246+
String html = renderer.render(option);
247+
248+
// Then - PointerEvent must be disabled for JavaFX WebView compatibility
249+
assertThat(html).contains("window.PointerEvent");
250+
assertThat(html).contains("PointerEvent = undefined");
251+
}
252+
253+
@Test
254+
void render_shouldPlaceCompatibilityPatchBeforeLeafletScript() {
255+
// Given
256+
JLMapOption option = createDefaultMapOption();
257+
258+
// When
259+
String html = renderer.render(option);
260+
261+
// Then - The patch must appear before Leaflet loads so L_DISABLE_3D is checked during init
262+
int patchPosition = html.indexOf("L_DISABLE_3D");
263+
int leafletScriptPosition = html.indexOf("leaflet@1.9.4/dist/leaflet.js");
264+
assertThat(patchPosition)
265+
.as("L_DISABLE_3D must appear before Leaflet script")
266+
.isGreaterThan(-1)
267+
.isLessThan(leafletScriptPosition);
268+
}
269+
270+
@Test
271+
void render_shouldWrapCompatibilityPatchInIIFE() {
272+
// Given
273+
JLMapOption option = createDefaultMapOption();
274+
275+
// When
276+
String html = renderer.render(option);
277+
278+
// Then - The patch should be wrapped in an IIFE with try-catch for safety
279+
int iifeStart = html.indexOf("(function()");
280+
int disableFlag = html.indexOf("L_DISABLE_3D");
281+
int iifeEnd = html.indexOf("})();");
282+
assertThat(iifeStart).isGreaterThan(-1);
283+
assertThat(disableFlag).isGreaterThan(iifeStart);
284+
assertThat(iifeEnd).isGreaterThan(disableFlag);
285+
}
227286
}

jlmap-vaadin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<maven.compiler.source>17</maven.compiler.source>
2828
<maven.compiler.target>17</maven.compiler.target>
2929
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
30-
<vaadin.version>24.8.6</vaadin.version>
30+
<vaadin.version>24.9.12</vaadin.version>
3131
<org.springframework.boot.version>3.5.4</org.springframework.boot.version>
3232
</properties>
3333

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<maven.compiler.source>17</maven.compiler.source>
2727
<maven.compiler.target>17</maven.compiler.target>
2828
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29-
<javafx.version>19.0.2.1</javafx.version>
29+
<javafx.version>21.0.5</javafx.version>
3030
<lombok.version>1.18.42</lombok.version>
3131
<jacoco.version>0.8.8</jacoco.version>
3232
<sonar.coverage.jacoco.xmlReportPaths>

0 commit comments

Comments
 (0)