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.

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
add comment

2 Answers

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
    }
  }
});
map.addControl(dragger);

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

You mean like this example?

http://openlayers.org/dev/examples/drag-feature.html

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
add comment

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.