I'm have an OpenLayers map with a single vector layer containing many features. I've been using SelectFeature to pop up some info when a feature is clicked, and that's working fine. However, I now want to add some functionality when the feature is double-clicked - specifically I just want to zoom in, and not have the popup appear.

I gave this a shot: http://blog.slashpoundbang.com/post/2342888467/openlayers-zoom-when-a-feature-in-a-vector-layer-is But it removed my single-click functionality.

Essentially this is the same problem as SelectFeature with Double-Click

Any ideas?


So I'm trying a workaround using SelectFeature to handle the single click and registering an event listener on the vector layer to handle the double click. All I want to do is zoom in on the double clicked feature. This is what I have:

VEClayer.events.register('dblclick', VEClayer, function(e){
    map.zoomToExtent(e.features.geometry.getBounds(), closest=true);

However now I have another problem, and I'm not sure if it's being caused by having both SelectFeature and the listener active or what. The new issue is that try as I might I can't access any of the event attributes. So when I try to get e.features.geometry.getBounds(), Firebug gives me the error "e.features is undefined". I've tried to get this multiple other ways (e.xy, e.longlat, getMousePosition) and it's always the same result.

1 Answer 1


Did you look at OpenLayers.Handler.Click?

The select control takes an handler as option, and the above one has a boolean that should tell you if is single or double click.


Not exactly what you asked (select on dblClick; deselect on click) but should be easy to change

// Simple WFS layer
wfs = new OpenLayers.Layer.Vector(
        strategies: [new OpenLayers.Strategy.BBOX()],
        protocol: new OpenLayers.Protocol.WFS(
            url:  "/optima/geoserver/wfs",
            featureType: "node",
            featureNS: "http://piemonte.optima.sistemaits.com",
            geometryName: 'poin'

// Add a select control (note: this control is added to the map, but is disabled)
var select = new OpenLayers.Control.SelectFeature(
        multiple: false,
        clickout: true,             // Will be ignored (aka, you have to deselect a feature when no feature is found onClick)
        onSelect: function(feature)
            // ...
        onUnselect: function(feature)
            // ...


// Handler to intercept click.
handler = new OpenLayers.Handler.Click(
    select,  // The select control
        click: function(evt)
            console.warn(this); // OpenLayers.Control.SelectFeature
            var feature = this.layer.getFeatureFromEvent(evt);
            // clickout
        dblclick: function(evt)
            console.info(this); // OpenLayers.Control.SelectFeature
            var feat = this.layer.getFeatureFromEvent(evt);
            // Select a feature

        single: true,
        double: true,
        stopDouble: true,
        stopSingle: true

// select.activate();  // The select control must NOT be active
handler.activate();    // The handler will handles the click events for the select control
  • Beat me to it. (+1)
    – CaptDragon
    Commented Sep 12, 2012 at 17:19
  • Thanks a lot for your input, though I'm a little stumped as to how to make it work for me. You mean I can pass an instance of a Click handler in the constructor for my SelectFeature like so? var clickControl = new OpenLayers.Control.Click(); var selectControls = new OpenLayers.Control.SelectFeature(VEClayer,{onSelect: selectFeatureInfo, onUnselect: closeFeatureInfo, handlers: clickControl}); I'm not really sure how to make them work together; would I move my function calls (selectFeatureInfo, closeFeatureInfo) to my click handler? Sorry for my lack of knowledge, I'm new to OpenLayers.
    – tairngire
    Commented Sep 13, 2012 at 13:03
  • Thank you for that great example! I always get "undefined" from var feature = this.layer.getFeatureFromEvent(evt); I operate the handler on one Vector layer named "kmlLayer". Even if I try var feature = kmlLayer.getFeatureFromEvent(evt); I still get undefined. Any suggestions?
    – mephistho
    Commented Jan 22, 2013 at 15:16
  • @mephistho, what's the output of console.log(this)? Did you set the layer for the control? Or maybe could be that the handler is added to the map and activated before the layer is added to the map (the layer should be added before the handler)
    – Tommaso
    Commented Jan 24, 2013 at 13:31
  • @mephistho, i have same issue. feature get undefined. I have output the console.log(this). log returns me Openlayers.Control.SelectFeature.Openlayers.Class.initialize {} Commented Apr 27, 2015 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.