Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

below is code that works for Openlayers drag function:

drag = new OpenLayers.Control.DragFeature(polygonLayer, {
    autoActivate: true,
    onComplete: function() {alert('Are you sure this is the right postion?')}
});

Now i,m trying to change my onComplete function:

drag = new OpenLayers.Control.DragFeature(polygonLayer, {
    autoActivate: true,
    onComplete: function (event){
        var bounds = event.features[0].geometry.getBounds();
        var answer = "bottom: " + bounds.bottom  + "\n";
        answer += "left: " + bounds.left  + "\n";
        answer += "right: " + bounds.right  + "\n";
        answer += "top: " + bounds.top  + "\n";
        alert(answer);
    }
});

I must be doing something wrong as this does not work?

share|improve this question
    
How does it not work? What are the error messages - if any? –  Chau Feb 9 '12 at 14:39
    
Don't get an error, I am able to drag my polygon, but when i drop it on a spot on the map , it does nothing as where my first alert works when i drop the polygon on the map. –  Blake Loizides Feb 9 '12 at 15:20
    
@Chau see post above. –  Blake Loizides Feb 9 '12 at 15:52

1 Answer 1

up vote 4 down vote accepted

You directly access the feature. So, the following code should work :

  drag = new OpenLayers.Control.DragFeature(polygonLayer, {
     autoActivate: true,
     onComplete: displayBounds
  });

function displayBounds(feature){
        var bounds = feature.geometry.getBounds();
        var answer = "bottom: " + bounds.bottom  + "\n";
        answer += "left: " + bounds.left  + "\n";
        answer += "right: " + bounds.right  + "\n";
        answer += "top: " + bounds.top  + "\n";
        alert(answer);
}
share|improve this answer
    
That was an excellent answer:) Still new to openlayers. –  Blake Loizides Feb 9 '12 at 18:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.