Skip to content

Commit 493a63d

Browse files
committed
implemented marker specific methods using transporter
Signed-off-by: makbn <[email protected]>
1 parent e1d6ee5 commit 493a63d

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

jlmap-api/src/main/java/io/github/makbn/jlmap/model/JLMarker.java

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

33

4+
import io.github.makbn.jlmap.engine.JLTransport;
45
import io.github.makbn.jlmap.engine.JLTransporter;
56
import io.github.makbn.jlmap.listener.JLAction;
67
import lombok.AccessLevel;
@@ -33,9 +34,24 @@ public final class JLMarker extends JLObject<JLMarker> {
3334
*/
3435
@NonFinal
3536
JLLatLng latLng;
37+
/**
38+
* By default, marker images zIndex is set automatically based on its latitude.
39+
* Use this option if you want to put the marker on top of all others (or below),
40+
* specifying a high value like 1000 (or high negative value, respectively).
41+
*/
42+
@NonFinal
43+
int zIndexOffset = 0;
44+
/**
45+
* The opacity of the marker.
46+
*/
47+
@NonFinal
48+
double opacity = 1.0;
49+
50+
@NonFinal
51+
JLIcon icon;
3652

3753
@Builder
38-
public JLMarker(String id, String text, JLLatLng latLng, JLTransporter transport) {
54+
public JLMarker(String id, String text, JLLatLng latLng, JLTransporter<?> transport) {
3955
super(transport);
4056
this.id = id;
4157
this.text = text;
@@ -52,4 +68,66 @@ public void update(Object... params) {
5268
latLng = (JLLatLng) params[1];
5369
}
5470
}
71+
72+
@Override
73+
public JLMarker self() {
74+
return this;
75+
}
76+
77+
/**
78+
* Changes the marker position to the given point.
79+
*
80+
* @param latLng new position of the marker.
81+
* @return the current instance of JLMarker.
82+
*/
83+
public JLMarker setLatLng(JLLatLng latLng) {
84+
getTransport().execute(new JLTransport(this,
85+
String.format("this.%s.setLatLng([%f, %f]);", getId(), latLng.getLat(), latLng.getLng())));
86+
this.latLng = latLng;
87+
return this;
88+
}
89+
90+
/**
91+
* By default, marker images zIndex is set automatically based on its latitude. Use this option if you want
92+
* to put the marker on top of all others (or below), specifying a high value like 1000 (or high
93+
* negative value, respectively).
94+
* Read more <a href="https://leafletjs.com/reference.html#marker-zindexoffset">here</a>!
95+
*
96+
* @param offset new zIndex offset of the marker.
97+
* @return the current instance of JLMarker.
98+
*/
99+
public JLMarker setZIndexOffset(int offset) {
100+
getTransport().execute(new JLTransport(this,
101+
String.format("this.%s.setZIndexOffset(%d);", getId(), offset)));
102+
this.zIndexOffset = offset;
103+
return this;
104+
}
105+
106+
/**
107+
* Changes the marker opacity.
108+
* Read more <a href="https://leafletjs.com/reference.html#marker-opacity">here</a>!
109+
*
110+
* @param opacity value between 0.0 and 1.0.
111+
* @return the current instance of JLMarker.
112+
*/
113+
public JLMarker setOpacity(double opacity) {
114+
getTransport().execute(new JLTransport(this,
115+
String.format("this.%s.setOpacity(%f);", getId(), opacity)));
116+
this.opacity = opacity;
117+
return this;
118+
}
119+
120+
/**
121+
* Changes the marker icon.
122+
*
123+
* @param icon new icon of the marker.
124+
* Read more <a href="https://leafletjs.com/reference.html#marker-seticon">here</a>!
125+
* @return the current instance of JLMarker.
126+
*/
127+
public JLMarker setIcon(JLIcon icon) {
128+
getTransport().execute(new JLTransport(this,
129+
String.format("this.%s.setIcon(%s);", getId(), icon)));
130+
this.icon = icon;
131+
return this;
132+
}
55133
}

0 commit comments

Comments
 (0)