Skip to content

Commit

Permalink
improving code quality and documenting for model classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt committed Sep 9, 2023
1 parent 7b262c5 commit f5002fa
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 84 deletions.
147 changes: 87 additions & 60 deletions src/main/java/io/github/makbn/jlmap/layer/JLVectorLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import io.github.makbn.jlmap.JLMapCallbackHandler;
import io.github.makbn.jlmap.JLProperties;
import io.github.makbn.jlmap.layer.leaflet.LeafletVectorLayerInt;
import io.github.makbn.jlmap.model.*;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;

/**
* Represents the Vector layer on Leaflet map.
* by: Mehdi Akbarian Rastaghi (@makbn)
* @author Mehdi Akbarian Rastaghi (@makbn)
*/
public class JLVectorLayer extends JLLayer {
public class JLVectorLayer extends JLLayer implements LeafletVectorLayerInt {

public JLVectorLayer(WebEngine engine, JLMapCallbackHandler callbackHandler) {
super(engine, callbackHandler);
Expand All @@ -19,18 +20,21 @@ public JLVectorLayer(WebEngine engine, JLMapCallbackHandler callbackHandler) {
/**
* Drawing polyline overlays on the map with {{@link JLOptions#DEFAULT}} options
*
* @see {{@link JLVectorLayer#addPolyline(JLLatLng[], JLOptions)}}
* @see JLVectorLayer#addPolyline(JLLatLng[], JLOptions)
*/
@Override
public JLPolyline addPolyline(JLLatLng[] vertices) {
return addPolyline(vertices, JLOptions.DEFAULT);
}

/**
* Drawing polyline overlays on the map.
*
* @param vertices arrays of LatLng points
* @param options see {{@link JLOptions}} for customizing
* @return the added {{@link JLPolyline}} to map
* @param options see {@link JLOptions} for customizing
* @return the added {@link JLPolyline} to map
*/
@Override
public JLPolyline addPolyline(JLLatLng[] vertices, JLOptions options) {
String latlngs = convertJLLatLngToString(vertices);
String hexColor = convertColorToString(options.getColor());
Expand All @@ -45,9 +49,11 @@ public JLPolyline addPolyline(JLLatLng[] vertices, JLOptions options) {

/**
* Remove a polyline from the map by id.
*
* @param id of polyline
* @return {{@link Boolean#TRUE}} if removed successfully
* @return {@link Boolean#TRUE} if removed successfully
*/
@Override
public boolean removePolyline(int id) {
String result = engine.executeScript(String.format("removePolyLine(%d)", id))
.toString();
Expand All @@ -59,20 +65,24 @@ public boolean removePolyline(int id) {
}

/**
* Drawing multi polyline overlays on the map with {{@link JLOptions#DEFAULT}} options.
* @see {{@link JLVectorLayer#addMultiPolyline(JLLatLng[][], JLOptions)}}
* @return the added {{@link JLMultiPolyline}} to map
* Drawing multi polyline overlays on the map with {@link JLOptions#DEFAULT} options.
*
* @return the added {@link JLMultiPolyline} to map
* @see JLVectorLayer#addMultiPolyline(JLLatLng[][], JLOptions)
*/
public JLMultiPolyline addMultiPolyline(JLLatLng[][] vertices){
@Override
public JLMultiPolyline addMultiPolyline(JLLatLng[][] vertices) {
return addMultiPolyline(vertices, JLOptions.DEFAULT);
}

/**
* Drawing MultiPolyline shape overlays on the map with multi-dimensional array.
*
* @param vertices arrays of LatLng points
* @param options see {{@link JLOptions}} for customizing
* @return the added {{@link JLMultiPolyline}} to map
* @param options see {@link JLOptions} for customizing
* @return the added {@link JLMultiPolyline} to map
*/
@Override
public JLMultiPolyline addMultiPolyline(JLLatLng[][] vertices, JLOptions options) {
String latlngs = convertJLLatLngToString(vertices);
String hexColor = convertColorToString(options.getColor());
Expand All @@ -87,9 +97,10 @@ public JLMultiPolyline addMultiPolyline(JLLatLng[][] vertices, JLOptions options


/**
* @see {{@link JLVectorLayer#removePolyline(int)}}
* @see JLVectorLayer#removePolyline(int)
*/
public boolean removeMultiPolyline(int id){
@Override
public boolean removeMultiPolyline(int id) {
return removePolyline(id);
}

Expand All @@ -101,17 +112,19 @@ public boolean removeMultiPolyline(int id){
* with the first dimension representing the outer shape and the other
* dimension representing holes in the outer shape!
* Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape!
*
* @param vertices array of {{@link JLLatLng}} points
* @param options see {{@link JLOptions}}
* @param options see {{@link JLOptions}}
* @return Instance of the created {{@link JLPolygon}}
*/
@Override
public JLPolygon addPolygon(JLLatLng[][][] vertices, JLOptions options) {
String latlngs = convertJLLatLngToString(vertices);

String result = engine.executeScript(String.format("addPolygon(%s, '%s', '%s', %d, %b, %b, %f, %f, %f)",
latlngs, convertColorToString(options.getColor()), convertColorToString(options.getFillColor()),
options.getWeight(), options.isStroke(), options.isFill(), options.getOpacity(),
options.getFillOpacity(), options.getSmoothFactor()))
latlngs, convertColorToString(options.getColor()), convertColorToString(options.getFillColor()),
options.getWeight(), options.isStroke(), options.isFill(), options.getOpacity(),
options.getFillOpacity(), options.getSmoothFactor()))
.toString();

int index = Integer.parseInt(result);
Expand All @@ -122,36 +135,42 @@ latlngs, convertColorToString(options.getColor()), convertColorToString(options.

/**
* Drawing polygon overlays on the map with {{@link JLOptions#DEFAULT}} option.
* @see {{@link JLVectorLayer#addMultiPolyline(JLLatLng[][], JLOptions)}}
*
* @see JLVectorLayer#addMultiPolyline(JLLatLng[][], JLOptions)
*/
public JLPolygon addPolygon(JLLatLng[][][] vertices){
@Override
public JLPolygon addPolygon(JLLatLng[][][] vertices) {
return addPolygon(vertices, JLOptions.DEFAULT);
}

/**
* Remove a {{@link JLPolygon}} from the map by id.
*
* @param id of Polygon
* @return {{@link Boolean#TRUE}} if removed successfully
*/
public boolean removePolygon(int id){
@Override
public boolean removePolygon(int id) {
String result = engine.executeScript(String.format("removePolygon(%d)", id))
.toString();
callbackHandler.remove(JLPolygon.class, id);
return Boolean.parseBoolean(result);
}

/**
* Add a {{@link JLCircle}} to the map;
* @param center coordinate of the circle.
* @param radius radius of circle in meter.
* @param options see {{@link JLOptions}}
* @return the instance of created {{@link JLCircle}}
* Add a {@link JLCircle} to the map;
*
* @param center coordinate of the circle.
* @param radius radius of circle in meter.
* @param options see {@link JLOptions}
* @return the instance of created {@link JLCircle}
*/
@Override
public JLCircle addCircle(JLLatLng center, int radius, JLOptions options) {
String result = engine.executeScript(String.format("addCircle([%f, %f], %d, '%s', '%s', %d, %b, %b, %f, %f, %f)",
center.getLat(), center.getLng(), radius, convertColorToString(options.getColor()), convertColorToString(options.getFillColor()),
options.getWeight(), options.isStroke(), options.isFill(), options.getOpacity(),
options.getFillOpacity(), options.getSmoothFactor()))
center.getLat(), center.getLng(), radius, convertColorToString(options.getColor()), convertColorToString(options.getFillColor()),
options.getWeight(), options.isStroke(), options.isFill(), options.getOpacity(),
options.getFillOpacity(), options.getSmoothFactor()))
.toString();

int index = Integer.parseInt(result);
Expand All @@ -161,38 +180,44 @@ public JLCircle addCircle(JLLatLng center, int radius, JLOptions options) {
}

/**
* Add {{@link JLCircle}} to the map with {{@link JLOptions#DEFAULT}} options.
* Default value for radius is {{@link JLProperties#DEFAULT_CIRCLE_RADIUS}}
* @see {{@link JLVectorLayer#addCircle(JLLatLng, int, JLOptions)}}
* Add {{@link JLCircle}} to the map with {@link JLOptions#DEFAULT} options.
* Default value for radius is {@link JLProperties#DEFAULT_CIRCLE_RADIUS}
*
* @see JLVectorLayer#addCircle(JLLatLng, int, JLOptions)
*/
public JLCircle addCircle(JLLatLng center){
@Override
public JLCircle addCircle(JLLatLng center) {
return addCircle(center, JLProperties.DEFAULT_CIRCLE_RADIUS, JLOptions.DEFAULT);
}

/**
* Remove a {{@link JLCircle}} from the map by id.
* Remove a {@link JLCircle} from the map by id.
*
* @param id of Circle
* @return {{@link Boolean#TRUE}} if removed successfully
* @return {@link Boolean#TRUE} if removed successfully
*/
public boolean removeCircle(int id){
@Override
public boolean removeCircle(int id) {
String result = engine.executeScript(String.format("removeCircle(%d)", id))
.toString();
callbackHandler.remove(JLCircle.class, id);
return Boolean.parseBoolean(result);
}

/**
* Add a {{@link JLCircleMarker}} to the map;
* @param center coordinate of the circle.
* @param radius radius of circle in meter.
* @param options see {{@link JLOptions}}
* @return the instance of created {{@link JLCircleMarker}}
* Add a {@link JLCircleMarker} to the map;
*
* @param center coordinate of the circle.
* @param radius radius of circle in meter.
* @param options see {@link JLOptions}
* @return the instance of created {@link JLCircleMarker}
*/
@Override
public JLCircleMarker addCircleMarker(JLLatLng center, int radius, JLOptions options) {
String result = engine.executeScript(String.format("addCircleMarker([%f, %f], %d, '%s', '%s', %d, %b, %b, %f, %f, %f)",
center.getLat(), center.getLng(), radius, convertColorToString(options.getColor()), convertColorToString(options.getFillColor()),
options.getWeight(), options.isStroke(), options.isFill(), options.getOpacity(),
options.getFillOpacity(), options.getSmoothFactor()))
center.getLat(), center.getLng(), radius, convertColorToString(options.getColor()), convertColorToString(options.getFillColor()),
options.getWeight(), options.isStroke(), options.isFill(), options.getOpacity(),
options.getFillOpacity(), options.getSmoothFactor()))
.toString();

int index = Integer.parseInt(result);
Expand All @@ -202,22 +227,24 @@ public JLCircleMarker addCircleMarker(JLLatLng center, int radius, JLOptions opt
}

/**
* Add {{@link JLCircleMarker}} to the map with {{@link JLOptions#DEFAULT}} options.
* Default value for radius is {{@link JLProperties#DEFAULT_CIRCLE_MARKER_RADIUS}}
* Add {@link JLCircleMarker} to the map with {@link JLOptions#DEFAULT} options.
* Default value for radius is {@link JLProperties#DEFAULT_CIRCLE_MARKER_RADIUS}
*
* @see {{@link JLVectorLayer#addCircle(JLLatLng, int, JLOptions)}}
* @see JLVectorLayer#addCircle(JLLatLng, int, JLOptions)
*/
@Override
public JLCircleMarker addCircleMarker(JLLatLng center) {
return addCircleMarker(center, JLProperties.DEFAULT_CIRCLE_MARKER_RADIUS, JLOptions.DEFAULT);
}


/**
* Remove a {{@link JLCircleMarker}} from the map by id.
* Remove a {@link JLCircleMarker} from the map by id.
*
* @param id of Circle
* @return {{@link Boolean#TRUE}} if removed successfully
* @return {@link Boolean#TRUE} if removed successfully
*/
@Override
public boolean removeCircleMarker(int id) {
String result = engine.executeScript(String.format("removeCircleMarker(%d)", id))
.toString();
Expand All @@ -229,37 +256,37 @@ private String convertJLLatLngToString(JLLatLng[] latLngs) {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (JLLatLng latLng : latLngs) {
sb.append(String.format("[%f, %f], ", latLng.getLat(), latLng.getLng()));
sb.append(String.format("%s, ", latLng.toString()));
}
sb.append("]");
return sb.toString();
}

private String convertJLLatLngToString(JLLatLng[][] latLngsList){
private String convertJLLatLngToString(JLLatLng[][] latLngsList) {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (JLLatLng[] latLngs : latLngsList){
for (JLLatLng[] latLngs : latLngsList) {
sb.append(convertJLLatLngToString(latLngs)).append(",");
}
sb.append("]");
return sb.toString();
}

private String convertJLLatLngToString(JLLatLng[][][] latLngsList){
private String convertJLLatLngToString(JLLatLng[][][] latLngList) {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (JLLatLng[][] latLngs : latLngsList){
sb.append(convertJLLatLngToString(latLngs)).append(",");
for (JLLatLng[][] latLng2DArray : latLngList) {
sb.append(convertJLLatLngToString(latLng2DArray)).append(",");
}
sb.append("]");
return sb.toString();
}

private String convertColorToString(Color c){
int r = (int)Math.round(c.getRed() * 255.0);
int g = (int)Math.round(c.getGreen() * 255.0);
int b = (int)Math.round(c.getBlue() * 255.0);
int a = (int)Math.round(c.getOpacity() * 255.0);
private String convertColorToString(Color c) {
int r = (int) Math.round(c.getRed() * 255.0);
int g = (int) Math.round(c.getGreen() * 255.0);
int b = (int) Math.round(c.getBlue() * 255.0);
int a = (int) Math.round(c.getOpacity() * 255.0);
return String.format("#%02x%02x%02x%02x", r, g, b, a);
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/github/makbn/jlmap/model/JLCircle.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* A class for drawing circle overlays on a map
* by: Mehdi Akbarian Rastaghi (@makbn)
* @author Mehdi Akbarian Rastaghi (@makbn)
*/
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* A circle of a fixed size with radius specified in pixels.
* by: Mehdi Akbarian Rastaghi (@makbn)
* @author Mehdi Akbarian Rastaghi (@makbn)
*/
@Getter
@Setter
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/makbn/jlmap/model/JLMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/**
* JLMarker is used to display clickable/draggable icons on the map!
* by: Mehdi Akbarian Rastaghi (@makbn)
* @author Mehdi Akbarian Rastaghi (@makbn)
*/
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* A class for drawing polyline overlays on a map
* by: Mehdi Akbarian Rastaghi (@makbn)
* @author Mehdi Akbarian Rastaghi (@makbn)
*/
@Getter
@Setter
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/makbn/jlmap/model/JLObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import io.github.makbn.jlmap.listener.OnJLObjectActionListener;

/**
* by: Mehdi Akbarian Rastaghi (@makbn)
* Represents basic object classes for interacting with Leaflet
* @author Mehdi Akbarian Rastaghi (@makbn)
*/
public abstract class JLObject<T extends JLObject> {
public abstract class JLObject<T extends JLObject<?>> {
private OnJLObjectActionListener<T> listener;

public OnJLObjectActionListener<T> getOnActionListener() {
Expand Down
Loading

0 comments on commit f5002fa

Please sign in to comment.