diff --git a/pom.xml b/pom.xml index cf34819..668aab6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.flowingcode.vaadin.addons google-maps - 2.5.1-SNAPSHOT + 2.6.0-SNAPSHOT Google Maps Addon Integration of google-map for Vaadin platform 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 77e3687..8f41cd9 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java +++ b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMap.java @@ -508,10 +508,38 @@ public double getLongitude() { return lon; } + /** + * Creates a new event with the click coordinates as separate lat/lon values. + * + * @param source the map that was clicked + * @param fromClient whether the event originated on the client side + * @param lat the latitude of the click + * @param lon the longitude of the click + */ + public GoogleMapClickEvent( + GoogleMap source, + boolean fromClient, + @EventData("event.detail.latLng.lat()") double lat, + @EventData("event.detail.latLng.lng()") double lon) { + super(source); + this.lat = lat; + this.lon = lon; + } + + /** + * Creates a new event with the click coordinates as a JSON value. + * + * @param source the map that was clicked + * @param fromClient whether the event originated on the client side + * @param latLng a JSON object containing {@code lat} and {@code lng} properties + * @deprecated since 2.6.0, for removal. Use + * {@link #GoogleMapClickEvent(GoogleMap, boolean, double, double)} instead. + */ + @Deprecated public GoogleMapClickEvent( GoogleMap source, boolean fromClient, - @EventData(value = "event.detail.latLng") JsonValue latLng) { + JsonValue latLng) { super(source); lat = ((JsonObject) latLng).getNumber("lat"); lon = ((JsonObject) latLng).getNumber("lng"); @@ -525,7 +553,9 @@ public Registration addClickListener(ComponentEventListener getElement() .addEventListener("google-map-click", ev -> { JsonObject latLng = ev.getEventData().get("event.detail.latLng"); - listener.onComponentEvent(new GoogleMapClickEvent(this, true, latLng)); + double lat = latLng.getNumber("lat"); + double lon = latLng.getNumber("lng"); + listener.onComponentEvent(new GoogleMapClickEvent(this, true, lat, lon)); }).addEventData("event.detail.latLng"); return registration::remove; } @@ -537,7 +567,9 @@ public Registration addRightClickListener(ComponentEventListener { JsonObject latLng = ev.getEventData().get("event.detail.latLng"); - listener.onComponentEvent(new GoogleMapClickEvent(this, true, latLng)); + double lat = latLng.getNumber("lat"); + double lon = latLng.getNumber("lng"); + listener.onComponentEvent(new GoogleMapClickEvent(this, true, lat, lon)); }).addEventData("event.detail.latLng"); return registration::remove; } diff --git a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMapMarker.java b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMapMarker.java index 0495465..6c06b48 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMapMarker.java +++ b/src/main/java/com/flowingcode/vaadin/addons/googlemaps/GoogleMapMarker.java @@ -261,10 +261,38 @@ public static class DragEndEvent extends ComponentEvent { private final double lat; private final double lon; + /** + * Creates a new event with the drag end coordinates as separate lat/lon values. + * + * @param source the marker that was dragged + * @param fromClient whether the event originated on the client side + * @param lat the latitude of the drag end + * @param lon the longitude of the drag end + */ public DragEndEvent( GoogleMapMarker source, boolean fromClient, - @EventData(value = "event.detail.latLng") JsonValue latLng) { + @EventData("event.detail.latLng.lat()") double lat, + @EventData("event.detail.latLng.lng()") double lon) { + super(source, fromClient); + this.lat = lat; + this.lon = lon; + } + + /** + * Creates a new event with the drag end coordinates as a JSON value. + * + * @param source the marker that was dragged + * @param fromClient whether the event originated on the client side + * @param latLng a JSON object containing {@code lat} and {@code lng} properties + * @deprecated since 2.6.0, for removal. Use + * {@link #DragEndEvent(GoogleMapMarker, boolean, double, double)} instead. + */ + @Deprecated + public DragEndEvent( + GoogleMapMarker source, + boolean fromClient, + JsonValue latLng) { super(source, fromClient); this.lat = ((JsonObject) latLng).getNumber("lat"); this.lon = ((JsonObject) latLng).getNumber("lng"); @@ -299,8 +327,34 @@ public static class GoogleMapMarkerClickEvent extends ClickEvent