kiks73
kiks73

Reputation: 3758

Google Maps API data layer feature. Event dragend not fired

I've got a data layer:

mylayer.loadGeoJson(myGeoJsonString);
mylayer.setStyle(function(feature){
    var col = feature.getProperty('strokeColor');
    return  { strokeColor: col,
        strokeWeight: 3,
        fillOpacity: 0,
        clickable: true,
        draggable: true             
    }
});

Every feature can be moved on the map with a drag operation with mouse, but if I try to add a listener to the dragend event:

    mylayer.addListener('dragend', function(event) {
        if (confirm("Do you really want to move it?")) {
            console.log ("Moved, need to update spatial DB...");
        }
    }); 

But event does not fire (checked with a Google Chrome Debug Console breakpoint too).

Where am I wrong?

Upvotes: 2

Views: 694

Answers (2)

Android Enthusiast
Android Enthusiast

Reputation: 4950

When you make calls to the Data Layer API, you can receive the status of the call when it completes as well as listen for any changes that the call ends up making with listeners.

You'll notice that calls to the Data Layer API sometimes return a 'PendingResult'. As soon as the 'PendingResult' is created, the operation is queued in the background, so the PendingResult lets you wait for the result status, either synchronously or asynchronously.

If your code is running on the main UI thread, do not make blocking calls to the Data LayerAPI. You can run the calls asynchronously by adding a callback method to the PendingResult.

If your code is running on a separate handler thread in a background service, its fine for the calls to block. In this case, you can call "await()' on the PendingResult.

For more information regarding Event handling, please follw this link: https://developers.google.com/maps/documentation/javascript/examples/layer-data-event

Upvotes: 0

geocodezip
geocodezip

Reputation: 161324

There is no dragend event on the Google Maps Javascript API Data Layer

See this answer for available events: What events are available for google.maps.data.addListener? or the documentation

Available Events:

  • addfeature
  • click
  • mousedown
  • mouseout
  • mouseover
  • mouseup
  • removefeature
  • removeproperty
  • rightclicksetgeometry
  • setproperty

Upvotes: 4

Related Questions