Skip to content

Commit b1f8c7e

Browse files
committed
Major refactoring / rework
* Fixed/Reworked method names * Reworked demo
1 parent 582f4b5 commit b1f8c7e

File tree

6 files changed

+227
-152
lines changed

6 files changed

+227
-152
lines changed

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

Lines changed: 70 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import software.xdev.vaadin.maps.leaflet.flow.LMap;
1212
import software.xdev.vaadin.maps.leaflet.flow.data.LCenter;
1313
import software.xdev.vaadin.maps.leaflet.flow.data.LCircle;
14+
import software.xdev.vaadin.maps.leaflet.flow.data.LComponent;
1415
import software.xdev.vaadin.maps.leaflet.flow.data.LDivIcon;
1516
import software.xdev.vaadin.maps.leaflet.flow.data.LIcon;
1617
import software.xdev.vaadin.maps.leaflet.flow.data.LMarker;
@@ -21,153 +22,133 @@
2122
@Route("")
2223
public class LeafletView extends VerticalLayout
2324
{
24-
25-
private final Button button;
26-
private List<LPoint> points;
25+
26+
private final Button btnLunch = new Button("Where do XDEV employees go for lunch?");
27+
private boolean viewLunch = false;
28+
2729
private LMap map;
28-
private boolean viewSwitch;
29-
30+
3031
private LMarker markerZob;
3132
private LMarker markerRathaus;
32-
33+
3334
private LCircle circleRange;
3435
private LMarker markerPizza;
3536
private LMarker markerKebab;
3637
private LMarker markerAsia;
3738
private LMarker markerGreek;
3839
private LMarker markerBakery;
3940
private LMarker markerLeberkaese;
40-
41+
4142
public LeafletView()
4243
{
43-
this.mapTest();
44-
this.button = new Button();
45-
this.button.setText("Where do XDEV employees go for lunch break?");
46-
this.button.addClickListener(this::buttonOnClick);
47-
this.add(this.button);
44+
this.initMapComponents();
45+
46+
this.btnLunch.addClickListener(this::btnLunchClick);
47+
this.add(this.btnLunch);
4848
}
49-
50-
private void buttonOnClick(final ClickEvent<Button> event)
49+
50+
private void btnLunchClick(final ClickEvent<Button> event)
5151
{
52-
53-
if(this.viewSwitch)
54-
{
55-
this.viewSwitch = false;
56-
57-
this.map.setViewPoint(new LCenter(49.675126, 12.160733, 16));
58-
this.map.removeItem(this.markerRathaus, this.markerZob);
59-
60-
this.map.addLComponent(
61-
this.circleRange,
62-
this.markerPizza,
63-
this.markerKebab,
64-
this.markerAsia,
65-
this.markerGreek,
66-
this.markerBakery,
67-
this.markerLeberkaese);
68-
69-
}
70-
else
71-
{
72-
this.viewSwitch = true;
73-
this.map.setViewPoint(new LCenter(49.675126, 12.160733, 17));
74-
this.map.addLComponent(this.markerRathaus, this.markerZob);
75-
76-
this.map.removeItem(
77-
this.circleRange,
78-
this.markerPizza,
79-
this.markerKebab,
80-
this.markerAsia,
81-
this.markerGreek,
82-
this.markerBakery,
83-
this.markerLeberkaese);
84-
}
52+
this.viewLunch = !this.viewLunch;
53+
54+
final List<LComponent> normalComponents = Arrays.asList(this.markerRathaus, this.markerZob);
55+
final List<LComponent> lunchComponents = Arrays.asList(
56+
this.circleRange,
57+
this.markerPizza,
58+
this.markerKebab,
59+
this.markerAsia,
60+
this.markerGreek,
61+
this.markerBakery,
62+
this.markerLeberkaese);
63+
64+
this.map.setViewPoint(new LCenter(49.675126, 12.160733, this.viewLunch ? 16 : 17));
65+
this.map.removeLComponents(this.viewLunch ? normalComponents : lunchComponents);
66+
this.map.addLComponents(this.viewLunch ? lunchComponents : normalComponents);
67+
68+
this.btnLunch.setText(this.viewLunch ? "Go back to the normal view" : "Where do XDEV employees go for lunch?");
8569
}
86-
87-
public void mapTest()
70+
71+
private void initMapComponents()
8872
{
89-
this.viewSwitch = true;
90-
this.map = new LMap(49.675126, 12.160733, 17);
91-
92-
this.map.setHeight("700px");
93-
this.map.setWidth("1000px");
94-
this.add(this.map);
95-
this.map.addMarkerClickListener(ev -> { System.out.println(ev.getTag());}); // add some logic here for called Markers (token)
96-
97-
this.markerZob = new LMarker(49.673470, 12.160108,"ZoB");
73+
this.markerZob = new LMarker(49.673470, 12.160108, "ZoB");
9874
this.markerZob.setPopup("Central bus station");
99-
100-
final LMarker markerXDev = new LMarker(49.675126, 12.160733);
75+
76+
final LMarker markerXDev = new LMarker(49.675806677512824, 12.160990185846394);
10177
final LIcon xDevLogo = new LIcon(
10278
"https://www.xing.com/img/custom/communities/communities_files/f/f/6/32758/large/XDEV_600x600_red.png?1438789458");
103-
79+
10480
// other option:
10581
// xDevLogo.setIconUrl(
10682
// "https://www.xing.com/img/custom/communities/communities_files/f/f/6/32758/large/XDEV_600x600_red.png?1438789458");
10783
xDevLogo.setIconSize(70, 70);
10884
xDevLogo.setIconAnchor(33, 55);
10985
markerXDev.setPopup("<a href='https://www.xdev-software.de/'>Xdev-Software GmbH</a>");
11086
markerXDev.setIcon(xDevLogo);
111-
87+
11288
final LMarker markerInfo = new LMarker(49.674095, 12.162257);
11389
final LDivIcon div = new LDivIcon(
11490
"<p><center><b>Welcome to Weiden in der Oberpfalz!</b></center></p><p>This Demo shows you different Markers,<br> Popups, Polygon and other Stuff</p>");
115-
116-
// other option:
91+
92+
// other options:
11793
// div.setIconSize(265, 90);
11894
// div.setHtml(
11995
// "<p><center><b>Welcome to Weiden in der Oberpfalz!</b></center></p><p>This Demo shows you different Markers,
12096
// Popups, Polygon and other Stuff</p>");
12197
markerInfo.setDivIcon(div);
122-
123-
this.getPunkte();
124-
final LPolygon polygonNoc = new LPolygon(this.points);
98+
99+
final LPolygon polygonNoc = new LPolygon(
100+
Arrays.asList(
101+
new LPoint(49.674910, 12.159202),
102+
new LPoint(49.675719, 12.160248),
103+
new LPoint(49.675962, 12.160033),
104+
new LPoint(49.675691, 12.158011),
105+
new LPoint(49.675306, 12.158499)));
125106
polygonNoc.setFill(true);
126107
polygonNoc.setFillColor("#3366ff");
127108
polygonNoc.setFillOpacity(0.8);
128109
polygonNoc.setStroke(false);
129110
polygonNoc.setPopup("NOC-Nordoberpfalz Center");
130-
111+
131112
this.markerRathaus = new LMarker(49.675519, 12.163868, "L-22556");
132113
this.markerRathaus.setPopup("Old Town Hall");
133-
134-
114+
135115
this.circleRange = new LCircle(49.675126, 12.160733, 450);
136-
116+
137117
this.markerPizza = new LMarker(49.674413, 12.160925);
138118
this.markerPizza.setPopup("Pizza!");
139-
119+
140120
this.markerKebab = new LMarker(49.673026, 12.156278);
141121
this.markerKebab.setPopup("Kebab!");
142-
122+
143123
this.markerAsia = new LMarker(49.675039, 12.162127);
144124
this.markerAsia.setPopup("Asian Food");
145-
125+
146126
this.markerGreek = new LMarker(49.675126, 12.161899);
147127
this.markerGreek.setPopup("Greek Food");
148-
128+
149129
this.markerBakery = new LMarker(49.674806, 12.160249);
150130
this.markerBakery.setPopup("Fresh baked stuff");
151-
131+
152132
this.markerLeberkaese = new LMarker(49.673800, 12.160113);
153133
this.markerLeberkaese.setPopup("Fast food like Leberkäsesemmeln");
154-
155-
this.map.addLComponent(
134+
135+
136+
this.map = new LMap(49.675126, 12.160733, 17);
137+
138+
this.map.setHeight("700px");
139+
this.map.setWidth("1000px");
140+
this.map.addMarkerClickListener(ev ->
141+
{
142+
System.out.println(ev.getTag());
143+
}); // add some logic here for called Markers (token)
144+
145+
this.map.addLComponents(
156146
markerXDev,
157147
markerInfo,
158148
this.markerZob,
159149
polygonNoc,
160150
this.markerRathaus);
161-
}
162-
163-
public void getPunkte()
164-
{
165-
this.points = Arrays.asList(
166-
new LPoint(49.674910, 12.159202),
167-
new LPoint(49.675719, 12.160248),
168-
new LPoint(49.675962, 12.160033),
169-
new LPoint(49.675691, 12.158011),
170-
new LPoint(49.675306, 12.158499));
171-
151+
152+
this.add(this.map);
172153
}
173154
}

0 commit comments

Comments
 (0)