2

i'm new to ArcObjects and i'm trying to make a program that uses an axmapcontrol and i wanted to zoom in and zoom out using the pointer , i've searched here and i've found this link which shows how to return x and y , i wanted to know what x and y do this lines of code return

How can one get the value of the point where the AxMapControl is centered at?

1

The first task here is to get the location of the pointer, you can get this from the events OnMouseDown and OnMouseMove, these will return the coordinates in screen coordinates and also map coordinates... depending on whether you want to click the map or zoom where the pointer currently is will decide which one you want to use.

To zoom the map it should be as simple as getting the extent, panning to the mouse location, reducing and then replacing it, like this example using OnMouseDown:

void OnMouseDown(long Button, long shift, long X, long Y, double mapX, double mapY)
{
    IEnvelope pExtent = MyMapControl.Extent;
    IPoint pZoomCentre = new PointClass();
    pZoomCentre.PutCoords(mapX, mapY);
    pZoomCentre.SpatialReference = pExtent.SpatialReference; // important to set spatial reference
    pExtent.CenterAt(pZoomCentre);
    if (shift == 0)
    { 
        // not holding down shift, alt or control = zoom in
        pExtent.Expand(0.5, 0.5, true); // half size                
    }
    else
    { 
        // holding down sift, alt or control = zoom out
        pExtent.Expand(2, 2, true); // double size  
    }
    MyMapControl.Extent = pExtent;
    MyMapControl.Refresh(); // update view
}

To get this to work you need to wire the OnMouseXXX events, this one's a little old but covers the basics, this one is newer but is slightly unrelated and a JAVA version here.

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.