wiki:SelectFeatureControlMapDragIssues

OpenLayers 2 is outdated. Go to the latest 3.x version: http://openlayers.org/

SelectFeature Control Map Drag Issues

If you have a layer with features and a SelectFeature Control attached to that, you might want to be able to drag the map whilst having the mouse pointer over a feature. At present OpenLayers does not allow you to do that using API methods, but there is a workaround:

See the following FAQ entry http://faq.openlayers.org/vector-related-questions/why-cant-i-drag-the-map-when-my-mouse-is-over-a-vector-feature/ for a solution

Copied from an old archive:

Why can't I drag the map when my mouse cursor is over a vector feature?

If you have a layer with features and a SelectFeature Control attached to that, you might want to be able to drag the map whilst having the mouse pointer over a feature. At present OpenLayers does not allow you to do that using API methods, but there is a workaround:

Suppose you have the following code (or something similar):

 selectFeatureControl = new OpenLayers.Control.SelectFeature(layer,{
       onSelect: onFeatureSelect, 
       onUnselect: onFeatureUnselect
 });

You can add the following lines to allow for dragging the map when your mouse cursor is over a feature:

    if (typeof(selectFeatureControl.handlers) != "undefined") { // OL 2.7
        selectFeatureControl.handlers.feature.stopDown = false;
    } else if (typeof(selectFeatureControl.handler) != "undefined") { // OL < 2.7
        selectFeatureControl.handler.stopDown = false; 
        selectFeatureControl.handler.stopUp = false; 
    }

The internal structure for the SelectFeature Control has changed from version 2.6 to 2.7, therefore there is if/then/else statement. Please note that this is an unsupported feature and could change without notice in newer OpenLayers releases.

Last modified 2 months ago Last modified on May 20, 2016 12:22:13 AM