diff --git a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java index eff7e16..c79f4cc 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java +++ b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java @@ -789,4 +789,56 @@ public void setCustomControls(CustomControl... customControls) { } this.getElement().setPropertyJson("customControls", jsonArray); } + + /** + * Adds a FullScreenEvent listener. The listener is called to notify whether the map is in full + * screen mode. + * + * @param listener a FullScreenEvent listener + * @return Registration object to allow removing the listener + */ + public Registration addFullScreenListener(ComponentEventListener listener) { + DomListenerRegistration registration = + this.getElement().addEventListener("fullscreenchange", ev -> { + this.getElement() + .executeJs( + "var isFullScreen = document.fullScreen ||\r\n" + + " document.mozFullScreen ||\r\n" + + " document.webkitIsFullScreen;\r\n" + + " return isFullScreen;") + .then(Boolean.class, isFullScreen -> listener + .onComponentEvent(new FullScreenEvent(this, true, isFullScreen))); + }); + return registration::remove; + } + + /** + * Event fired when the full screen mode changes on the map. + */ + public static class FullScreenEvent extends ComponentEvent { + + private boolean isFullScreen; + + /** + * Creates a new FullScreenEvent. + * + * @param source the source component + * @param fromClient whether the event originated from the client side + * @param isFullScreen the full screen state + */ + public FullScreenEvent(GoogleMap source, boolean fromClient, boolean isFullScreen) { + super(source, true); + this.isFullScreen = isFullScreen; + } + + /** + * Checks if the map is in full screen mode. + * + * @return true if the map is in full screen mode, false otherwise + */ + public boolean isFullScreen() { + return isFullScreen; + } + } + }