|
19 | 19 | */ |
20 | 20 | package com.flowingcode.vaadin.addons.googlemaps; |
21 | 21 |
|
| 22 | +import com.vaadin.flow.component.ClickEvent; |
22 | 23 | import com.vaadin.flow.component.Component; |
23 | 24 | import com.vaadin.flow.component.ComponentEvent; |
24 | 25 | import com.vaadin.flow.component.ComponentEventListener; |
@@ -251,4 +252,41 @@ public Registration addDragEndEventListener(ComponentEventListener<DragEndEvent> |
251 | 252 | this.getElement().setProperty("dragEvents", true); |
252 | 253 | return addListener(DragEndEvent.class, listener); |
253 | 254 | } |
| 255 | + |
| 256 | + /** |
| 257 | + * Event called on marker's click. |
| 258 | + */ |
| 259 | + @DomEvent("google-map-marker-click") |
| 260 | + public static class GoogleMapMarkerClickEvent extends ClickEvent<GoogleMapMarker> { |
| 261 | + |
| 262 | + private final double lat; |
| 263 | + private final double lon; |
| 264 | + |
| 265 | + public GoogleMapMarkerClickEvent(GoogleMapMarker source, boolean fromClient, |
| 266 | + @EventData(value = "event.detail.latLng") JsonValue latLng) { |
| 267 | + super(source); |
| 268 | + this.lat = ((JsonObject) latLng).getNumber("lat"); |
| 269 | + this.lon = ((JsonObject) latLng).getNumber("lng"); |
| 270 | + } |
| 271 | + |
| 272 | + public double getLatitude() { |
| 273 | + return this.lat; |
| 274 | + } |
| 275 | + |
| 276 | + public double getLongitude() { |
| 277 | + return this.lon; |
| 278 | + } |
| 279 | + } |
| 280 | + |
| 281 | + /** |
| 282 | + * Adds a click event listener to a marker. |
| 283 | + * |
| 284 | + * @param listener |
| 285 | + * @return |
| 286 | + */ |
| 287 | + public Registration addClickListener(ComponentEventListener<GoogleMapMarkerClickEvent> listener) { |
| 288 | + this.getElement().setProperty("clickable", true); |
| 289 | + this.getElement().setProperty("clickEvents", true); |
| 290 | + return addListener(GoogleMapMarkerClickEvent.class, listener); |
| 291 | + } |
254 | 292 | } |
0 commit comments