FlowingCode/GoogleMapsAddon

Add DomEvent for google-map-marker-dragend marker event

Closed this issue · 1 comments

paodb commented

There was this question on directory:

I would like to know how to retrieve the new (after dragend) LAT and LON values since I cannot retrieve them with the following.

addMarker.setDraggable(true);
addMarker.getElement().setProperty("dragEvents", true);
addMarker.getElement().addEventListener("google-map-marker-dragend", l -> {
Notification.show(addMarker.getPosition().toString());
});

The listener does fire but I get the old LON and LAT results.

I made it work like this:

addMarker.setDraggable(true);
addMarker.getElement().setProperty("dragEvents", true);
addMarker.getElement().addEventListener("google-map-marker-dragend", event -> {
        JsonObject eventData = event.getEventData();
        JsonObject latLng = eventData.getObject("event.detail.latLng");
        Notification.show("Lat: " + latLng.getNumber("lat") + " - Lng: " + latLng.getNumber("lng"));
      }).addEventData("event.detail.latLng");

But I think it will be a better idea to define a DomEvent for "google-map-marker-dragend" event in GoogleMapMarker class so the call to get the new position is simplified by just adding a listener.

paodb commented

Currently blocked by google-map #7