Skip to content

Commit 554f52e

Browse files
paodbjavier-godoy
authored andcommitted
deprecate: deprecate addCustomControls method
Use setCustomControls instead. Close #127
1 parent 03ebe30 commit 554f52e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,10 @@ public LatLonBounds getBounds() {
747747
* Adds custom control buttons to the map.
748748
*
749749
* @param customControls list of custom controls to add to the map
750+
*
751+
* @deprecated {@link #setCustomControls(CustomControl... customControls)} should be used instead.
750752
*/
753+
@Deprecated
751754
public void addCustomControls(CustomControl... customControls) {
752755
JsonArray jsonArray = Json.createArray();
753756
for (int i = 0; i < customControls.length; i++) {
@@ -758,4 +761,20 @@ public void addCustomControls(CustomControl... customControls) {
758761
}
759762
this.getElement().setPropertyJson("customControls", jsonArray);
760763
}
764+
765+
/**
766+
* Sets the custom control buttons to be displayed in the map.
767+
*
768+
* @param customControls list of custom controls to add to the map
769+
*/
770+
public void setCustomControls(CustomControl... customControls) {
771+
JsonArray jsonArray = Json.createArray();
772+
for (int i = 0; i < customControls.length; i++) {
773+
CustomControl customControl = customControls[i];
774+
jsonArray.set(i, customControl.getJson(i));
775+
customControl.getControlButton().getElement().setAttribute("slot", "customControlSlot_" + i);
776+
this.getElement().appendChild(customControl.getControlButton().getElement());
777+
}
778+
this.getElement().setPropertyJson("customControls", jsonArray);
779+
}
761780
}

src/test/java/com/flowingcode/vaadin/addons/googlemaps/GeolocationDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected void createGoogleMapsDemo(String apiKey) {
5252
currentLocationButton.setClassName("geolocation-button");
5353
CustomControl geolocationControl =
5454
new CustomControl(currentLocationButton, ControlPosition.TOP_CENTER);
55-
gmaps.addCustomControls(geolocationControl);
55+
gmaps.setCustomControls(geolocationControl);
5656

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

0 commit comments

Comments
 (0)