Skip to content

Commit 030b320

Browse files
author
Matt
committed
this commit adds the LeafletUILayerInt interface, which provides methods for adding and managing user interface elements like markers and popups in a Leaflet map. Leaflet is a popular JavaScript library for creating interactive maps, and this interface provides a Java API for working with user interface elements within Leaflet. it includes methods for adding markers and popups at specified geographical coordinates, as well as removing them based on their identifiers. This enhancement improves the usability and flexibility of the Leaflet map UI layer.
1 parent 5a320b4 commit 030b320

2 files changed

Lines changed: 82 additions & 6 deletions

File tree

‎src/main/java/io/github/makbn/jlmap/layer/JLUiLayer.java‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.makbn.jlmap.layer;
22

33
import io.github.makbn.jlmap.JLMapCallbackHandler;
4+
import io.github.makbn.jlmap.layer.leaflet.LeafletUILayerInt;
45
import io.github.makbn.jlmap.model.JLLatLng;
56
import io.github.makbn.jlmap.model.JLMarker;
67
import io.github.makbn.jlmap.model.JLOptions;
@@ -9,9 +10,9 @@
910

1011
/**
1112
* Represents the UI layer on Leaflet map.
12-
* by: Mehdi Akbarian Rastaghi (@makbn)
13+
* @author Mehdi Akbarian Rastaghi (@makbn)
1314
*/
14-
public class JLUiLayer extends JLLayer {
15+
public class JLUiLayer extends JLLayer implements LeafletUILayerInt {
1516

1617
public JLUiLayer(WebEngine engine, JLMapCallbackHandler callbackHandler) {
1718
super(engine, callbackHandler);
@@ -24,6 +25,7 @@ public JLUiLayer(WebEngine engine, JLMapCallbackHandler callbackHandler) {
2425
* @param text content of the related popup if available!
2526
* @return the instance of added {{@link JLMarker}} on the map.
2627
*/
28+
@Override
2729
public JLMarker addMarker(JLLatLng latLng, String text, boolean draggable) {
2830
String result = engine.executeScript(String.format("addMarker(%f, %f, '%s', %b)", latLng.getLat(), latLng.getLng(), text, draggable))
2931
.toString();
@@ -38,6 +40,7 @@ public JLMarker addMarker(JLLatLng latLng, String text, boolean draggable) {
3840
* @param id of the marker for removing.
3941
* @return {{@link Boolean#TRUE}} if removed successfully.
4042
*/
43+
@Override
4144
public boolean removeMarker(int id){
4245
String result = engine.executeScript(String.format("removeMarker(%d)", id))
4346
.toString();
@@ -52,8 +55,9 @@ public boolean removeMarker(int id){
5255
* @param options see {{@link JLOptions}} for customizing
5356
* @return the instance of added {{@link JLPopup}} on the map.
5457
*/
58+
@Override
5559
public JLPopup addPopup(JLLatLng latLng, String text, JLOptions options){
56-
String result = engine.executeScript(String.format("addPopup(%f, %f, %s, %b , %b)", latLng.getLat(),
60+
String result = engine.executeScript(String.format("addPopup(%f, %f, \"%s\", %b , %b)", latLng.getLat(),
5761
latLng.getLng(), text, options.isCloseButton(), options.isAutoClose()))
5862
.toString();
5963

@@ -63,17 +67,19 @@ public JLPopup addPopup(JLLatLng latLng, String text, JLOptions options){
6367

6468
/**
6569
* Add popup with {{@link JLOptions#DEFAULT}} options
66-
* @see {{@link JLUiLayer#addPopup(JLLatLng, String, JLOptions)}}
70+
* @see JLUiLayer#addPopup(JLLatLng, String, JLOptions)
6771
*/
72+
@Override
6873
public JLPopup addPopup(JLLatLng latLng, String text){
6974
return addPopup(latLng, text, JLOptions.DEFAULT);
7075
}
7176

7277
/**
73-
* Remove a {{@link JLPopup}} from the map.
78+
* Remove a {@link JLPopup} from the map.
7479
* @param id of the marker for removing.
75-
* @return {{@link Boolean#TRUE}} if removed successfully.
80+
* @return true if removed successfully.
7681
*/
82+
@Override
7783
public boolean removePopup(int id){
7884
String result = engine.executeScript(String.format("removePopup(%d)", id))
7985
.toString();
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package io.github.makbn.jlmap.layer.leaflet;
2+
3+
import io.github.makbn.jlmap.model.JLLatLng;
4+
import io.github.makbn.jlmap.model.JLMarker;
5+
import io.github.makbn.jlmap.model.JLOptions;
6+
import io.github.makbn.jlmap.model.JLPopup;
7+
8+
/**
9+
* The {@code LeafletUILayerInt} interface defines methods for adding and managing
10+
* user interface elements like markers and popups in a Leaflet map. Leaflet is a popular
11+
* JavaScript library for creating interactive maps, and this interface provides a Java
12+
* API for working with user interface elements within Leaflet.
13+
*
14+
* @author Mehdi Akbarian Rastaghi (@makbn)
15+
*/
16+
public interface LeafletUILayerInt {
17+
18+
/**
19+
* Adds a marker to the Leaflet map at the specified geographical coordinates.
20+
*
21+
* @param latLng The geographical coordinates (latitude and longitude) where the marker
22+
* should be placed.
23+
* @param text The text content associated with the marker.
24+
* @param draggable {@code true} if the marker should be draggable, {@code false} otherwise.
25+
* @return The {@link JLMarker} representing the added marker on the map.
26+
*/
27+
JLMarker addMarker(JLLatLng latLng, String text, boolean draggable);
28+
29+
/**
30+
* Removes a marker from the Leaflet map based on its identifier.
31+
*
32+
* @param id The unique identifier of the marker to be removed.
33+
* @return {@code true} if the marker was successfully removed, {@code false} if the
34+
* marker with the specified identifier was not found.
35+
*/
36+
boolean removeMarker(int id);
37+
38+
/**
39+
* Adds a popup to the Leaflet map at the specified geographical coordinates with custom
40+
* options.
41+
*
42+
* @param latLng The geographical coordinates (latitude and longitude) where the popup
43+
* should be displayed.
44+
* @param text The text content of the popup.
45+
* @param options Custom options for configuring the appearance and behavior of the popup.
46+
* @return The {@link JLPopup} representing the added popup on the map.
47+
*/
48+
JLPopup addPopup(JLLatLng latLng, String text, JLOptions options);
49+
50+
/**
51+
* Adds a popup to the Leaflet map at the specified geographical coordinates with default
52+
* options.
53+
*
54+
* @param latLng The geographical coordinates (latitude and longitude) where the popup
55+
* should be displayed.
56+
* @param text The text content of the popup.
57+
* @return The {@link JLPopup} representing the added popup on the map.
58+
*/
59+
JLPopup addPopup(JLLatLng latLng, String text);
60+
61+
/**
62+
* Removes a popup from the Leaflet map based on its identifier.
63+
*
64+
* @param id The unique identifier of the popup to be removed.
65+
* @return {@code true} if the popup was successfully removed, {@code false} if the
66+
* popup with the specified identifier was not found.
67+
*/
68+
boolean removePopup(int id);
69+
}
70+

0 commit comments

Comments
 (0)