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.

I am using OpenLayers. When a user holds Shift, clicks on map and moves the mouse, the box is shown. When user releases the mouse button, I intercept the event and use the coordinates of the box.

        var boxControl = new OpenLayers.Control();
        OpenLayers.Util.extend(boxControl, {
            draw: function () {
                // this Handler.Box will intercept the shift-mousedown
                // before Control.MouseDefault gets to see it
                this.box = new OpenLayers.Handler.Box(boxControl,
                        { "done": this.notice },
                    { keyMask: OpenLayers.Handler.MOD_SHIFT });
                this.box.activate();
            },

            notice: function (bounds) {

                var ll = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.left, bounds.bottom));
                var ur = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.right, bounds.top));
                doSomething(ll, ur);
            }
        });
        map.addControl(boxControl);

It works when with Shift button. But when I change MOD_SHIFT to MOD_ALT, my code is ignored, the bounding box is never shown on screen and "notice" function is never called.

Could you help to fix it (for either Alt or Control buttons), please?

PS. I cannot use OpenLayers.Control.Select

share|improve this question

1 Answer 1

Can you also put your map initializing code here? I'm not 100% sure, but please note when you initialize map object without any controls provided, the map object will be created associated with 4 controls, and among the is the OpenLayers.Control.Navigation control by which you can draw zoombox on map (behind it is a OpenLayers.Handler.Box handler with default MOD_SHIFT keymask). So I doubt if this boxControl actually takes effect.

share|improve this answer
    
I will check, thanks! –  Maxim Eliseev Jun 26 '13 at 11:05

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.