diff --git a/src/main/java/io/github/makbn/jlmap/layer/JLUiLayer.java b/src/main/java/io/github/makbn/jlmap/layer/JLUiLayer.java index ac86c16..c9c82b3 100644 --- a/src/main/java/io/github/makbn/jlmap/layer/JLUiLayer.java +++ b/src/main/java/io/github/makbn/jlmap/layer/JLUiLayer.java @@ -1,6 +1,7 @@ package io.github.makbn.jlmap.layer; import io.github.makbn.jlmap.JLMapCallbackHandler; +import io.github.makbn.jlmap.layer.leaflet.LeafletUILayerInt; import io.github.makbn.jlmap.model.JLLatLng; import io.github.makbn.jlmap.model.JLMarker; import io.github.makbn.jlmap.model.JLOptions; @@ -9,9 +10,9 @@ /** * Represents the UI layer on Leaflet map. - * by: Mehdi Akbarian Rastaghi (@makbn) + * @author Mehdi Akbarian Rastaghi (@makbn) */ -public class JLUiLayer extends JLLayer { +public class JLUiLayer extends JLLayer implements LeafletUILayerInt { public JLUiLayer(WebEngine engine, JLMapCallbackHandler callbackHandler) { super(engine, callbackHandler); @@ -24,6 +25,7 @@ public JLUiLayer(WebEngine engine, JLMapCallbackHandler callbackHandler) { * @param text content of the related popup if available! * @return the instance of added {{@link JLMarker}} on the map. */ + @Override public JLMarker addMarker(JLLatLng latLng, String text, boolean draggable) { String result = engine.executeScript(String.format("addMarker(%f, %f, '%s', %b)", latLng.getLat(), latLng.getLng(), text, draggable)) .toString(); @@ -38,6 +40,7 @@ public JLMarker addMarker(JLLatLng latLng, String text, boolean draggable) { * @param id of the marker for removing. * @return {{@link Boolean#TRUE}} if removed successfully. */ + @Override public boolean removeMarker(int id){ String result = engine.executeScript(String.format("removeMarker(%d)", id)) .toString(); @@ -52,8 +55,9 @@ public boolean removeMarker(int id){ * @param options see {{@link JLOptions}} for customizing * @return the instance of added {{@link JLPopup}} on the map. */ + @Override public JLPopup addPopup(JLLatLng latLng, String text, JLOptions options){ - String result = engine.executeScript(String.format("addPopup(%f, %f, %s, %b , %b)", latLng.getLat(), + String result = engine.executeScript(String.format("addPopup(%f, %f, \"%s\", %b , %b)", latLng.getLat(), latLng.getLng(), text, options.isCloseButton(), options.isAutoClose())) .toString(); @@ -63,17 +67,19 @@ public JLPopup addPopup(JLLatLng latLng, String text, JLOptions options){ /** * Add popup with {{@link JLOptions#DEFAULT}} options - * @see {{@link JLUiLayer#addPopup(JLLatLng, String, JLOptions)}} + * @see JLUiLayer#addPopup(JLLatLng, String, JLOptions) */ + @Override public JLPopup addPopup(JLLatLng latLng, String text){ return addPopup(latLng, text, JLOptions.DEFAULT); } /** - * Remove a {{@link JLPopup}} from the map. + * Remove a {@link JLPopup} from the map. * @param id of the marker for removing. - * @return {{@link Boolean#TRUE}} if removed successfully. + * @return true if removed successfully. */ + @Override public boolean removePopup(int id){ String result = engine.executeScript(String.format("removePopup(%d)", id)) .toString(); diff --git a/src/main/java/io/github/makbn/jlmap/layer/leaflet/LeafletUILayerInt.java b/src/main/java/io/github/makbn/jlmap/layer/leaflet/LeafletUILayerInt.java new file mode 100644 index 0000000..849c460 --- /dev/null +++ b/src/main/java/io/github/makbn/jlmap/layer/leaflet/LeafletUILayerInt.java @@ -0,0 +1,70 @@ +package io.github.makbn.jlmap.layer.leaflet; + +import io.github.makbn.jlmap.model.JLLatLng; +import io.github.makbn.jlmap.model.JLMarker; +import io.github.makbn.jlmap.model.JLOptions; +import io.github.makbn.jlmap.model.JLPopup; + +/** + * The {@code LeafletUILayerInt} interface defines 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. + * + * @author Mehdi Akbarian Rastaghi (@makbn) + */ +public interface LeafletUILayerInt { + + /** + * Adds a marker to the Leaflet map at the specified geographical coordinates. + * + * @param latLng The geographical coordinates (latitude and longitude) where the marker + * should be placed. + * @param text The text content associated with the marker. + * @param draggable {@code true} if the marker should be draggable, {@code false} otherwise. + * @return The {@link JLMarker} representing the added marker on the map. + */ + JLMarker addMarker(JLLatLng latLng, String text, boolean draggable); + + /** + * Removes a marker from the Leaflet map based on its identifier. + * + * @param id The unique identifier of the marker to be removed. + * @return {@code true} if the marker was successfully removed, {@code false} if the + * marker with the specified identifier was not found. + */ + boolean removeMarker(int id); + + /** + * Adds a popup to the Leaflet map at the specified geographical coordinates with custom + * options. + * + * @param latLng The geographical coordinates (latitude and longitude) where the popup + * should be displayed. + * @param text The text content of the popup. + * @param options Custom options for configuring the appearance and behavior of the popup. + * @return The {@link JLPopup} representing the added popup on the map. + */ + JLPopup addPopup(JLLatLng latLng, String text, JLOptions options); + + /** + * Adds a popup to the Leaflet map at the specified geographical coordinates with default + * options. + * + * @param latLng The geographical coordinates (latitude and longitude) where the popup + * should be displayed. + * @param text The text content of the popup. + * @return The {@link JLPopup} representing the added popup on the map. + */ + JLPopup addPopup(JLLatLng latLng, String text); + + /** + * Removes a popup from the Leaflet map based on its identifier. + * + * @param id The unique identifier of the popup to be removed. + * @return {@code true} if the popup was successfully removed, {@code false} if the + * popup with the specified identifier was not found. + */ + boolean removePopup(int id); +} +