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 am new to OpenLayers and I'm trying to drag markers and skip some markers from being dragged, I've tried dragFeature.deactivate(); it will deactivate entire features please help me.

Please check this code :

dragFeature = new OpenLayers.Control.DragFeature(vectorLayer, {
    autoActivate: true,
    onEnter: function (feature) {                 
        //  example assign : x=1;
        //  if(x==0){ continue draging of a feature }
        //  else{  stop a feature from being dragged }
    },
    onLeave: function (feature) {            

    },
    onStart: function (feature, pixel) {
    },        
    onComplete: function (feature, pixel) {
    }
});
map.addControl(dragFeature);
dragFeature.activate();

Please help me. thanks in advance..

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You can check feature attributes and deactivate drag handler for some values:

drag.onStart = function(f,p) {
    if (f.attributes.draggable === false) {
        drag.handlers.drag.deactivate();
    }
}

LIVE DEMO

share|improve this answer
    
Thanks for the help, after deactivating handler when I mouse over to a fixed feature it shows a crosshair cursor, is there any way to avoid that, so that i can fix other events on that fixed feature. –  bios Aug 11 '12 at 3:57
    
You should override overFeature method of DragFeature control. I've updated my live demo. Please check it out. –  drnextgis Aug 11 '12 at 7:46
    
Thanks its working. –  bios Aug 11 '12 at 7:55

It looks like there is typo in your code.

dragFeature = new OpenLayers.Control.DragFeature(vectorLayer, {
    autoActivate: true,
    onEnter: function (feature) {                 
        //  example assign : x=1;
        //  if(x==0){ continue draging of a feature }
        //  else{  stop a feature from being dragged }
    },
    onLeave: function (feature) {            
},
onStart: function (feature, pixel) {
}**,**        
onComplete: function (feature, pixel) {
}
});

I am just pointing typo, there might be you already solved the problem. :)

share|improve this answer

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.