Skip to content

Commit 008fa39

Browse files
committed
Add support for WMS
Fixes #486
1 parent f8e7614 commit 008fa39

File tree

8 files changed

+400
-148
lines changed

8 files changed

+400
-148
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.4.1
2+
* Added support for [WMS](https://leafletjs.com/reference.html#tilelayer-wms) #486
3+
* Updated dependencies
4+
15
## 4.4.0
26
* Added support for [GeoJSON](https://leafletjs.com/reference.html#geojson) and [FeatureGroup](https://leafletjs.com/reference.html#featuregroup) #438
37
* Add "draggable" property to LMarkerOptions #413 (thanks to @ChristianHoesel)

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import software.xdev.vaadin.maps.leaflet.layer.LLayerGroup;
3434
import software.xdev.vaadin.maps.leaflet.layer.raster.LImageOverlay;
3535
import software.xdev.vaadin.maps.leaflet.layer.raster.LTileLayer;
36+
import software.xdev.vaadin.maps.leaflet.layer.raster.LTileLayerWMS;
37+
import software.xdev.vaadin.maps.leaflet.layer.raster.LTileLayerWMSOptions;
3638
import software.xdev.vaadin.maps.leaflet.layer.raster.LVideoOverlay;
3739
import software.xdev.vaadin.maps.leaflet.layer.raster.LVideoOverlayOptions;
3840
import software.xdev.vaadin.maps.leaflet.layer.ui.LMarker;
@@ -89,9 +91,26 @@ public ComplexDemo()
8991
"https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png",
9092
16,
9193
"Map data: &copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors, <a "
92-
+ "href=\"http://viewfinderpanoramas.org\">SRTM</a> | Map style: &copy; <a href=\"https://opentopomap"
94+
+ "href=\"https://viewfinderpanoramas.org\">SRTM</a> | Map style: &copy; <a href=\"https://opentopomap"
9395
+ ".org\">OpenTopoMap</a> (<a href=\"https://creativecommons.org/licenses/by-sa/3.0/\">CC-BY-SA</a>"
9496
);
97+
final LTileLayerWMS tlWMS = new LTileLayerWMS(
98+
this.reg,
99+
"https://ows.mundialis.de/services/service?",
100+
"TOPO-WMS,OSM-Overlay-WMS",
101+
11,
102+
"&copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors, "
103+
+ "<a href=\"https://www.terrestris.de/en/demos/\">Terrestris/Mundialis</a>"
104+
);
105+
final LTileLayerWMS tlWMSUSWeatherData = new LTileLayerWMS(
106+
this.reg,
107+
"https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi",
108+
new LTileLayerWMSOptions()
109+
.withLayers("nexrad-n0r-900913")
110+
.withFormat("image/png")
111+
.withTransparent(true)
112+
.withAttribution("Weather data © 2012 IEM Nexrad")
113+
);
95114

96115
final LDivIcon divIconInfo = new LDivIcon(this.reg, new LDivIconOptions()
97116
.withHtml("""
@@ -177,7 +196,7 @@ public ComplexDemo()
177196
.addLayer(tlOSM)
178197
.addLayer(lLayerGroupPlaces);
179198

180-
this.addControls(tlOSM, tlOSMHOT, tlTopo, lLayerGroupPlaces, lLayerGroupFood);
199+
this.addControls(tlOSM, tlOSMHOT, tlTopo, tlWMS, lLayerGroupPlaces, lLayerGroupFood, tlWMSUSWeatherData);
181200

182201
this.hlButtons.setWidthFull();
183202
this.add(this.hlButtons);
@@ -198,20 +217,24 @@ private void addControls(
198217
final LTileLayer tlOSM,
199218
final LTileLayer tlOSMHOT,
200219
final LTileLayer tlTopo,
220+
final LTileLayerWMS tlWMS,
201221
final LLayerGroup lLayerGroupPlaces,
202-
final LLayerGroup lLayerGroupFood)
222+
final LLayerGroup lLayerGroupFood,
223+
final LTileLayerWMS tlWMSUSWeatherData)
203224
{
204225
// Use LinkedHashMap for order
205226
final LinkedHashMap<String, LLayer<?>> baseLayers = new LinkedHashMap<>();
206227
baseLayers.put("OSM", tlOSM);
207228
baseLayers.put("OSM HOT", tlOSMHOT);
208229
baseLayers.put("TOPO", tlTopo);
230+
baseLayers.put("WMS", tlWMS);
209231
final LControlLayers lControlLayers = new LControlLayers(
210232
this.reg,
211233
baseLayers,
212234
new LControlLayersOptions().withCollapsed(false))
213235
.addOverlay(lLayerGroupPlaces, "Places")
214236
.addOverlay(lLayerGroupFood, "Food")
237+
.addOverlay(tlWMSUSWeatherData, "US Weather data")
215238
.addTo(this.map);
216239
// Apply manual patch for https://github.com/Leaflet/Leaflet/issues/9009 as this was not released yet
217240
this.map.on(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.layer.raster;
17+
18+
import java.io.Serializable;
19+
20+
import software.xdev.vaadin.maps.leaflet.layer.LGridLayer;
21+
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
22+
23+
24+
/**
25+
* Represents a <a href="https://leafletjs.com/reference.html#tilelayer">tile layer</a>.
26+
*/
27+
public abstract class LAbstractTileLayer<S extends LAbstractTileLayer<S>> extends LGridLayer<S>
28+
{
29+
protected LAbstractTileLayer(
30+
final LComponentManagementRegistry compReg,
31+
final String jsConstructorCallExpression,
32+
final Serializable... parameters)
33+
{
34+
super(compReg, jsConstructorCallExpression, parameters);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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.layer.raster;
17+
18+
import software.xdev.vaadin.maps.leaflet.layer.LGridLayerOptions;
19+
20+
21+
/**
22+
* @see <a href="https://leafletjs.com/reference.html#tilelayer-option">Leaflet docs</a>
23+
*/
24+
public abstract class LAbstractTileLayerOptions<S extends LAbstractTileLayerOptions<S>> extends LGridLayerOptions<S>
25+
{
26+
// String|String[]
27+
private Object subdomains;
28+
private String errorTileUrl;
29+
private Integer zoomOffset;
30+
private Boolean tms;
31+
private Boolean zoomReverse;
32+
private Boolean detectRetina;
33+
// Boolean|String
34+
private Object crossOrigin;
35+
// Boolean|String
36+
private Object referrerPolicy;
37+
38+
public Object getSubdomains()
39+
{
40+
return this.subdomains;
41+
}
42+
43+
public void setSubdomains(final Object subdomains)
44+
{
45+
this.subdomains = subdomains;
46+
}
47+
48+
public S withSubdomains(final Object subdomains)
49+
{
50+
this.setSubdomains(subdomains);
51+
return this.self();
52+
}
53+
54+
public String getErrorTileUrl()
55+
{
56+
return this.errorTileUrl;
57+
}
58+
59+
public void setErrorTileUrl(final String errorTileUrl)
60+
{
61+
this.errorTileUrl = errorTileUrl;
62+
}
63+
64+
public S withErrorTileUrl(final String errorTileUrl)
65+
{
66+
this.setErrorTileUrl(errorTileUrl);
67+
return this.self();
68+
}
69+
70+
public Integer getZoomOffset()
71+
{
72+
return this.zoomOffset;
73+
}
74+
75+
public void setZoomOffset(final Integer zoomOffset)
76+
{
77+
this.zoomOffset = zoomOffset;
78+
}
79+
80+
public S withZoomOffset(final Integer zoomOffset)
81+
{
82+
this.setZoomOffset(zoomOffset);
83+
return this.self();
84+
}
85+
86+
public Boolean getTms()
87+
{
88+
return this.tms;
89+
}
90+
91+
public void setTms(final Boolean tms)
92+
{
93+
this.tms = tms;
94+
}
95+
96+
public S withTms(final Boolean tms)
97+
{
98+
this.setTms(tms);
99+
return this.self();
100+
}
101+
102+
public Boolean getZoomReverse()
103+
{
104+
return this.zoomReverse;
105+
}
106+
107+
public void setZoomReverse(final Boolean zoomReverse)
108+
{
109+
this.zoomReverse = zoomReverse;
110+
}
111+
112+
public S withZoomReverse(final Boolean zoomReverse)
113+
{
114+
this.setZoomReverse(zoomReverse);
115+
return this.self();
116+
}
117+
118+
public Boolean getDetectRetina()
119+
{
120+
return this.detectRetina;
121+
}
122+
123+
public void setDetectRetina(final Boolean detectRetina)
124+
{
125+
this.detectRetina = detectRetina;
126+
}
127+
public S withDetectRetina(final Boolean detectRetina)
128+
{
129+
this.setDetectRetina(detectRetina);
130+
return this.self();
131+
}
132+
133+
134+
public Object getCrossOrigin()
135+
{
136+
return this.crossOrigin;
137+
}
138+
139+
public void setCrossOrigin(final Object crossOrigin)
140+
{
141+
this.crossOrigin = crossOrigin;
142+
}
143+
144+
public S withCrossOrigin(final Object crossOrigin)
145+
{
146+
this.setCrossOrigin(crossOrigin);
147+
return this.self();
148+
}
149+
150+
public Object getReferrerPolicy()
151+
{
152+
return this.referrerPolicy;
153+
}
154+
155+
public void setReferrerPolicy(final Object referrerPolicy)
156+
{
157+
this.referrerPolicy = referrerPolicy;
158+
}
159+
160+
public S withReferrerPolicy(final Object referrerPolicy)
161+
{
162+
this.setReferrerPolicy(referrerPolicy);
163+
return this.self();
164+
}
165+
}

vaadin-maps-leaflet-flow/src/main/java/software/xdev/vaadin/maps/leaflet/layer/raster/LTileLayer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package software.xdev.vaadin.maps.leaflet.layer.raster;
1717

18-
import software.xdev.vaadin.maps.leaflet.layer.LGridLayer;
1918
import software.xdev.vaadin.maps.leaflet.registry.LComponentManagementRegistry;
2019

2120

@@ -30,7 +29,7 @@
3029
*
3130
* @see <a href="https://wiki.openstreetmap.org/wiki/Raster_tile_providers">List of raster tile providers</a>
3231
*/
33-
public class LTileLayer extends LGridLayer<LTileLayer>
32+
public class LTileLayer extends LAbstractTileLayer<LTileLayer>
3433
{
3534
public LTileLayer(
3635
final LComponentManagementRegistry compReg,

0 commit comments

Comments
 (0)