[mapguide-users] Zoom Rectangle tool observations and (in my situation) fix

nclayton nclayton at gmail.com
Thu Mar 13 14:39:42 EDT 2008


Hi everyone,
I'd noticed in working with MGOS (1.2 and 2.0) that the zoom rectangle tool
seemed a bit "off", in that
I would create a rectangle around and area and it would actually zoom in
closer than I felt it should.

This may have been an intentional action, but for my needs, I needed it to
zoom to display the entire area covered by the rectangle. Here are the
changes I made to make that happen:

ajaxmappage.templ
===========================================================================
function ExecuteRectangleTool()
{
    var x1, x2;
    var y1, y2;

    if(rcx1 <= rcx2)
    {
        x1 = rcx1;
        x2 = rcx2;
    }
    else
    {
        x1 = rcx2;
        x2 = rcx1;
    }

    if(rcy1 <= rcy2)
    {
        y1 = rcy1;
        y2 = rcy2;
    }
    else
    {
        y1 = rcy2;
        y2 = rcy1;
    }

    if(tool == 3)
    {
        if((x2 - x1 <= 2) && (y2 - y1 <= 2))
            return;

        pt1 = ScreenToMapUnits(x1, y1);
        pt2 = ScreenToMapUnits(x2, y2);

        mcsW = pt2.X - pt1.X;
        mcsH = pt2.Y - pt1.Y;

        //Accommodate for mcsH being a negative value by multiplying by -1
to make it a positive value
	if(mcsH < 0)
		mcsH = mcsH * -1;

        //Determin the lower values between pt1.X and pt2.X then pt1.Y and
pt2.Y
	var lowX = (pt1.X < pt2.X? pt1.X: pt2.X);
	var lowY = (pt1.Y < pt2.Y? pt1.Y: pt2.Y);	

        scale = CalculateScale1(mcsW, mcsH, mapDevW, mapDevH);
        scale = finscale? GetNearestFiniteScale(scale):
NormalizeScale(scale);
        HideMapImage();

        //Make chage here so that mcsW/2 and mcsH/2 are always added to the
lower of the X and Y values
	GotoView(lowX + mcsW/2, lowY + mcsH/2, scale, true, false);
    }
    else if(tool == 0)
    {
        if((x2 - x1 <= 2) && (y2 - y1 <= 2))
        {
            pt1 = ScreenToMapUnits(x1-2, y1-2);
            pt2 = ScreenToMapUnits(x1+2, y1+2);
            RequestPointSelection(pt1.X, pt1.Y, pt2.X, pt2.Y, appending);
        }
        else
        {
            pt1 = ScreenToMapUnits(x1, y1);
            pt2 = ScreenToMapUnits(x2, y2);
            RequestRectSelection(pt1.X, pt1.Y, pt2.X, pt2.Y, appending);
        }
    }
}

-- 
View this message in context: http://www.nabble.com/Zoom-Rectangle-tool-observations-and-%28in-my-situation%29-fix-tp16035155s16610p16035155.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list