2323import com .flowingcode .vaadin .addons .demo .DemoSource ;
2424import com .flowingcode .vaadin .addons .googlemaps .GoogleMap .MapType ;
2525import com .vaadin .flow .component .button .Button ;
26+ import com .vaadin .flow .component .dependency .CssImport ;
27+ import com .vaadin .flow .component .icon .VaadinIcon ;
2628import com .vaadin .flow .component .notification .Notification ;
27- import com .vaadin .flow .component .orderedlayout .FlexLayout ;
28- import com .vaadin .flow .component .orderedlayout .FlexLayout .FlexWrap ;
2929import com .vaadin .flow .router .PageTitle ;
3030import 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" )
3640public 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}
0 commit comments