Skip to content

Commit 83dec93

Browse files
authored
Merge pull request #266 from xdev-software/add-polyline-support
Add support for polyline
2 parents 74677e7 + a8aca24 commit 83dec93

File tree

5 files changed

+516
-22
lines changed

5 files changed

+516
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.0.2
2+
* Added support for Polyline #266 (thanks to @blitzdose)
3+
14
## 3.0.1
25
* Fixed ``divIcon`` being displayed incorrectly [due to a default ``iconSize`` of ``12px``](https://github.com/Leaflet/Leaflet/issues/4238) #246
36
* Updated dependencies

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

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import software.xdev.vaadin.maps.leaflet.flow.data.LMarker;
2323
import software.xdev.vaadin.maps.leaflet.flow.data.LPoint;
2424
import software.xdev.vaadin.maps.leaflet.flow.data.LPolygon;
25+
import software.xdev.vaadin.maps.leaflet.flow.data.LPolyline;
2526
import software.xdev.vaadin.maps.leaflet.flow.data.LTileLayer;
2627

2728

@@ -36,16 +37,17 @@ public class LeafletView extends VerticalLayout
3637
private final Button btnLunch = new Button("Where do XDEV employees go for lunch?");
3738
private LMap map;
3839

39-
private LMarker markerZob;
40-
private LMarker markerRathaus;
40+
private final LMarker markerZob = new LMarker(49.673470, 12.160108, "ZoB");
41+
private final LMarker markerRathaus = new LMarker(49.675519, 12.163868, "L-22556");
4142

42-
private LCircle circleRange;
43-
private LMarker markerPizza;
44-
private LMarker markerKebab;
45-
private LMarker markerAsia;
46-
private LMarker markerGreek;
47-
private LMarker markerBakery;
48-
private LMarker markerLeberkaese;
43+
private final LCircle circleRange = new LCircle(49.675126, 12.160733, 450);
44+
private final LMarker markerPizza = new LMarker(49.674413, 12.160925);
45+
private final LMarker markerKebab = new LMarker(49.673026, 12.156278);
46+
private final LMarker markerAsia = new LMarker(49.675039, 12.162127);
47+
private final LMarker markerGreek = new LMarker(49.675126, 12.161899);
48+
private final LMarker markerBakery = new LMarker(49.674806, 12.160249);
49+
private final LMarker markerSchnitzel = new LMarker(49.673800, 12.160113);
50+
private final LMarker markerBratwurst = new LMarker(49.674907, 12.161937);
4951

5052
public LeafletView()
5153
{
@@ -89,7 +91,8 @@ private void btnLunchClick(final ClickEvent<Button> event)
8991
this.markerAsia,
9092
this.markerGreek,
9193
this.markerBakery,
92-
this.markerLeberkaese);
94+
this.markerSchnitzel,
95+
this.markerBratwurst);
9396

9497
this.map.setViewPoint(new LCenter(49.675126, 12.160733, this.viewLunch ? 16 : 17));
9598
this.map.removeLComponents(this.viewLunch ? normalComponents : lunchComponents);
@@ -100,7 +103,6 @@ private void btnLunchClick(final ClickEvent<Button> event)
100103

101104
private void initMapComponents()
102105
{
103-
this.markerZob = new LMarker(49.673470, 12.160108, "ZoB");
104106
this.markerZob.setPopup("Central bus station");
105107

106108
final LMarker markerXDev = new LMarker(49.675806677512824, 12.160990185846394);
@@ -142,32 +144,33 @@ private void initMapComponents()
142144
new LPoint(49.675306, 12.158499)));
143145
polygonNoc.setFill(true);
144146
polygonNoc.setFillColor("#3366ff");
145-
polygonNoc.setFillOpacity(0.8);
147+
polygonNoc.setFillOpacity(0.5);
146148
polygonNoc.setStroke(false);
147149
polygonNoc.setPopup("NOC-Nordoberpfalz Center");
148150

