Skip to content

Commit 59380c0

Browse files
committed
Added basic support for CRS + a demo
1 parent 17ee408 commit 59380c0

File tree

7 files changed

+167
-3
lines changed

7 files changed

+167
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 4.2.0
22
* Fixed some invalid built JavaScript commands #330
3+
* Add basic support for CRS #333
34

45
## 4.1.1
56
* ⚠️ GroupId changed from ``com.xdev-software`` to ``software.xdev``

vaadin-maps-leaflet-flow-demo/src/main/java/software/xdev/vaadin/maps/leaflet/flow/DemoView.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import software.xdev.vaadin.maps.leaflet.flow.demo.FreeingUpResourceBenchmarkDemo;
1818
import software.xdev.vaadin.maps.leaflet.flow.demo.InitialResizeDemo;
1919
import software.xdev.vaadin.maps.leaflet.flow.demo.MinimalisticDemo;
20+
import software.xdev.vaadin.maps.leaflet.flow.demo.NotOfThisEarthDemo;
2021

2122

2223
@PageTitle("Leaflet + Vaadin demos")
@@ -67,6 +68,11 @@ protected void onAttach(final AttachEvent attachEvent)
6768
"Complex",
6869
"A complex example with various leaflet components and methods"
6970
),
71+
new Example(
72+
NotOfThisEarthDemo.NAV,
73+
"Not of this earth",
74+
"Displays a map that is not from this earth"
75+
),
7076
new Example(
7177
FreeingUpResourceBenchmarkDemo.NAV,
7278
"Freeing up resources Benchmark",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package software.xdev.vaadin.maps.leaflet.flow.demo;
2+
3+
import java.util.Map;
4+
5+
import com.vaadin.flow.component.html.Anchor;
6+
import com.vaadin.flow.router.Route;
7+
8+
import software.xdev.vaadin.maps.leaflet.MapContainer;
9+
import software.xdev.vaadin.maps.leaflet.basictypes.LLatLng;
10+
import software.xdev.vaadin.maps.leaflet.basictypes.LLatLngBounds;
11+
import software.xdev.vaadin.maps.leaflet.crs.LCRS;
12+
import software.xdev.vaadin.maps.leaflet.layer.raster.LImageOverlay;
13+
import software.xdev.vaadin.maps.leaflet.layer.ui.LMarker;
14+
import software.xdev.vaadin.maps.leaflet.layer.vector.LPolyline;
15+
import software.xdev.vaadin.maps.leaflet.map.LMap;
16+
import software.xdev.vaadin.maps.leaflet.map.LMapOptions;
17+
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
18+
import software.xdev.vaadin.maps.leaflet.registry.LDefaultComponentManagementRegistry;
19+
20+
21+
@Route(NotOfThisEarthDemo.NAV)
22+
@SuppressWarnings("checkstyle:MagicNumber")
23+
public class NotOfThisEarthDemo extends AbstractDemo
24+
{
25+
public static final String NAV = "not-of-this-earth";
26+
27+
private final LComponentManagementRegistry reg;
28+
29+
public NotOfThisEarthDemo()
30+
{
31+
// Let the view use 100% of the site
32+
this.setSizeFull();
33+
34+
this.add(new Anchor("https://leafletjs.com/examples/crs-simple/crs-simple.html", "Based on this example"));
35+
36+
// Create the registry which is needed so that components can be reused and their methods invoked
37+
// Note: You normally don't need to invoke any methods of the registry and just hand it over to the components
38+
this.reg = new LDefaultComponentManagementRegistry(this);
39+
40+
this.buildMap();
41+
}
42+
43+
private void buildMap()
44+
{
45+
// Create and add the MapContainer (which contains the map) to the UI
46+
final MapContainer mapContainer = new MapContainer(
47+
this.reg,
48+
new LMapOptions()
49+
.withCrs(LCRS.Defined.SIMPLE)
50+
.withMinZoom(-3));
51+
mapContainer.setSizeFull();
52+
this.add(mapContainer);
53+
54+
final LMap map = mapContainer.getlMap();
55+
56+
new LImageOverlay(
57+
this.reg,
58+
"uqm_map_full.png",
59+
new LLatLngBounds(
60+
this.reg,
61+
this.xy(-25, -26.5),
62+
this.xy(1023, 1021.5))
63+
).addTo(map);
64+
65+
final LLatLng cordSol = this.xy(175.2, 145);
66+
final LLatLng cordDeneb = this.xy(218.7, 8.3);
67+
Map.ofEntries(
68+
Map.entry(cordSol, "Sol"),
69+
Map.entry(this.xy(41.6, 130.1), "Mizar"),
70+
Map.entry(this.xy(13.4, 56.5), "Krueger-Z"),
71+
Map.entry(cordDeneb, "Deneb")
72+
).forEach((cords, text) -> new LMarker(this.reg, cords)
73+
.bindPopup(text)
74+
.addTo(map));
75+
76+
new LPolyline(this.reg, cordSol, cordDeneb)
77+
.addTo(map);
78+
79+
map.setView(this.xy(300, 140), 1);
80+
}
81+
82+
private LLatLng xy(final double x, final double y)
83+
{
84+
return new LLatLng(this.reg, y, x);
85+
}
86+
}
307 KB
Loading

vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/MapContainer.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import software.xdev.vaadin.maps.leaflet.basictypes.LLatLngBounds;
3333
import software.xdev.vaadin.maps.leaflet.map.LMap;
34+
import software.xdev.vaadin.maps.leaflet.map.LMapOptions;
3435
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
3536

3637

@@ -49,7 +50,29 @@ public class MapContainer extends Composite<Div> implements HasSize, HasStyle, H
4950

5051
public MapContainer(final LComponentManagementRegistry reg)
5152
{
52-
this(reg, null);
53+
this(reg, (LMapOptions)null);
54+
}
55+
56+
public MapContainer(
57+
final LComponentManagementRegistry reg,
58+
final LMapOptions options)
59+
{
60+
this(reg, options, null);
61+
}
62+
63+
/**
64+
* @param afterInitialResize This is called after the map was initially resized/is ready.
65+
* <p/>
66+
* This is ONLY required when calling certain methods like e.g.
67+
* {@link LMap#fitBounds(LLatLngBounds)} instantly after the map is created.
68+
* <p/>
69+
* For performance reasons it's highly recommended to only use this when required.
70+
*/
71+
public MapContainer(
72+
final LComponentManagementRegistry reg,
73+
final Consumer<LMap> afterInitialResize)
74+
{
75+
this(reg, null, afterInitialResize);
5376
}
5477

5578
/**
@@ -62,13 +85,14 @@ public MapContainer(final LComponentManagementRegistry reg)
6285
*/
6386
public MapContainer(
6487
final LComponentManagementRegistry reg,
88+
final LMapOptions options,
6589
final Consumer<LMap> afterInitialResize)
6690
{
6791
this.afterInitialResize = afterInitialResize;
6892
this.getContent().setSizeFull();
6993
this.fixZIndex();
7094

71-
this.lMap = new LMap(reg, this.getContent());
95+
this.lMap = new LMap(reg, this.getContent(), options);
7296
this.fixInitialSizeAfterCreation();
7397
}
7498

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package software.xdev.vaadin.maps.leaflet.crs;
2+
3+
import software.xdev.vaadin.maps.leaflet.base.RawString;
4+
5+
6+
/**
7+
* @apiNote CRS can't be constructed
8+
* @see <a href="https://leafletjs.com/reference.html#crs">Leaflet docs</a>
9+
*/
10+
public final class LCRS
11+
{
12+
public static final class Defined
13+
{
14+
public static final RawString EARTH = new RawString("L.CRS.Earth");
15+
16+
public static final RawString EPSG3395 = new RawString("L.CRS.EPSG3395");
17+
public static final RawString EPSG3857 = new RawString("L.CRS.EPSG3857");
18+
public static final RawString EPSG4326 = new RawString("L.CRS.EPSG4326");
19+
public static final RawString BASE = new RawString("L.CRS.Base");
20+
public static final RawString SIMPLE = new RawString("L.CRS.Simple");
21+
22+
private Defined()
23+
{
24+
}
25+
}
26+
27+
private LCRS()
28+
{
29+
}
30+
}

vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/map/LMapOptions.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public class LMapOptions implements LComponentOptions<LMapOptions>
5959
// Boolean|String
6060
private Object touchZoom;
6161
private Boolean bounceAtZoomLimits;
62-
// CRS is currently not implemented - the default used one should be sufficient
62+
63+
private Object crs;
6364
private LLatLng center;
6465
private Integer zoom;
6566
private Integer minZoom;
@@ -473,6 +474,22 @@ public LMapOptions withBounceAtZoomLimits(final Boolean bounceAtZoomLimits)
473474
return this.self();
474475
}
475476

477+
public Object getCrs()
478+
{
479+
return this.crs;
480+
}
481+
482+
public void setCrs(final Object crs)
483+
{
484+
this.crs = crs;
485+
}
486+
487+
public LMapOptions withCrs(final Object crs)
488+
{
489+
this.setCrs(crs);
490+
return this.self();
491+
}
492+
476493
public LLatLng getCenter()
477494
{
478495
return this.center;

0 commit comments

Comments
 (0)