Skip to content

Commit f9bb15c

Browse files
committed
feat: add compatible constructor for map ClickEvent
Close #182
1 parent bd8824a commit f9bb15c

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,38 @@ public double getLongitude() {
508508
return lon;
509509
}
510510

511+
/**
512+
* Creates a new event with the click coordinates as separate lat/lon values.
513+
*
514+
* @param source the map that was clicked
515+
* @param fromClient whether the event originated on the client side
516+
* @param lat the latitude of the click
517+
* @param lon the longitude of the click
518+
*/
519+
public GoogleMapClickEvent(
520+
GoogleMap source,
521+
boolean fromClient,
522+
@EventData("event.detail.latLng.lat()") double lat,
523+
@EventData("event.detail.latLng.lng()") double lon) {
524+
super(source);
525+
this.lat = lat;
526+
this.lon = lon;
527+
}
528+
529+
/**
530+
* Creates a new event with the click coordinates as a JSON value.
531+
*
532+
* @param source the map that was clicked
533+
* @param fromClient whether the event originated on the client side
534+
* @param latLng a JSON object containing {@code lat} and {@code lng} properties
535+
* @deprecated since 2.6.0, for removal. Use
536+
* {@link #GoogleMapClickEvent(GoogleMap, boolean, double, double)} instead.
537+
*/
538+
@Deprecated
511539
public GoogleMapClickEvent(
512540
GoogleMap source,
513541
boolean fromClient,
514-
@EventData(value = "event.detail.latLng") JsonValue latLng) {
542+
JsonValue latLng) {
515543
super(source);
516544
lat = ((JsonObject) latLng).getNumber("lat");
517545
lon = ((JsonObject) latLng).getNumber("lng");
@@ -525,7 +553,9 @@ public Registration addClickListener(ComponentEventListener<GoogleMapClickEvent>
525553
getElement()
526554
.addEventListener("google-map-click", ev -> {
527555
JsonObject latLng = ev.getEventData().get("event.detail.latLng");
528-
listener.onComponentEvent(new GoogleMapClickEvent(this, true, latLng));
556+
double lat = latLng.getNumber("lat");
557+
double lon = latLng.getNumber("lng");
558+
listener.onComponentEvent(new GoogleMapClickEvent(this, true, lat, lon));
529559
}).addEventData("event.detail.latLng");
530560
return registration::remove;
531561
}
@@ -537,7 +567,9 @@ public Registration addRightClickListener(ComponentEventListener<GoogleMapClickE
537567
getElement()
538568
.addEventListener("google-map-rightclick", ev -> {
539569
JsonObject latLng = ev.getEventData().get("event.detail.latLng");
540-
listener.onComponentEvent(new GoogleMapClickEvent(this, true, latLng));
570+
double lat = latLng.getNumber("lat");
571+
double lon = latLng.getNumber("lng");
572+
listener.onComponentEvent(new GoogleMapClickEvent(this, true, lat, lon));
541573
}).addEventData("event.detail.latLng");
542574
return registration::remove;
543575
}

0 commit comments

Comments
 (0)