149-
this.markerRathaus = new LMarker(49.675519, 12.163868, "L-22556");
150-
this.markerRathaus.setPopup("Old Town Hall");
151+
final LPolyline polylineRouteZOB = new LPolyline(List.of(
152+
new LPoint(49.673800, 12.160113),
153+
new LPoint(49.67391927694611, 12.160769132769188),
154+
new LPoint(49.67567078571473, 12.160428926167304)
155+
));
156+
polylineRouteZOB.setStrokeOpacity(0.5);
157+
polylineRouteZOB.setPopup("Route to ZOB");
151158

152-
this.circleRange = new LCircle(49.675126, 12.160733, 450);
159+
this.markerRathaus.setPopup("Old Town Hall");
153160

154-
this.markerPizza = new LMarker(49.674413, 12.160925);
155161
this.markerPizza.setPopup("Pizza!");
156162

157-
this.markerKebab = new LMarker(49.673026, 12.156278);
158163
this.markerKebab.setPopup("Kebab!");
159164

160-
this.markerAsia = new LMarker(49.675039, 12.162127);
161165
this.markerAsia.setPopup("Asian Food");
162166

163-
this.markerGreek = new LMarker(49.675126, 12.161899);
164167
this.markerGreek.setPopup("Greek Food");
165168

166-
this.markerBakery = new LMarker(49.674806, 12.160249);
167169
this.markerBakery.setPopup("Fresh baked stuff");
168170

169-
this.markerLeberkaese = new LMarker(49.673800, 12.160113);
170-
this.markerLeberkaese.setPopup("Fast food like Leberkäsesemmeln");
171+
this.markerSchnitzel.setPopup("Fast food like Schnitzel");
172+
173+
this.markerBratwurst.setPopup("Bratwurst");
171174

