Skip to content

Commit c782420

Browse files
paodbjavier-godoy
authored andcommitted
refactor(demo): make GeolocationDemo to use custom control button
Close #114
1 parent f26b711 commit c782420

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

src/test/java/com/flowingcode/vaadin/addons/googlemaps/GeolocationDemo.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@
2323
import com.flowingcode.vaadin.addons.demo.DemoSource;
2424
import com.flowingcode.vaadin.addons.googlemaps.GoogleMap.MapType;
2525
import com.vaadin.flow.component.button.Button;
26+
import com.vaadin.flow.component.dependency.CssImport;
27+
import com.vaadin.flow.component.icon.VaadinIcon;
2628
import com.vaadin.flow.component.notification.Notification;
27-
import com.vaadin.flow.component.orderedlayout.FlexLayout;
28-
import com.vaadin.flow.component.orderedlayout.FlexLayout.FlexWrap;
2929
import com.vaadin.flow.router.PageTitle;
3030
import com.vaadin.flow.router.Route;
3131

3232
@PageTitle("Geolocation Demo")
3333
@DemoSource
34+
@DemoSource(
35+
value = "/src/test/resources/META-INF/resources/frontend/styles/google-maps/geolocation-demo-styles.css",
36+
caption = "geolocation-demo-styles.css")
3437
@Route(value = "googlemaps/geolocation", layout = GooglemapsDemoView.class)
38+
@CssImport("./styles/google-maps/geolocation-demo-styles.css")
3539
@SuppressWarnings("serial")
3640
public class GeolocationDemo extends AbstractGoogleMapsDemo {
3741

@@ -40,22 +44,21 @@ protected void createGoogleMapsDemo(String apiKey) {
4044
GoogleMap gmaps = new GoogleMap(apiKey, null, null);
4145
gmaps.setMapType(MapType.ROADMAP);
4246
gmaps.setSizeFull();
47+
add(gmaps);
4348

44-
FlexLayout layout = new FlexLayout();
45-
layout.setFlexWrap(FlexWrap.WRAP);
46-
layout.add(new Button("Go to current location", e -> gmaps.goToCurrentLocation()));
47-
add(gmaps, layout);
49+
// create custom control button to pan to current location
50+
Button currentLocationButton = new Button("Go to current location",
51+
VaadinIcon.CROSSHAIRS.create(), e -> gmaps.goToCurrentLocation());
52+
currentLocationButton.setClassName("geolocation-button");
53+
CustomControl geolocationControl =
54+
new CustomControl(currentLocationButton, ControlPosition.TOP_CENTER);
55+
gmaps.addCustomControls(geolocationControl);
4856

49-
gmaps.addCurrentLocationEventListener(
50-
e ->
51-
gmaps.addMarker(
52-
new GoogleMapMarker("You are here!", gmaps.getCenter(), false, Markers.GREEN)));
57+
gmaps.addCurrentLocationEventListener(e -> gmaps
58+
.addMarker(new GoogleMapMarker("You are here!", gmaps.getCenter(), false, Markers.GREEN)));
5359

54-
gmaps.addGeolocationErrorEventListener(
55-
e ->
56-
Notification.show(
57-
e.isBrowserHasGeolocationSupport()
58-
? "The geolocation service failed on retrieving your location."
59-
: "Your browser doesn't support geolocation."));
60+
gmaps.addGeolocationErrorEventListener(e -> Notification.show(e.isBrowserHasGeolocationSupport()
61+
? "The geolocation service failed on retrieving your location."
62+
: "Your browser doesn't support geolocation."));
6063
}
6164
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*-
2+
* #%L
3+
* Google Maps Addon
4+
* %%
5+
* Copyright (C) 2020 - 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
.geolocation-button {
22+
background: white;
23+
margin: 10px;
24+
height: 40px;
25+
color: black;
26+
cursor: pointer;
27+
font-family: Arial;
28+
font-size: 18px;
29+
border-radius: 0;
30+
box-shadow: rgba(0, 0, 0, 0.3) 0px 1px 4px -1px;
31+
}

0 commit comments

Comments
 (0)