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.

I have the following code:

    function mapCreate(lon,lat){
    map = new OpenLayers.Map("map1");
    var osm = new OpenLayers.Layer.OSM();
    vectors = new OpenLayers.Layer.Vector("Vector Layer");
    map.addLayer(osm);
    var center = new OpenLayers.LonLat(lon,lat).transform(
        new OpenLayers.Projection("EPSG:4326"),
        map.getProjectionObject()
    );

    point = new OpenLayers.Geometry.Point(center.lon,center.lat);
    vectors.addFeatures([new OpenLayers.Feature.Vector(point)]);
    drag = new OpenLayers.Control.DragFeature(vectors);
    //map.addLayer(vectors);
    map.addControl(drag);
    drag.activate();
    map.setCenter(center, 15);
    map.addLayer(vectors);
    point.events.register('moveend',point, function(evt){
        alert('hello');
    });

}

The part that does not work is:

        point.events.register('moveend',point, function(evt){
        alert('hello');
    });

Can anyone help me with creating an event listener for a point in open layers?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You should use onComplete property of OpenLayers.Control.DragFeature, for example:

drag = new OpenLayers.Control.DragFeature(vectors, {
    autoActivate: true,
    onComplete: function() {alert('hello')}
});

Here is my online example: DragFeature.

share|improve this answer
    
Thanks, this helped me out too. Question: It strikes me that having to pass an empty function to a control to make it work is, well...kind of dumb. What is going on here that leads to this? –  bshender May 2 '13 at 13:43

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.