Skip to content

Commit

Permalink
deprecate: deprecate addCustomControls method
Browse files Browse the repository at this point in the history
Use setCustomControls instead.

Close #127
  • Loading branch information
paodb authored and javier-godoy committed May 21, 2024
1 parent 03ebe30 commit 554f52e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,10 @@ public LatLonBounds getBounds() {
* Adds custom control buttons to the map.
*
* @param customControls list of custom controls to add to the map
*
* @deprecated {@link #setCustomControls(CustomControl... customControls)} should be used instead.
*/
@Deprecated
public void addCustomControls(CustomControl... customControls) {
JsonArray jsonArray = Json.createArray();
for (int i = 0; i < customControls.length; i++) {
Expand All @@ -758,4 +761,20 @@ public void addCustomControls(CustomControl... customControls) {
}
this.getElement().setPropertyJson("customControls", jsonArray);
}

/**
* Sets the custom control buttons to be displayed in the map.
*
* @param customControls list of custom controls to add to the map
*/
public void setCustomControls(CustomControl... customControls) {
JsonArray jsonArray = Json.createArray();
for (int i = 0; i < customControls.length; i++) {
CustomControl customControl = customControls[i];
jsonArray.set(i, customControl.getJson(i));
customControl.getControlButton().getElement().setAttribute("slot", "customControlSlot_" + i);
this.getElement().appendChild(customControl.getControlButton().getElement());
}
this.getElement().setPropertyJson("customControls", jsonArray);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void createGoogleMapsDemo(String apiKey) {
currentLocationButton.setClassName("geolocation-button");
CustomControl geolocationControl =
new CustomControl(currentLocationButton, ControlPosition.TOP_CENTER);
gmaps.addCustomControls(geolocationControl);
gmaps.setCustomControls(geolocationControl);

gmaps.addCurrentLocationEventListener(e -> gmaps
.addMarker(new GoogleMapMarker("You are here!", gmaps.getCenter(), false, Markers.GREEN)));
Expand Down

0 comments on commit 554f52e

Please sign in to comment.