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)));