Skip to content

Commit bee8770

Browse files
committed
Add sorting option to Marker and MarkerSet
1 parent 1d0d63f commit bee8770

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

src/main/java/de/bluecolored/bluemap/api/markers/Marker.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ public abstract class Marker {
4444
private final String type;
4545
private String label;
4646
private Vector3d position;
47+
private int sorting;
4748

4849
public Marker(String type, String label, Vector3d position) {
4950
this.type = Objects.requireNonNull(type, "type cannot be null");
5051
this.label = Objects.requireNonNull(label, "label cannot be null");
5152
this.position = Objects.requireNonNull(position, "position cannot be null");
53+
this.sorting = 0;
5254
}
5355

5456
/**
@@ -107,6 +109,28 @@ public void setPosition(double x, double y, double z) {
107109
setPosition(new Vector3d(x, y, z));
108110
}
109111

112+
/**
113+
* Returns the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
114+
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
115+
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
116+
* This value defaults to 0.
117+
* @return This markers sorting-value
118+
*/
119+
public int getSorting() {
120+
return sorting;
121+
}
122+
123+
/**
124+
* Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
125+
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
126+
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
127+
* This value defaults to 0.
128+
* @param sorting the new sorting-value for this marker
129+
*/
130+
public void setSorting(int sorting) {
131+
this.sorting = sorting;
132+
}
133+
110134
@Override
111135
public boolean equals(Object o) {
112136
if (this == o) return true;
@@ -131,6 +155,7 @@ public static abstract class Builder<T extends Marker, B extends Marker.Builder<
131155

132156
String label;
133157
Vector3d position;
158+
Integer sorting;
134159

135160
/**
136161
* Sets the label of the {@link Marker}.
@@ -164,6 +189,18 @@ public B position(double x, double y, double z) {
164189
return position(new Vector3d(x, y, z));
165190
}
166191

192+
/**
193+
* Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
194+
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
195+
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
196+
* This value defaults to 0.
197+
* @param sorting the new sorting-value for this marker
198+
*/
199+
public B sorting(Integer sorting) {
200+
this.sorting = sorting;
201+
return self();
202+
}
203+
167204
/**
168205
* Creates a new {@link Marker} with the current builder-settings
169206
* @return The new {@link Marker}-instance
@@ -173,6 +210,7 @@ public B position(double x, double y, double z) {
173210
T build(T marker) {
174211
if (label != null) marker.setLabel(label);
175212
if (position != null) marker.setPosition(position);
213+
if (sorting != null) marker.setSorting(sorting);
176214
return marker;
177215
}
178216

src/main/java/de/bluecolored/bluemap/api/markers/MarkerSet.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class MarkerSet {
3838

3939
private String label;
4040
private boolean toggleable, defaultHidden;
41+
private int sorting;
4142
private final ConcurrentHashMap<String, Marker> markers;
4243

4344
/**
@@ -56,10 +57,7 @@ private MarkerSet() {
5657
* @see #setLabel(String)
5758
*/
5859
public MarkerSet(String label) {
59-
this.label = Objects.requireNonNull(label);
60-
this.toggleable = true;
61-
this.defaultHidden = false;
62-
this.markers = new ConcurrentHashMap<>();
60+
this(label, true, false);
6361
}
6462

6563
/**
@@ -77,6 +75,7 @@ public MarkerSet(String label, boolean toggleable, boolean defaultHidden) {
7775
this.label = Objects.requireNonNull(label);
7876
this.toggleable = toggleable;
7977
this.defaultHidden = defaultHidden;
78+
this.sorting = 0;
8079
this.markers = new ConcurrentHashMap<>();
8180
}
8281

@@ -149,6 +148,28 @@ public void setDefaultHidden(boolean defaultHidden) {
149148
this.defaultHidden = defaultHidden;
150149
}
151150

151+
/**
152+
* Returns the sorting-value that will be used by the webapp to sort the marker-sets.<br>
153+
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
154+
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
155+
* This value defaults to 0.
156+
* @return This marker-sets sorting-value
157+
*/
158+
public int getSorting() {
159+
return sorting;
160+
}
161+
162+
/**
163+
* Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).<br>
164+
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
165+
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
166+
* This value defaults to 0.
167+
* @param sorting the new sorting-value for this marker-set
168+
*/
169+
public void setSorting(int sorting) {
170+
this.sorting = sorting;
171+
}
172+
152173
/**
153174
* Getter for a (modifiable) {@link Map} of all {@link Marker}s in this {@link MarkerSet}.
154175
* The keys of the map are the id's of the {@link Marker}s.
@@ -220,6 +241,7 @@ public static class Builder {
220241

221242
private String label;
222243
private Boolean toggleable, defaultHidden;
244+
Integer sorting;
223245

224246
/**
225247
* Sets the label of the {@link MarkerSet}.
@@ -262,6 +284,18 @@ public Builder defaultHidden(Boolean defaultHidden) {
262284
return this;
263285
}
264286

287+
/**
288+
* Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).<br>
289+
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
290+
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
291+
* This value defaults to 0.
292+
* @param sorting the new sorting-value for this marker-set
293+
*/
294+
public Builder sorting(Integer sorting) {
295+
this.sorting = sorting;
296+
return this;
297+
}
298+
265299
/**
266300
* Creates a new {@link MarkerSet} with the current builder-settings.<br>
267301
* The minimum required settings to build this marker-set are:
@@ -276,6 +310,7 @@ public MarkerSet build() {
276310
);
277311
if (toggleable != null) markerSet.setToggleable(toggleable);
278312
if (defaultHidden != null) markerSet.setDefaultHidden(defaultHidden);
313+
if (sorting != null) markerSet.setSorting(sorting);
279314
return markerSet;
280315
}
281316

0 commit comments

Comments
 (0)