|
11 | 11 | import software.xdev.vaadin.maps.leaflet.flow.LMap; |
12 | 12 | import software.xdev.vaadin.maps.leaflet.flow.data.LCenter; |
13 | 13 | import software.xdev.vaadin.maps.leaflet.flow.data.LCircle; |
| 14 | +import software.xdev.vaadin.maps.leaflet.flow.data.LComponent; |
14 | 15 | import software.xdev.vaadin.maps.leaflet.flow.data.LDivIcon; |
15 | 16 | import software.xdev.vaadin.maps.leaflet.flow.data.LIcon; |
16 | 17 | import software.xdev.vaadin.maps.leaflet.flow.data.LMarker; |
|
21 | 22 | @Route("") |
22 | 23 | public class LeafletView extends VerticalLayout |
23 | 24 | { |
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 | + |
27 | 29 | private LMap map; |
28 | | - private boolean viewSwitch; |
29 | | - |
| 30 | + |
30 | 31 | private LMarker markerZob; |
31 | 32 | private LMarker markerRathaus; |
32 | | - |
| 33 | + |
33 | 34 | private LCircle circleRange; |
34 | 35 | private LMarker markerPizza; |
35 | 36 | private LMarker markerKebab; |
36 | 37 | private LMarker markerAsia; |
37 | 38 | private LMarker markerGreek; |
38 | 39 | private LMarker markerBakery; |
39 | 40 | private LMarker markerLeberkaese; |
40 | | - |
| 41 | + |
41 | 42 | public LeafletView() |
42 | 43 | { |
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); |
48 | 48 | } |
49 | | - |
50 | | - private void buttonOnClick(final ClickEvent<Button> event) |
| 49 | + |
| 50 | + private void btnLunchClick(final ClickEvent<Button> event) |
51 | 51 | { |
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?"); |
85 | 69 | } |
86 | | - |
87 | | - public void mapTest() |
| 70 | + |
| 71 | + private void initMapComponents() |
88 | 72 | { |
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"); |
98 | 74 | 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); |
101 | 77 | final LIcon xDevLogo = new LIcon( |
102 | 78 | "https://www.xing.com/img/custom/communities/communities_files/f/f/6/32758/large/XDEV_600x600_red.png?1438789458"); |
103 | | - |
| 79 | + |
104 | 80 | // other option: |
105 | 81 | // xDevLogo.setIconUrl( |
106 | 82 | // "https://www.xing.com/img/custom/communities/communities_files/f/f/6/32758/large/XDEV_600x600_red.png?1438789458"); |
107 | 83 | xDevLogo.setIconSize(70, 70); |
108 | 84 | xDevLogo.setIconAnchor(33, 55); |
109 | 85 | markerXDev.setPopup("<a href='https://www.xdev-software.de/'>Xdev-Software GmbH</a>"); |
110 | 86 | markerXDev.setIcon(xDevLogo); |
111 | | - |
| 87 | + |
112 | 88 | final LMarker markerInfo = new LMarker(49.674095, 12.162257); |
113 | 89 | final LDivIcon div = new LDivIcon( |
114 | 90 | "<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: |
117 | 93 | // div.setIconSize(265, 90); |
118 | 94 | // div.setHtml( |
119 | 95 | // "<p><center><b>Welcome to Weiden in der Oberpfalz!</b></center></p><p>This Demo shows you different Markers, |
120 | 96 | // Popups, Polygon and other Stuff</p>"); |
121 | 97 | 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))); |
125 | 106 | polygonNoc.setFill(true); |
126 | 107 | polygonNoc.setFillColor("#3366ff"); |
127 | 108 | polygonNoc.setFillOpacity(0.8); |
128 | 109 | polygonNoc.setStroke(false); |
129 | 110 | polygonNoc.setPopup("NOC-Nordoberpfalz Center"); |
130 | | - |
| 111 | + |
131 | 112 | this.markerRathaus = new LMarker(49.675519, 12.163868, "L-22556"); |
132 | 113 | this.markerRathaus.setPopup("Old Town Hall"); |
133 | | - |
134 | | - |
| 114 | + |
135 | 115 | this.circleRange = new LCircle(49.675126, 12.160733, 450); |
136 | | - |
| 116 | + |
137 | 117 | this.markerPizza = new LMarker(49.674413, 12.160925); |
138 | 118 | this.markerPizza.setPopup("Pizza!"); |
139 | | - |
| 119 | + |
140 | 120 | this.markerKebab = new LMarker(49.673026, 12.156278); |
141 | 121 | this.markerKebab.setPopup("Kebab!"); |
142 | | - |
| 122 | + |
143 | 123 | this.markerAsia = new LMarker(49.675039, 12.162127); |
144 | 124 | this.markerAsia.setPopup("Asian Food"); |
145 | | - |
| 125 | + |
146 | 126 | this.markerGreek = new LMarker(49.675126, 12.161899); |
147 | 127 | this.markerGreek.setPopup("Greek Food"); |
148 | | - |
| 128 | + |
149 | 129 | this.markerBakery = new LMarker(49.674806, 12.160249); |
150 | 130 | this.markerBakery.setPopup("Fresh baked stuff"); |
151 | | - |
| 131 | + |
152 | 132 | this.markerLeberkaese = new LMarker(49.673800, 12.160113); |
153 | 133 | 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( |
156 | 146 | markerXDev, |
157 | 147 | markerInfo, |
158 | 148 | this.markerZob, |
159 | 149 | polygonNoc, |
160 | 150 | 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); |
172 | 153 | } |
173 | 154 | } |
0 commit comments