Skip to content

Commit d35d500

Browse files
AB-xdevblitzdose
andcommitted
Ported changes from #225 and refitted them for develop
Co-Authored-By: Christian Zäske <[email protected]>
1 parent 74677e7 commit d35d500

File tree

3 files changed

+487
-0
lines changed

3 files changed

+487
-0
lines changed
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.List;
19+
20+
21+
public class LPolylineGeometry
22+
{
23+
private List<List<Double>> coordinates;
24+
private String type;
25+
26+
public LPolylineGeometry(final String type, final List<List<Double>> coordinates)
27+
{
28+
this.type = type;
29+
this.coordinates = coordinates;
30+
}
31+
32+
public String getType()
33+
{
34+
return this.type;
35+
}
36+
37+
public void setType(final String type)
38+
{
39+
this.type = type;
40+
}
41+
42+
public List<List<Double>> getCoordinates()
43+
{
44+
return this.coordinates;
45+
}
46+
47+
public void setCoordinates(final List<List<Double>> poly)
48+
{
49+
this.coordinates = poly;
50+
}
51+
}

0 commit comments

Comments
 (0)