Skip to content

Commit

Permalink
getBound in "Synchromized Mode" without wait Event from Client
Browse files Browse the repository at this point in the history
added "MapIdle" Listener
  • Loading branch information
[email protected] committed Oct 2, 2023
1 parent 60ef03e commit f56bf05
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public GoogleMap(String apiKey, String clientId, String language) {
if (!StringUtils.isEmpty(language)) {
this.getElement().setAttribute("language", language);
}
getElement().addEventListener("google-map-ready", event -> {
getElement().executeJs(
"$0.map.addListener(\"bounds_changed\", (event) => {$0.bounds =$0.map.getBounds();});", this);
});
}

@Synchronize("google-map-idle")
Expand Down Expand Up @@ -542,6 +546,11 @@ public CompletableFuture<LatLonBounds> getBounds() {
});
}

@Synchronize("google-map-idle")
public LatLonBounds getBoundsSync() {
return new LatLonBounds((JsonObject) this.getElement().getPropertyRaw("bounds"));
}

/**
* Sets the custom renderer definition to be applied to the markers clustering. The custom
* renderer needs to be define as a global JavaScript object conforming the Renderer interface
Expand All @@ -553,4 +562,18 @@ public CompletableFuture<LatLonBounds> getBounds() {
public void setClusteringRenderer(String customRenderer) {
this.getElement().setProperty("customRenderer", customRenderer);
}

public Registration addMapIdleListener(ComponentEventListener<GoogleMapIdleEvent> listener) {
DomListenerRegistration registration = this.getElement().addEventListener("google-map-idle", ev -> {
listener.onComponentEvent(new GoogleMapIdleEvent(this, true));
});
return registration::remove;
}

public static class GoogleMapIdleEvent extends ComponentEvent<GoogleMap> {
public GoogleMapIdleEvent(GoogleMap source, boolean fromClient) {
super(source, true);
}
}

}

0 comments on commit f56bf05

Please sign in to comment.