Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to make one vector layer (or a certain kind of feature draggable), while the other types of feature or layer is not?

share|improve this question

You mean like this example?

See the DragFeature control for details. If you do not want to drag all features in a layer then set the geometryTypes property, or add your own custom logic to the onStart event to stop a feature being dragged if itdoes not meet your criteria.

share|improve this answer

I would comment on @geographika's answer but I don't have any reputation.

In case you need finer control over exactly which feature can be dragged, actually it can't be done from onStart. But you can supply featureCallbacks as in this example.

// these are set up as in drag-feature example
var map = new OpenLayers.Map( /* ... */ );
var vectors = new OpenLayers.Layer.Vector( /* ... */ );

// this specialized DragFeature control will only drag the single
// feature which is set as dragger.interesting_feature.
var dragger = new OpenLayers.Control.DragFeature(vectors, {
  autoActivate: false,
  onComplete: function(vertex) {
    // drag complete, do something interesting here
  featureCallbacks: {
    // called when a feature is clicked
    click: function(feature) {
      if (feature === this.interesting_feature) {
        return this.clickFeature(feature); // do the default thing
      // otherwise do nothing
    // called when mouse goes over a feature
    over: function(feature) {
      if (feature === this.interesting_feature) {
        return this.overFeature(feature); // do the default thing
      // otherwise do nothing

// to use the single-feature drag control, do this
dragger.interesting_feature = my_interesting_feature;
share|improve this answer

Your Answer


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.