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.

Hi GIS-Cracks,

I've been reading in this forum for a while and it helps me lot of times. Now I think it is the time to help me again but maybe other people too. So I try to describe a problem I have with OpenLayers 2.13 dev and the drag feature control.

First of all. I'am working on a bigger GIS-Applikation and the most libraries are bound to this. So I can't change them.

The Problem:

//=>layer for the control was created correctly (controled with firebug)
var dragCtrl = new OpenLayers.Control.DragFeature(editLayer);
app.mapPanel.map.addControl(dragCtrl);
dragCtrl.activate();
//=>if i use console.log at this time I can see the control was created correctly and
//looks like any other drag control on the map


//=>Just for explanation: the record element is from a geoext feature store
var lonlat = record.data.feature.geometry.bounds.getCenterLonLat();
var xy = lonlat.toShortString();
var xyArray = xy.split(', ')

var point = new OpenLayers.Geometry.Point(xyArray[0],xyArray[1]);

var feature = new OpenLayers.Feature.Vector(point);
editLayer.addFeatures(feature);
//=>at this time I expect that it should be possible to drag the added feature on the
//layer

The snippet of code is used in a listener which is executed each time I select a row in a table where some features are stored. So each time there will be a new element of OpenLayers.Control.DragFeature. This is only for testing. Now the strange thing. The first time I call this snippet above I can't drag the feature on the layer. Even if I zoom the map and redraw the layer.

But if I call the code again the new control is added to the map (I have now 2 new dragcontrols at the map => firebug) and a new feature on the layer the drag control works like a charm. For every feature. Also if I call it again and again (new control each time). It doesn't matter where I create the control and where I add it (also if I creates it only one time at the init of the application). If I have only one control on the layer it doesn't work. Each new one works.

Only the first time it fails. What is the problem here?

It is a simple piece of code i think. But I banging my head for it about one week without any solution. I really hope that the solution is simple and I just missed a little detail. Maybe there is anybody out there who had the same problem?!

Thanks for any help. Kalle

share|improve this question
add comment

1 Answer 1

In my case I had an active select control on another layer. You need to .deactivate() any select controls in order for the drag control to work.

      //deactivate control on layer 1:
      this.selectControlOnLayer1.deactivate();

      //activate Layer2 control:
      this.dragControlOnLayer2.activate();

      // and vice-versa to go back to select controls.

this seemed relevant, from the Openlayers Documentation :

"The activate call will move the vector layer to the forefront of the map, so that all events will occur on this layer.

As of OpenLayers 2.7, there is no support for selecting features from more than a single vector layer at a time. The layer which is currently being used for selection is the last one on which the .activate() method of the attached select feature control was called."

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.