From fa118aca960ec2a6915ccc55c02cfae1a0ca3d28 Mon Sep 17 00:00:00 2001 From: Paola De Bartolo Date: Thu, 16 May 2024 11:05:00 -0300 Subject: [PATCH] deprecate: deprecate addCustomControls method Use setCustomControls instead. Close #127 --- .../vaadin/addons/googlemaps/GoogleMap.java | 19 +++++++++++++++++++ .../addons/googlemaps/GeolocationDemo.java | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) 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 b42629d..8daf37b 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java +++ b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java @@ -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++) { @@ -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); + } } diff --git a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/GeolocationDemo.java b/src/test/java/com/flowingcode/vaadin/addons/googlemaps/GeolocationDemo.java index a9fd1dc..84e2516 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/googlemaps/GeolocationDemo.java +++ b/src/test/java/com/flowingcode/vaadin/addons/googlemaps/GeolocationDemo.java @@ -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)));