Skip to content

Commit 0813507

Browse files
committed
Add Geoman + Refactor plugins
1 parent 099ebad commit 0813507

File tree

34 files changed

+2387
-93
lines changed

34 files changed

+2387
-93
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
77
* Introduced support for Leaflet plugins #307
88
* Plugins can be installed from ``software.xdev.vaadin.maps-leaflet.plugins:<artifactId>``
9-
* The following [plugins](./plugins/) are available:
9+
* The following [plugins](./plugins/) are currently available:
10+
* geoman
1011
* leaflet-markercluster
1112
* maplibre-gl-leaflet
1213
* You can also use the [``bom``](./bom/) for easier dependency management

bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
<artifactId>flow</artifactId>
5454
<version>5.0.0-SNAPSHOT</version>
5555
</dependency>
56+
<dependency>
57+
<groupId>software.xdev.vaadin.maps-leaflet.plugins</groupId>
58+
<artifactId>geoman</artifactId>
59+
<version>5.0.0-SNAPSHOT</version>
60+
</dependency>
5661
<dependency>
5762
<groupId>software.xdev.vaadin.maps-leaflet.plugins</groupId>
5863
<artifactId>leaflet-markercluster</artifactId>

flow-demo/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
<artifactId>flow</artifactId>
9999
<version>${project.version}</version>
100100
</dependency>
101+
<dependency>
102+
<groupId>software.xdev.vaadin.maps-leaflet.plugins</groupId>
103+
<artifactId>geoman</artifactId>
104+
<version>${project.version}</version>
105+
</dependency>
101106
<dependency>
102107
<groupId>software.xdev.vaadin.maps-leaflet.plugins</groupId>
103108
<artifactId>leaflet-markercluster</artifactId>

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
@@ -23,6 +23,7 @@
2323
import software.xdev.vaadin.maps.leaflet.flow.demo.MultiLayerWithPyramidDemo;
2424
import software.xdev.vaadin.maps.leaflet.flow.demo.NotOfThisEarthDemo;
2525
import software.xdev.vaadin.maps.leaflet.flow.demo.WatermarkControlDemo;
26+
import software.xdev.vaadin.maps.leaflet.flow.demo.plugins.GeomanDemo;
2627
import software.xdev.vaadin.maps.leaflet.flow.demo.plugins.LeafletMarkerClusterDemo;
2728
import software.xdev.vaadin.maps.leaflet.flow.demo.plugins.MaplibreGLDemo;
2829

