Skip to content

Commit 93ebc8f

Browse files
committed
added image overlay functionality to javafx
Signed-off-by: makbn <mehdi74akbarian@gmail.com>
1 parent 4897db9 commit 93ebc8f

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

jlmap-fx/src/main/java/io/github/makbn/jlmap/fx/demo/LeafletTestJFX.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ public void mapLoadedSuccessfully(@NonNull JLMapController mapView) {
9191
.lng(51.45)
9292
.build(), 30000, JLOptions.DEFAULT);
9393

94+
// JLImageOverlay demo: Eiffel Tower image over Paris
95+
JLBounds eiffelBounds = JLBounds.builder()
96+
.southWest(JLLatLng.builder().lat(47.857).lng(3.293).build())
97+
.northEast(JLLatLng.builder().lat(49.860).lng(1.298).build())
98+
.build();
99+
map.getUiLayer().addImage(
100+
eiffelBounds,
101+
"https://img.favpng.com/1/24/8/eiffel-tower-eiffel-tower-illustrated-landmark-L5szYqrZ_t.jpg",
102+
JLOptions.DEFAULT
103+
);
104+
94105
// map zoom functionalities
95106
map.getControlLayer().setZoom(5);
96107
map.getControlLayer().zoomIn(2);

jlmap-fx/src/main/java/io/github/makbn/jlmap/fx/layer/JLUiLayer.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
1717
public class JLUiLayer extends JLLayer implements LeafletUILayerInt {
18-
JLTransporter transporter;
18+
JLTransporter<Object> transporter;
1919

2020
public JLUiLayer(JLWebEngine<Object> engine, JLMapCallbackHandler callbackHandler) {
2121
super(engine, callbackHandler);
@@ -95,8 +95,29 @@ public boolean removePopup(String id) {
9595
return Boolean.parseBoolean(result);
9696
}
9797

98+
/**
99+
* Adds an image overlay to the map at the specified bounds with the given image URL and options.
100+
*
101+
* @param bounds the geographical bounds the image is tied to
102+
* @param imageUrl URL of the image to be used as an overlay
103+
* @param options theming options for JLImageOverlay
104+
* @return the instance of added {@link JLImageOverlay} on the map
105+
*/
98106
@Override
99107
public JLImageOverlay addImage(JLBounds bounds, String imageUrl, JLOptions options) {
100-
throw new UnsupportedOperationException();
108+
// Convert options to JS object (simple: only opacity and zIndex for demo)
109+
String optionsJs = String.format("{opacity: %f, zIndex: %d}",
110+
options.getOpacity(), 1);
111+
// Call JS function to add image overlay
112+
String result = engine.executeScript(String.format(
113+
"addImageOverlay(%s, '%s', %s)", bounds, imageUrl, optionsJs)).toString();
114+
JLImageOverlay overlay = JLImageOverlay.builder()
115+
.transport(transporter)
116+
.options(options)
117+
.bounds(bounds)
118+
.imageUrl(imageUrl)
119+
.build();
120+
callbackHandler.addJLObject(result, overlay);
121+
return overlay;
101122
}
102123
}

jlmap-fx/src/main/resources/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
var circleMarkers = [];
121121
var popups = [];
122122
var polyLines = []
123+
var images = []
123124
var polygons = []
124125
var circles = []
125126

@@ -212,6 +213,14 @@
212213

213214
}
214215

216+
function addImageOverlay(bounds, imageUrl, options) {
217+
let image = L.imageOverlay(imageUrl, bounds, options);
218+
image.jlid = 'image';
219+
image.addTo(jlFeatureGroup);
220+
let len = images.push(image);
221+
}
222+
223+
215224
function removeCircle(index) {
216225
let circle = circles[index];
217226
if (circle === undefined) {

0 commit comments

Comments
 (0)