[mapguide-users] RE: OnMouseWheel Zoom in and Zoom out

Ivan Miličević Ivan.Milicevic at supranet.hr
Tue Apr 13 03:30:00 EDT 2010


So, here is code. You can copy/paste it over existing in ajaxmappane.templ. Be aware of inEditMode variable.


//this is the key
var inEditMode = true;

function HandleMouseWheelEvent(delta, event)
{
    //if you are NOT in editing mode
    if(!inEditMode)
    {
        if(!mapInit || mapLoading)
        {
            return false;
        }

        //Clear any existing map redraw events
        if(wheelZoomTimer > 0)
        {
            clearInterval(wheelZoomTimer);
            wheelZoomTimer = 0;
        }

        if(wheelZoomDelta == null)
        {
            //Determine the cursor position
            wheelZoomCursor = new Point(msie ? event.clientX - mapPosX : event.screenX - mapPosX,
                msie ? event.clientY : event.screenY);
            if(wheelZoomCursor.X < 0)
            {
                //Do not process wheel events in the property or legend area
                return false;
            }
            wheelZoomDelta = 0;
        }

        //Determine the desired change in zoom
        wheelZoomDelta += delta;
        var currentScale = CalculateScale();
        var newScale = GetNewScale(currentScale, wheelZoomDelta);
        var zoomChange = currentScale / newScale;

        //Determine the center of the new, zoomed map, in current screen device coords
        var screenZoomCenterX = wheelZoomCursor.X - (wheelZoomCursor.X - mapDevW/2) / zoomChange;
        var screenZoomCenterY = wheelZoomCursor.Y - (wheelZoomCursor.Y - mapDevH/2) / zoomChange;

        //Adjust the existing map image to the new scale and location
        w = parseInt((extX2 - extX1) * metersPerUnit / (newScale * metersPerPixel));
        if(w > 20000)
        {
            w = 20000;
        }
        h = parseInt(w * (mapDevH / mapDevW));
        var xClickOffset = screenZoomCenterX - mapDevW/2;
        var yClickOffset = screenZoomCenterY - mapDevH/2;
        xi = parseInt(mapDevW/2 - w / 2 - xClickOffset * zoomChange);
        yi = parseInt(mapDevH/2 - h / 2 - yClickOffset * zoomChange);
        img = document.getElementById(msie6minus ? "img1div": curimg);
        if(img)
        {
            imgs = img.style;
            imgs.position = "absolute";
            imgs.left = xi;
            imgs.top = yi;
            imgs.width = w;
            imgs.height = h;
        }

        selImg = document.getElementById(msie6minus ? "selImg1div": curSelImg);
        if(selImg)
        {
            selImg.style.position = "absolute";
            selImg.style.left = xi;
            selImg.style.top = yi;
            selImg.style.width = w;
            selImg.style.height = h;
        }

        //Update scale displayed in status bar
        parent.OnScaleChanged(newScale);

        //Reload the map at the new scale. 500ms delay to allow for more
        //mouse wheel events.
        wheelZoomCenter = ScreenToMapUnits2(screenZoomCenterX, screenZoomCenterY, true);
        wheelZoomScale = newScale;
        wheelZoomTimer = setInterval(WheelZoom, 500);
    }
    else
    {
        //if you are in editing mode...
        return false;
    }
}

-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of SriRam007
Sent: Tuesday, April 13, 2010 6:49 AM
To: mapguide-users at lists.osgeo.org
Subject: [mapguide-users] RE: OnMouseWheel Zoom in and Zoom out


yes I m creating a site where people can edit data

And during editing i want to disable the zoom in and zoom out functionality

There are two button
Edit : To start editing feature -->On this button click i want to disable
the both functionality.
Update : To Update modified feature  -->On this button click i want to
enable again the both functionality.


This is our requirement and i have to do it with out changing inside the
viewers file.

If this is not possible using MGOS (Ajax viewer,C#.net,Javascript) Please
tell me.


thanks


-- 
View this message in context: http://n2.nabble.com/OnMouseWheel-Zoom-in-and-Zoom-out-tp4889474p4894255.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users


More information about the mapguide-users mailing list