FlowingCode / GoogleMapsAddon

Vaadin Addon based on Google Maps Web Component
https://www.flowingcode.com/en/open-source/
Apache License 2.0
20 stars 7 forks source link

setZoom write attribute but getZoom read property #132

Closed webshopboys closed 5 months ago

webshopboys commented 5 months ago

Describe the bug

Hi!

I found that setZoom not change zoom level if it is large (no shrink).

I debug and getZoom always zero. Is this not a source bug (setAttribute vs getProperty)?

public void setZoom(int zoom) { this.getElement().setAttribute("zoom", Integer.toString(zoom)); }

@Synchronize({"google-map-idle"}) public int getZoom() { return this.getElement().getProperty("zoom", 0); }

Expected behavior

No response

Minimal reproducible example

No response

Add-on Version

1.13.0

Vaadin Version

24.0.5

Additional information

No response

paodb commented 5 months ago

Hello @webshopboys. Thanks for creating the issue. I already did the fix to replace the use of setAttribute with setProperty when setting the zoom, as setProperty is the right approach here. I did a quick test but I cannot reproduce the zoom not changing. I've created a view with a map with zoom in 13 and then added some buttons to change the zoom to different values and then one button to invoke getZoom anytime and in all cases the zoom values return correctly. I'm sharing my code just in case:

GoogleMap gmaps = new GoogleMap(apiKey, null, null);
gmaps.setMapType(MapType.TERRAIN);
gmaps.setSizeFull();
gmaps.setZoom(14);
gmaps.setCenter(new LatLon(0, -180));
add(gmaps);
add(new Button("zoom 3", e -> gmaps.setZoom(3)));
add(new Button("zoom 18", e -> gmaps.setZoom(18)));
add(new Button("get current zoom", e -> Notification.show("Zoom: " + gmaps.getZoom())));

If the error still persist for you, please feel free to report a new issue providing a reproducible example.

Regards.

paodb commented 5 months ago

Released in version 2.0.0.