172175
this.map = new LMap(49.675126, 12.160733, 17);
173176
this.map.setTileLayer(LTileLayer.DEFAULT_OPENSTREETMAP_TILE);
@@ -181,6 +184,7 @@ private void initMapComponents()
181184
markerInfo,
182185
this.markerZob,
183186
polygonNoc,
187+
polylineRouteZOB,
184188
this.markerRathaus);
185189
}
186190
}
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
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.flow.data;
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
import com.fasterxml.jackson.core.JsonProcessingException;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
23+
24+
25+
public class LPolyline implements LComponent
26+
{
27+
private final LPolylineGeometry geometry;
28+
private final LPolylineOptions properties;
29+
30+
public LPolyline(final LPoint... points)
31+
{
32+
final List<List<Double>> posis = new ArrayList<>();
33+
this.properties = new LPolylineOptions();
34+
for(final LPoint p : points)
35+
{
36+
posis.add(p.getCoords());
37+
}
38+
this.geometry = new LPolylineGeometry("Polyline", posis);
39+
}
40+
41+
/**
42+
* Create a new Polyline for marking a line on the map
43+
*
44+
* @param points List of points to draw the Polyline
45+
*/
46+
public LPolyline(final List<LPoint> points)
47+
{
48+
final List<List<Double>> posis = new ArrayList<>();
49+
for(final LPoint p : points)
50+
{
51+
posis.add(p.getCoords());
52+
}
53+
54+
this.properties = new LPolylineOptions();
55+
this.geometry = new LPolylineGeometry("Polyline", posis);
56+
}
57+
58+
public boolean isStroke()
59+
{
60+
return this.properties.isStroke();
61+
}
62+
63+
/**
64+
* Draws a border, default is true.
65+
*/
66+
public void setStroke(final boolean stroke)
67+
{
68+
this.properties.setStroke(stroke);
69+
}
70+
71+
public String getStrokeColor()
72+
{
73+
return this.properties.getColor();
74+
}
75+
76+
/**
77+
* Set a Color to the border.
78+
*/
79+
public void setStrokeColor(final String strokeColor)
80+
{
81+
this.properties.setColor(strokeColor);
82+
}
83+
84+
public double getStrokeOpacity()
85+
{
86+
return this.properties.getOpacity();
87+
}
88+
89+
/**
90+
* Sets the opacity of the border.
91+
*/
92+
public void setStrokeOpacity(final double strokeOpacity)
93+
{
94+
this.properties.setOpacity(strokeOpacity);
95+
}
96+
97+
public int getStrokeWeight()
98+
{
99+
return this.properties.getWeight();
100+
}
101+
102+
/**
103+
* Sets the width of the border.
104+
*/
105+
public void setStrokeWeight(final int strokeWeight)
106+
{
107+
this.properties.setWeight(strokeWeight);
108+
}
109+
110+
public String getLineJoin()
111+
{
112+
return this.properties.getLineJoin();
113+
}
114+
115+
/**
116+
* A string that defines shape to be used at the corners of the stroke.<br>
117+
* <li>miter</li>
118+
* <li>round</li>
119+
* <li>bevel</li>
120+
* <li>miter-clip</li>
121+
* <li>arcs</li>
122+
*/
123+
public void setLineJoin(final String lineJoin)
124+
{
125+
this.properties.setLineJoin(lineJoin);
126+
}
127+
128+
public String getDashArray()
129+
{
130+
return this.properties.getDashArray();
131+
}
132+
133+
/**
134+
* A string that defines the stroke dash pattern.<br> For example: "2 1 3 1 2"
135+
*/
136+
public void setDashArray(final String dashArray)
137+
{
138+
this.properties.setDashArray(dashArray);
139+
}
140+
141+
public String getDashOffset()
142+
{
143+
return this.properties.getDashOffset();
144+
}
145+
146+
/**
147+
* A string that defines the distance into the dash pattern to start the dash.<br> For example: "2" - The start of
148+
* the dash array computation is pulled by 3 user units
149+
*/
150+
public void setDashOffset(final String dashOffset)
151+
{
152+
this.properties.setDashOffset(dashOffset);
153+
}
154+
155+
public boolean isFill()
156+
{
157+
return this.properties.isFill();
158+
}
159+
160+
/**
161+
* Whether to fill the path with color. Set it to false to disable filling.
162+
*/
163+
public void setFill(final boolean fill)
164+
{
165+
this.properties.setFill(fill);
166+
}
167+
168+
public String getFillColor()
169+
{
170+
return this.properties.getFillColor();
171+
}
172+
173+
/**
174+
* Fill color.
175+
*/
176+
public void setFillColor(final String fillColor)
177+
{
178+
this.properties.setFillColor(fillColor);
179+
}
180+
181+
public double getFillOpacity()
182+
{
183+
return this.properties.getFillOpacity();
184+
}
185+
186+
/**
187+
* Fill opacity.
188+
*/
189+
public void setFillOpacity(final double fillOpacity)
190+
{
191+
this.properties.setFillOpacity(fillOpacity);
192+
}
193+
194+
@Override
195+
public String getPopup()
196+
{
197+
return this.properties.getPopup();
198+
}
199+
200+
/**
201+
* Set Pop-up message.
202+
*/
203+
public void setPopup(final String popup)
204+
{
205+
this.properties.setPopup(popup);
206+
}
207+
208+
public String getFillRule()
209+
{
210+
return this.properties.getFillRule();
211+
}
212+
213+
/**
214+
* A string that defines how the inside of a shape is determined.<br>
215+
* <li>evenodd</li>
216+
* <li>nonzero</li>
217+
*/
218+
public void setFillRule(final String fillRule)
219+
{
220+
this.properties.setFillRule(fillRule);
221+
}
222+
223+
public boolean isNoClip()
224+
{
225+
return this.properties.isNoClip();
226+
}
227+
228+
/**
229+
* Disable polyline clipping.
230+
*/
231+
public void setNoClip(final boolean noClip)
232+
{
233+
this.properties.setNoClip(noClip);
234+
}
235+
236+
public double getSmoothFactor()
237+
{
238+
return this.properties.getSmoothFactor();
239+
}
240+
241+
/**
242+
* How much to simplify the polyline on each zoom level.<br> More means better performance and smoother look, and
243+
* less means more accurate representation.
244+
*/
245+
public void setSmoothFactor(final double smoothFactor)
246+
{
247+
this.properties.setSmoothFactor(smoothFactor);
248+
}
249+
250+
@Override
251+
public String buildClientJSItems() throws JsonProcessingException
252+
{
253+
final ObjectMapper mapper = new ObjectMapper();
254+
return "let item = L.polyline("
255+
+ mapper.writeValueAsString(this.geometry.getCoordinates()) + ","
256+
+ mapper.writeValueAsString(this.properties)
257+
+ ");";
258+
}
259+
}

0 commit comments

Comments
 (0)