Thursday 16 February 2017

openlayers 2 - How to skip drag event to stop a feature being dragged


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 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.



Answer



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();
}
}


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...