[mapguide-users] patch for Mouse Wheel Zoom, set scale and image on loading map in Ajax.

Jackie Ng jackie.ng at aecsystems.com.au
Mon Apr 2 05:45:47 EDT 2007


Here's a solution I've been working on, it's based on the snippet of js found
here: http://adomas.org/javascript-mouse-wheel/

This code currently works for firefox, but not internet explorer. (I just
can't get the stubborn browser to fire onmousewheel !). If anyone can help
to get this to work in IE, would be appreciated.

/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
function handle(delta) {
    var mapFrame = ViewerFrame.GetMapFrame();
    //We will map the scroll of the mouse wheel to the movement of the
slider bar.
    //Therefore, we want to invoke ZoomCloser(e) / ZoomFurther(e) in the map
frame.
    //We need to fake a mousedown event in order to invoke it.
    var evt = document.createEvent("MouseEvents");
    //The important things here are that the event must be "mousedown". 
    evt.initMouseEvent("mousedown", true, true, window, 1, 0, 0, 0, 0,
false, false, false, false, 0, null);
    if (delta < 0) //negative delta -> mouse scroll backwards -> zoom out
		mapFrame.ZoomFurther(evt);
    else //positive delta -> mouse scroll forwards -> zoom in
		mapFrame.ZoomCloser(evt);
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;




Hope that helps

- Jackie


Jose Manuel C G wrote:
> 
> Nice job. 
> 
> This patch has been created to be applied in the internal source code.
> Your code is out from the ajax viewer code.
> 
> I want another people participe to show the code they have created. Always
> thinking to add/fix/modify problems in the code.
> 
> You solution is one in a million. We can't see how you design it because
> you don't show it, but I understand you don't want to modify the viewer
> code.
> 
> bye.
> 

-- 
View this message in context: http://www.nabble.com/patch-for-Mouse-Wheel-Zoom%2C-set-scale-and-image-on-loading-map-in-Ajax.-tf3491633s16610.html#a9787653
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list