Skip to content

Commit 89c0a7e

Browse files
committed
added getTransporter to JLVaadinLayer and used as default transport provider
Signed-off-by: makbn <mehdi74akbarian@gmail.com>
1 parent af1536a commit 89c0a7e

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

jlmap-vaadin/src/main/java/io/github/makbn/jlmap/vaadin/layer/JLVaadinGeoJsonLayer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public boolean removeGeoJson(@NonNull String id) {
7575
private JLGeoJson addGeoJson(String geoJson) {
7676
String elementUniqueName = getElementUniqueName(JLGeoJson.class, idGenerator.incrementAndGet());
7777
JLGeoJsonObjectBuilder builder = new JLGeoJsonObjectBuilder()
78+
.setTransporter(getTransporter())
7879
.setUuid(elementUniqueName)
7980
.setGeoJson(geoJson);
8081
engine.executeScript(builder.buildJsElement());

jlmap-vaadin/src/main/java/io/github/makbn/jlmap/vaadin/layer/JLVaadinLayer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
import com.vaadin.flow.component.page.PendingJavaScriptResult;
44
import io.github.makbn.jlmap.JLMapCallbackHandler;
5+
import io.github.makbn.jlmap.engine.JLTransport;
56
import io.github.makbn.jlmap.engine.JLWebEngine;
67
import io.github.makbn.jlmap.layer.leaflet.LeafletLayer;
78
import io.github.makbn.jlmap.model.JLObject;
9+
import io.github.makbn.jlmap.vaadin.engine.JLVaadinTransporter;
810
import lombok.AccessLevel;
911
import lombok.NonNull;
1012
import lombok.experimental.FieldDefaults;
1113
import org.jetbrains.annotations.NotNull;
1214

1315
import java.util.UUID;
16+
import java.util.function.Function;
1417

1518
/**
1619
* Represents the basic layer.
@@ -37,4 +40,13 @@ protected JLVaadinLayer(JLWebEngine<PendingJavaScriptResult> engine, JLMapCallba
3740
protected final String removeLayerWithUUID(@NonNull String uuid) {
3841
return String.format("this.map.removeLayer(this.%s)", uuid);
3942
}
43+
44+
protected @NotNull JLVaadinTransporter getTransporter() {
45+
return new JLVaadinTransporter() {
46+
@Override
47+
public Function<JLTransport, PendingJavaScriptResult> clientToServerTransport() {
48+
return transport -> engine.executeScript(transport.function());
49+
}
50+
};
51+
}
4052
}

jlmap-vaadin/src/main/java/io/github/makbn/jlmap/vaadin/layer/JLVaadinUiLayer.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22

33
import com.vaadin.flow.component.page.PendingJavaScriptResult;
44
import io.github.makbn.jlmap.JLMapCallbackHandler;
5-
import io.github.makbn.jlmap.engine.JLTransport;
65
import io.github.makbn.jlmap.engine.JLWebEngine;
76
import io.github.makbn.jlmap.layer.leaflet.LeafletUILayerInt;
87
import io.github.makbn.jlmap.listener.JLAction;
9-
import io.github.makbn.jlmap.model.JLLatLng;
10-
import io.github.makbn.jlmap.model.JLMarker;
11-
import io.github.makbn.jlmap.model.JLOptions;
12-
import io.github.makbn.jlmap.model.JLPopup;
8+
import io.github.makbn.jlmap.model.*;
9+
import io.github.makbn.jlmap.model.builder.JLImageOverlayBuilder;
1310
import io.github.makbn.jlmap.model.builder.JLMarkerBuilder;
1411
import io.github.makbn.jlmap.model.builder.JLPopupBuilder;
15-
import io.github.makbn.jlmap.vaadin.engine.JLVaadinTransporter;
1612
import lombok.AccessLevel;
1713
import lombok.experimental.FieldDefaults;
1814
import lombok.extern.slf4j.Slf4j;
19-
import org.jetbrains.annotations.NotNull;
2015

16+
import java.util.List;
2117
import java.util.concurrent.atomic.AtomicInteger;
22-
import java.util.function.Function;
2318

2419
/**
2520
* Represents the UI layer on Leaflet map.
@@ -154,12 +149,24 @@ public boolean removePopup(String id) {
154149
return true;
155150
}
156151

157-
private @NotNull JLVaadinTransporter getTransporter() {
158-
return new JLVaadinTransporter() {
159-
@Override
160-
public Function<JLTransport, PendingJavaScriptResult> clientToServerTransport() {
161-
return transport -> engine.executeScript(transport.function());
162-
}
163-
};
152+
@Override
153+
public JLImageOverlay addImage(JLBounds bounds, String imageUrl, JLOptions options) {
154+
String elementUniqueName = getElementUniqueName(JLPopup.class, idGenerator.incrementAndGet());
155+
156+
JLImageOverlayBuilder imageBuilder = new JLImageOverlayBuilder()
157+
.setUuid(elementUniqueName)
158+
.setImageUrl(imageUrl)
159+
.setBounds(List.of(new double[]{bounds.getSouthWest().getLat(), bounds.getSouthWest().getLng()},
160+
new double[]{bounds.getNorthEast().getLat(), bounds.getNorthEast().getLng()}))
161+
.setTransporter(getTransporter())
162+
.withOptions(options)
163+
.withCallbacks(jlCallbackBuilder -> {
164+
165+
});
166+
167+
engine.executeScript(imageBuilder.buildJsElement());
168+
var imageOverlay = imageBuilder.buildJLObject();
169+
callbackHandler.addJLObject(elementUniqueName, imageOverlay);
170+
return imageOverlay;
164171
}
165172
}

jlmap-vaadin/src/main/java/io/github/makbn/jlmap/vaadin/layer/JLVaadinVectorLayer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.vaadin.flow.component.page.PendingJavaScriptResult;
44
import io.github.makbn.jlmap.JLMapCallbackHandler;
5+
import io.github.makbn.jlmap.JLProperties;
56
import io.github.makbn.jlmap.engine.JLWebEngine;
67
import io.github.makbn.jlmap.layer.leaflet.LeafletVectorLayerInt;
78
import io.github.makbn.jlmap.listener.JLAction;
@@ -55,7 +56,7 @@ public JLPolyline addPolyline(JLLatLng[] vertices, JLOptions options) {
5556

5657
var polylineBuilder = new JLPolylineBuilder()
5758
.setUuid(elementUniqueName)
58-
.setTransporter(() -> transport -> {})
59+
.setTransporter(getTransporter())
5960
.withOptions(options)
6061
.withCallbacks(jlCallbackBuilder -> {
6162
jlCallbackBuilder.on(JLAction.MOVE);
@@ -121,7 +122,7 @@ public JLMultiPolyline addMultiPolyline(JLLatLng[][] vertices,
121122

122123
var multiPolylineBuilder = new JLMultiPolylineBuilder()
123124
.setUuid(elementUniqueName)
124-
.setTransporter(() -> transport -> {})
125+
.setTransporter(getTransporter())
125126
.withOptions(options)
126127
.withCallbacks(jlCallbackBuilder -> {
127128
jlCallbackBuilder.on(JLAction.MOVE);
@@ -176,7 +177,7 @@ public JLPolygon addPolygon(JLLatLng[][][] vertices, JLOptions options) {
176177

177178
var polygonBuilder = new JLPolygonBuilder()
178179
.setUuid(elementUniqueName)
179-
.setTransporter(() -> transport -> {})
180+
.setTransporter(getTransporter())
180181
.withOptions(options)
181182
.withCallbacks(jlCallbackBuilder -> {
182183
jlCallbackBuilder.on(JLAction.MOVE);
@@ -249,7 +250,7 @@ public JLCircle addCircle(JLLatLng center, int radius, JLOptions options) {
249250
.setLat(center.getLat())
250251
.setLng(center.getLng())
251252
.setRadius(radius)
252-
.setTransporter(() -> transport -> {})
253+
.setTransporter(getTransporter())
253254
.withOptions(options)
254255
.withCallbacks(jlCallbackBuilder -> {
255256
jlCallbackBuilder.on(JLAction.MOVE);
@@ -265,13 +266,13 @@ public JLCircle addCircle(JLLatLng center, int radius, JLOptions options) {
265266

266267
/**
267268
* Drawing circle overlays on the map with {@link JLOptions#DEFAULT}
268-
* options.
269+
* options and {@link JLProperties#DEFAULT_CIRCLE_RADIUS}.
269270
*
270271
* @see JLVaadinVectorLayer#addCircle(JLLatLng, int, JLOptions)
271272
*/
272273
@Override
273274
public JLCircle addCircle(JLLatLng center) {
274-
return addCircle(center, 1000, JLOptions.DEFAULT);
275+
return addCircle(center, JLProperties.DEFAULT_CIRCLE_RADIUS, JLOptions.DEFAULT);
275276
}
276277

277278
/**
@@ -310,7 +311,7 @@ public JLCircleMarker addCircleMarker(JLLatLng center, int radius,
310311
.setLat(center.getLat())
311312
.setLng(center.getLng())
312313
.setRadius(radius)
313-
.setTransporter(() -> transport -> {})
314+
.setTransporter(getTransporter())
314315
.withOptions(options)
315316
.withCallbacks(jlCallbackBuilder -> {
316317
jlCallbackBuilder.on(JLAction.MOVE);

0 commit comments

Comments
 (0)