@@ -118,6 +119,11 @@ protected void onAttach(final AttachEvent attachEvent)
118119
MaplibreGLDemo.NAV,
119120
"Plugin: MapLibre GL Leaflet",
120121
"Showcases how vector tile servers can be used with MapLibre GL Leaflet"
122+
),
123+
new Example(
124+
GeomanDemo.NAV,
125+
"Plugin: leaflet-geoman",
126+
"Showcases how to created, edit, draw, cut, drag, cut, ... layers"
121127
)
122128
));
123129
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package software.xdev.vaadin.maps.leaflet.flow.demo.plugins;
2+
3+
import com.vaadin.flow.component.button.Button;
4+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
5+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
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.geoman.LTextOptions;
11+
import software.xdev.vaadin.maps.leaflet.geoman.map.LMapPM;
12+
import software.xdev.vaadin.maps.leaflet.layer.raster.LTileLayer;
13+
import software.xdev.vaadin.maps.leaflet.layer.ui.LMarker;
14+
import software.xdev.vaadin.maps.leaflet.map.LMap;
15+
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
16+
import software.xdev.vaadin.maps.leaflet.registry.LDefaultComponentManagementRegistry;
17+
18+
19+
@Route(GeomanDemo.NAV)
20+
@SuppressWarnings("checkstyle:MagicNumber")
21+
public class GeomanDemo extends VerticalLayout
22+
{
23+
public static final String NAV = "/geoman";
24+
25+
public GeomanDemo()
26+
{
27+
// Let the view use 100% of the site
28+
this.setSizeFull();
29+
30+
// Create the registry which is needed so that components can be reused and their methods invoked
31+
// Note: You normally don't need to invoke any methods of the registry and just hand it over to the components
32+
final LComponentManagementRegistry reg = new LDefaultComponentManagementRegistry(this);
33+
34+
// Create and add the MapContainer (which contains the map) to the UI
35+
final MapContainer mapContainer = new MapContainer(reg);
36+
mapContainer.setSizeFull();
37+
this.add(mapContainer);
38+
39+
final LMap map = mapContainer.getlMap();
40+
41+
// Add a (default) TileLayer so that we can see something on the map
42+
map.addLayer(LTileLayer.createDefaultForOpenStreetMapTileServer(reg));
43+
44+
// Set what part of the world should be shown
45+
map.setView(new LLatLng(reg, 49.6751, 12.1607), 17);
46+
47+
// Create a new marker
48+
new LMarker(reg, new LLatLng(reg, 49.6756, 12.1610))
49+
// Bind a popup which is displayed when clicking the marker
50+
.bindPopup("XDEV Software")
51+
// Add it to the map
52+
.addTo(map);
53+
54+
// Add Geoman Controls
55+
final LMapPM lMapPM = new LMapPM(map);
56+
lMapPM.addControls();
57+
58+
final HorizontalLayout hlButtons = new HorizontalLayout();
59+
this.add(hlButtons);
60+
61+
final Button btnText = new Button(
62+
"Add text", ev -> lMapPM.enableDrawText(new LTextOptions()
63+
.withText("Some text")
64+
.withTextMarkerCentered(true)));
65+
hlButtons.add(btnText);
66+
}
67+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import software.xdev.vaadin.maps.leaflet.MapContainer;
77
import software.xdev.vaadin.maps.leaflet.basictypes.LLatLng;
8-
import software.xdev.vaadin.maps.leaflet.layer.other.LMarkerClusterGroup;
98
import software.xdev.vaadin.maps.leaflet.layer.raster.LTileLayer;
109
import software.xdev.vaadin.maps.leaflet.layer.ui.LMarker;
1110
import software.xdev.vaadin.maps.leaflet.map.LMap;
11+
import software.xdev.vaadin.maps.leaflet.markercluster.layer.other.LMarkerClusterGroup;
1212
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
1313
import software.xdev.vaadin.maps.leaflet.registry.LDefaultComponentManagementRegistry;
1414

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import software.xdev.vaadin.maps.leaflet.MapContainer;
77
import software.xdev.vaadin.maps.leaflet.basictypes.LLatLng;
88
import software.xdev.vaadin.maps.leaflet.layer.ui.LMarker;
9-
import software.xdev.vaadin.maps.leaflet.layer.vector.maplibregl.LMaplibreGL;
109
import software.xdev.vaadin.maps.leaflet.map.LMap;
10+
import software.xdev.vaadin.maps.leaflet.maplibregl.layer.vector.LMaplibreGL;
1111
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
1212
import software.xdev.vaadin.maps.leaflet.registry.LDefaultComponentManagementRegistry;
1313

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright © 2019 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.vaadin.maps.leaflet.base;
17+
18+
import java.util.Objects;
19+
20+
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
21+
22+
23+
public abstract class LAbstractComponent<S extends LComponent<S>> implements LComponent<S>
24+
{
25+
private final LComponentManagementRegistry componentRegistry;
26+
27+
protected LAbstractComponent(
28+
final LComponentManagementRegistry compReg)
29+
{
30+
this.componentRegistry = Objects.requireNonNull(compReg);
31+
}
32+
33+
@Override
34+
public LComponentManagementRegistry componentRegistry()
35+
{
36+
return this.componentRegistry;
37+
}
38+
}

flow/src/main/java/software/xdev/vaadin/maps/leaflet/base/LBaseComponent.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,24 @@
1616
package software.xdev.vaadin.maps.leaflet.base;
1717

1818
import java.io.Serializable;
19-
import java.util.Objects;
2019

2120
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
2221

2322

24-
public abstract class LBaseComponent<S extends LComponent<S>> implements LComponent<S>
23+
public abstract class LBaseComponent<S extends LComponent<S>> extends LAbstractComponent<S>
2524
{
26-
private final LComponentManagementRegistry componentRegistry;
27-
2825
protected LBaseComponent(
2926
final LComponentManagementRegistry compReg,
3027
final String jsConstructorCallExpression,
3128
final Serializable... parameters)
3229
{
33-
this.componentRegistry = Objects.requireNonNull(compReg);
34-
this.componentRegistry.add(this.self(), jsConstructorCallExpression, parameters);
35-
}
36-
37-
@Override
38-
public LComponentManagementRegistry componentRegistry()
39-
{
40-
return this.componentRegistry;
30+
super(compReg);
31+
this.componentRegistry().add(this.self(), jsConstructorCallExpression, parameters);
4132
}
4233

4334
@Override
4435
public String clientComponentJsAccessor()
4536
{
46-
return this.componentRegistry.clientComponentJsAccessor(this);
37+
return this.componentRegistry().clientComponentJsAccessor(this);
4738
}
4839
}

flow/src/main/java/software/xdev/vaadin/maps/leaflet/base/LComponent.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ public interface LComponent<S extends LComponent<S>>
2626
{
2727
LComponentManagementRegistry componentRegistry();
2828

29-
default String clientComponentJsAccessor()
30-
{
31-
return this.componentRegistry().clientComponentJsAccessor(this);
32-
}
29+
String clientComponentJsAccessor();
3330

3431
default PendingJavaScriptResult invokeSelf(final String payload, final Serializable... params)
3532
{

0 commit comments

Comments
 (0)