Skip to content

Commit af1536a

Browse files
committed
implemented image builder
Signed-off-by: makbn <mehdi74akbarian@gmail.com>
1 parent 0e5d0de commit af1536a

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.github.makbn.jlmap.model.builder;
2+
3+
import io.github.makbn.jlmap.model.JLBounds;
4+
import io.github.makbn.jlmap.model.JLImageOverlay;
5+
import lombok.AccessLevel;
6+
import lombok.experimental.FieldDefaults;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
@FieldDefaults(level = AccessLevel.PRIVATE)
12+
public class JLImageOverlayBuilder extends JLObjectBuilder<JLImageOverlay, JLImageOverlayBuilder> {
13+
String imageUrl;
14+
List<double[]> bounds = new ArrayList<>();
15+
16+
public JLImageOverlayBuilder setImageUrl(String imageUrl) {
17+
this.imageUrl = imageUrl;
18+
return this;
19+
}
20+
21+
/**
22+
* Set bounds using two double arrays: [lat, lng] for southwest and northeast corners.
23+
*/
24+
public JLImageOverlayBuilder setBounds(List<double[]> bounds) {
25+
if (bounds == null || bounds.size() != 2)
26+
throw new IllegalArgumentException("Bounds must have exactly two coordinates (SW, NE)");
27+
this.bounds = bounds;
28+
return this;
29+
}
30+
31+
@Override
32+
protected String getElementVarName() {
33+
return uuid;
34+
}
35+
36+
@Override
37+
protected String getElementType() {
38+
return JLImageOverlay.class.getSimpleName().toLowerCase();
39+
}
40+
41+
@Override
42+
public String buildJsElement() {
43+
if (imageUrl == null || bounds.size() != 2) return "";
44+
String boundsJs = String.format("[[%f, %f], [%f, %f]]", bounds.get(0)[0], bounds.get(0)[1], bounds.get(1)[0], bounds.get(1)[1]);
45+
return String.format("""
46+
let %1$s = L.imageOverlay('%2$s', %3$s, { %4$s });
47+
this.%1$s = %1$s;
48+
%1$s.uuid = '%5$s';
49+
// callback start
50+
%6$s
51+
// callback end
52+
%1$s.addTo(this.map);
53+
""",
54+
getElementVarName(),
55+
imageUrl,
56+
boundsJs,
57+
renderOptions(),
58+
getElementVarName(),
59+
renderCallbacks()
60+
);
61+
}
62+
63+
@Override
64+
public JLImageOverlay buildJLObject() {
65+
return JLImageOverlay.builder()
66+
.id(uuid)
67+
.imageUrl(imageUrl)
68+
.bounds(JLBounds.builder().build())
69+
.options(jlOptions)
70+
.transport(transporter)
71+
.build();
72+
}
73+
}

0 commit comments

Comments
 (0)