Skip to content

Commit

Permalink
this commit adds the LeafletUILayerInt interface, which provides meth…
Browse files Browse the repository at this point in the history
…ods 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.
  • Loading branch information
Matt committed Sep 9, 2023
1 parent 5a320b4 commit 030b320
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/io/github/makbn/jlmap/layer/JLUiLayer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 030b320

Please sign in to comment.