[OpenLayers-Users] combining drag and select layers on one map - drag not working

Charlie DeTar chazen at gmail.com
Sat Apr 4 10:40:09 EDT 2009


Hi,

I'm trying to construct a map that contains a draggable marker in
addition to features that, when clicked, produce a popup.  Reading the
docs and examples, it seemed that the way to do this is to use a vector
layer with a DragFeature control, and an additional vector layer with a
SelectFeature control to handle popups.  However, I'm finding that once
the SelectFeature control has been activated, the DragFeature no longer
works -- dragging only pans the map.  I'm testing this using Firefox 3.0
under Linux with stable OpenLayers (2.7).

I've been trying to figure out if this has something to do with event
propagation, and have tried setting stopUp and stopDown to false for
both the dragFeature and selectFeature handlers to no effect.  Calling
dragFeature.handlers.feature.moveLayerToTop() makes the drag handler
work, but kills the selectFeature, regardless of what order the layers
are added.  Though I would like both layers working simultaneously, I
did find that disabling the selectable layer using the LayerSwitcher
made the drag control work again in stable 2.7, but in the latest SVN
R9190 dragging still doesn't work after disabling the selectable layer.

Any suggestions for how I might be able to get a draggable layer and
separate popup-producing layer working simultaneously on one map?

Here are routines I'm using to construct the layers:

var map;
function init() {
    map = new OpenLayers.Map('map');
    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.addLayer(
       new OpenLayers.Layer.WMS("OpenLayers WMS",
            "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} )
    );

    map.setCenter(new OpenLayers.Geometry.Point(0, 0), 4);

    add_draggable();
    add_selectable();
}
function add_draggable() {
    var draggable = new OpenLayers.Layer.Vector(
            "Draggable",
            {
                styleMap: new OpenLayers.StyleMap({
                    externalGraphic:
                        "http://openlayers.org/dev/img/marker-gold.png",
                    pointRadius: 10
                }),
            }
    );
    map.addLayer(draggable)
    draggable.addFeatures([
        new OpenLayers.Feature.Vector(
           new OpenLayers.Geometry.Point(0, 0)
        )
    ]);

    var dragFeature = new OpenLayers.Control.DragFeature(draggable);
    map.addControl(dragFeature);
    dragFeature.activate();
}
function add_selectable() {
    var selectable = new OpenLayers.Layer.Vector("Selectable");
    selectable.addFeatures([
        new OpenLayers.Feature.Vector(
             new OpenLayers.Geometry.Point(5, 5)),
        new OpenLayers.Feature.Vector(
             new OpenLayers.Geometry.Point(-5, -5)),
    ]);
    map.addLayer(selectable);

    var selectControl = new
         OpenLayers.Control.SelectFeature(selectable);
    map.addControl(selectControl);
    selectControl.activate();
}

cheers,
Charlie



More information about the Users mailing list