|
7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | * you may not use this file except in compliance with the License. |
9 | 9 | * You may obtain a copy of the License at |
10 | | - * |
| 10 | + * |
11 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | - * |
| 12 | + * |
13 | 13 | * Unless required by applicable law or agreed to in writing, software |
14 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
20 | 20 | package com.flowingcode.vaadin.addons.googlemaps; |
21 | 21 |
|
22 | 22 | import java.util.List; |
23 | | - |
24 | 23 | import org.apache.commons.lang3.StringUtils; |
25 | | - |
| 24 | +import com.vaadin.flow.component.ClickEvent; |
26 | 25 | import com.vaadin.flow.component.Component; |
| 26 | +import com.vaadin.flow.component.ComponentEventListener; |
| 27 | +import com.vaadin.flow.component.DomEvent; |
| 28 | +import com.vaadin.flow.component.EventData; |
27 | 29 | import com.vaadin.flow.component.HasSize; |
28 | 30 | import com.vaadin.flow.component.Synchronize; |
29 | 31 | import com.vaadin.flow.component.Tag; |
30 | 32 | import com.vaadin.flow.component.dependency.JsModule; |
31 | 33 | import com.vaadin.flow.component.dependency.NpmPackage; |
| 34 | +import com.vaadin.flow.shared.Registration; |
| 35 | +import elemental.json.JsonObject; |
| 36 | +import elemental.json.JsonValue; |
32 | 37 |
|
33 | 38 | @SuppressWarnings("serial") |
34 | 39 | @Tag("google-map") |
@@ -155,8 +160,9 @@ public void removePolygon(GoogleMapPolygon polygon) { |
155 | 160 | */ |
156 | 161 | public void addMarker(GoogleMapMarker marker) { |
157 | 162 | this.getElement().appendChild(marker.getElement()); |
158 | | - if (this.getElement().getParent() != null) |
| 163 | + if (this.getElement().getParent() != null) { |
159 | 164 | this.getElement().executeJs("this._updateMarkers()"); |
| 165 | + } |
160 | 166 | } |
161 | 167 |
|
162 | 168 | @SuppressWarnings("squid:S3242") |
@@ -236,4 +242,54 @@ public int getMinZoom() { |
236 | 242 | return this.getElement().getProperty("minZoom", 1); |
237 | 243 | } |
238 | 244 |
|
| 245 | + @DomEvent("google-map-click") |
| 246 | + public static class GoogleMapClickEvent extends ClickEvent<GoogleMap> { |
| 247 | + private final double lat; |
| 248 | + private final double lon; |
| 249 | + public double getLatitude() { |
| 250 | + return this.lat; |
| 251 | + } |
| 252 | + public double getLongitude() { |
| 253 | + return this.lon; |
| 254 | + } |
| 255 | + public GoogleMapClickEvent(GoogleMap source, boolean fromClient, |
| 256 | + @EventData(value = "event.detail.latLng") JsonValue latLng) { |
| 257 | + super(source); |
| 258 | + this.lat = ((JsonObject) latLng).getNumber("lat"); |
| 259 | + this.lon = ((JsonObject) latLng).getNumber("lng"); |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + public Registration addClickListener( |
| 264 | + ComponentEventListener<GoogleMapClickEvent> listener) { |
| 265 | + this.getElement().setProperty("clickable", true); |
| 266 | + this.getElement().setProperty("clickEvents", true); |
| 267 | + return addListener(GoogleMapClickEvent.class, listener); |
| 268 | + } |
| 269 | + |
| 270 | + @DomEvent("google-map-rightclick") |
| 271 | + public static class GoogleMapRightClickEvent extends ClickEvent<GoogleMap> { |
| 272 | + private final double lat; |
| 273 | + private final double lon; |
| 274 | + public double getLatitude() { |
| 275 | + return this.lat; |
| 276 | + } |
| 277 | + public double getLongitude() { |
| 278 | + return this.lon; |
| 279 | + } |
| 280 | + public GoogleMapRightClickEvent(GoogleMap source, boolean fromClient, |
| 281 | + @EventData(value = "event.detail.latLng") JsonValue latLng) { |
| 282 | + super(source); |
| 283 | + this.lat = ((JsonObject)latLng).getNumber("lat"); |
| 284 | + this.lon = ((JsonObject)latLng).getNumber("lng"); |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + public Registration addRightClickListener( |
| 289 | + ComponentEventListener<GoogleMapRightClickEvent> listener) { |
| 290 | + this.getElement().setProperty("clickable", true); |
| 291 | + this.getElement().setProperty("clickEvents", true); |
| 292 | + return addListener(GoogleMapRightClickEvent.class, listener); |
| 293 | + } |
| 294 | + |
239 | 295 | } |
0 commit comments