1

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

2

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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