Skip to content

Commit 743b366

Browse files
paodbjavier-godoy
authored andcommitted
feat: add listener to know if map is in full screen mode
1 parent 73dc5a8 commit 743b366

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,4 +789,56 @@ public void setCustomControls(CustomControl... customControls) {
789789
}
790790
this.getElement().setPropertyJson("customControls", jsonArray);
791791
}
792+
793+
/**
794+
* Adds a FullScreenEvent listener. The listener is called to notify whether the map is in full
795+
* screen mode.
796+
*
797+
* @param listener a FullScreenEvent listener
798+
* @return Registration object to allow removing the listener
799+
*/
800+
public Registration addFullScreenListener(ComponentEventListener<FullScreenEvent> listener) {
801+
DomListenerRegistration registration =
802+
this.getElement().addEventListener("fullscreenchange", ev -> {
803+
this.getElement()
804+
.executeJs(
805+
"var isFullScreen = document.fullScreen ||\r\n"
806+
+ " document.mozFullScreen ||\r\n"
807+
+ " document.webkitIsFullScreen;\r\n"
808+
+ " return isFullScreen != null ? isFullScreen : false;")
809+
.then(Boolean.class, isFullScreen -> listener
810+
.onComponentEvent(new FullScreenEvent(this, true, isFullScreen)));
811+
});
812+
return registration::remove;
813+
}
814+
815+
/**
816+
* Event fired when the full screen mode changes on the map.
817+
*/
818+
public static class FullScreenEvent extends ComponentEvent<GoogleMap> {
819+
820+
private boolean isFullScreen;
821+
822+
/**
823+
* Creates a new FullScreenEvent.
824+
*
825+
* @param source the source component
826+
* @param fromClient whether the event originated from the client side
827+
* @param isFullScreen the full screen state
828+
*/
829+
public FullScreenEvent(GoogleMap source, boolean fromClient, boolean isFullScreen) {
830+
super(source, true);
831+
this.isFullScreen = isFullScreen;
832+
}
833+
834+
/**
835+
* Checks if the map is in full screen mode.
836+
*
837+
* @return true if the map is in full screen mode, false otherwise
838+
*/
839+
public boolean isFullScreen() {
840+
return isFullScreen;
841+
}
842+
}
843+
792844
}

0 commit comments

Comments
 (0)