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.

Possible Duplicate:
How to skip drag event to stop a feature being dragged

I've created a map and added markers to baselayer on click by using this code :

vectorLayer = new OpenLayers.Layer.Vector("Vectors");
        vectorLayer.id = "Vectors";
        map.addLayer(vectorLayer);

        map.events.register("click", map, function (e) {  

            //gets pixels on mouse position                    
            position = map.getLonLatFromPixel(e.xy);
            latitude = position.lat;
            longitude =position.lon;

            //Adding markers to vectorLayer 
            marker = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(longitude, latitude),
                { draggable: true },
                { externalGraphic: 'http://www.openlayers.org/dev/img/marker-blue.png',
                graphicHeight: 25, graphicWidth: 21,
                graphicXOffset: -((size.w / 2) - 2), graphicYOffset: -(size.h - 2) });

                // function markersIdGenerator() will return a random id for the marker 
                marker.id = markersIdGenerator();
                // Adding marker to vector layer
                vectorLayer.addFeatures(marker);                    
            });                

I've added DragFeature control to drag markers is there any way to fix a marker ?

I've tried like this:

draggable=true;
    dragmarker = new OpenLayers.Control.DragFeature(vectorLayer, {
        autoActivate: true,
        onEnter: function (marker) { 
            if (dragChecker(marker) == true) {                
                draggable = true;
                dragmarker.activate();
            }
            else {                
                dragmarker.deactivate();
                draggable = false;                
                return;
            }
        },
        onLeave: function (marker) {            
            if (draggable == false)
            { return; }
            else {
                Log("draggable value => "); Log(draggable);
                dragmarker.activate();
            }        
        },        
        onComplete: function (marker, pixel) {           
            if (draggable == false)
            { return; }
            else {     
                var fixer = confirm("Are you want to Fix this marker");
                if (fixer == true) {
                    marker.data.draggable = false;   
                    console.log("Fixed");                   
                }
                else {
                    marker.data.draggable = true;
                    console.log("Not Fixed");
                }
            }        
        }
    });
    map.addControl(dragmarker);

    //  this function will return whether the marker is dragable or not
    //  by checking marker.data.draggable
    function dragChecker(marker) 
    { 
        if (marker.data.draggable == true)
        { return true; }
        else
        { return false; }
    }
share|improve this question

marked as duplicate by whuber Aug 11 '12 at 20:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

I'v find out a way to fix a marker by deactivating the drag handler, for this example it is dragmarker.handlers.drag.deactivate(); , Special thanks to @drnextgis

share|improve this answer

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