Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the ability to select features on the map with a click using OpenLayers.Control.SelectFeature. How can i add a double-click handler to that?

I have tried modifying this code to suite my needs, but it ends up overriding my SelectFeature. So i'm able to handle the double click, but the single click in the SelectFeature stops working.



<script type="text/javascript">
    var map, vectorLayer;

    function init() {
        map = new OpenLayers.Map('map');
        var layer = new OpenLayers.Layer.WMS("OpenLayers WMS",
                "", { layers: 'basic' });

        vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");

        map.addLayers([layer, vectorLayer]);

        var wkt = new OpenLayers.Format.WKT();

        polygonFeature ="POLYGON((-85.419086 49.25385,-55.05949 44.951293,-71.090388 1.315632,-91.743655 4.348987,-85.419086 49.25385))");

        var bounds = polygonFeature.geometry.getBounds();



    function addDoubleClickHandler() {

        var DblclickFeature = OpenLayers.Class(OpenLayers.Control, {
            initialize: function (layer, options) {
                OpenLayers.Control.prototype.initialize.apply(this, [options]);
                this.handler = new OpenLayers.Handler.Feature(this, layer, {
                    dblclick: this.dblclick

        var dblclick = new DblclickFeature(vectorLayer, {
            dblclick: function (event) {


    function addClickHandler() {

        var handler_featureselected = function (e) {
        var handler_featureunselected = function (e) {

        var selectControl = new OpenLayers.Control.SelectFeature(vectorLayer,
                hover: false,
                clickout: false,
                multiple: true,
                toggle: true,
                //box: true,
                eventListeners: {
                    featurehighlighted: handler_featureselected,
                    featureunhighlighted: handler_featureunselected
                //multipleKey: "shiftKey"


share|improve this question
CaptDragon, I'm having exactly the same issue - did you ever figure out a workaround? – tairngire Sep 10 '12 at 15:53
@tairngire I have not, sorry. – CaptDragon Sep 10 '12 at 17:19

I think you will get what you're looking for examining the source code of that page.

share|improve this answer
That's part of the code i am using. However, I'm trying to make it work with the SelectFeature. the link to the example you provided does the double click and single click on the map and does not select features. I guess i'll have to come up with my own SelectFeature based on the example you provided. That is, for all the features intersecting the mouse click/dblclick get the topmost and do a on it. I'll try it out. But i was hoping to somehow leverage OpenLayers.Control.SelectFeature. – CaptDragon Jul 6 '11 at 13:03

Your Answer


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.