Limiting panning?

3877
6
05-28-2012 10:34 AM
JamesColeman1
New Contributor
In the sample projects as well as the app I've been working on, I've noticed that I can drag past the viewable area of the map. It appears that I can drag the map so far as to place any of the four corners in the center point of the screen. If I enable wrap-around, it makes this unnoticeable in the horizontal plane, but it's still a problem in the vertical plane.

How do I limit the panning so the user can't drag past the edge of the map? So there aren't ever white bars around the actual map area?
0 Kudos
6 Replies
RickJones
Occasional Contributor II
Add an observer

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToPan:)name:@"MapDidEndPanning" object:nil];

and check if the user has panned beyond an arbitrary extent. If so, move them back.


- (void)respondToPan:(NSNotification*)notification {
    // get the current envelope
   
    if (extent is outside top/bottom/left/right bounds) {
        // bounce back
        // map envelope = corrected envelope
    }
0 Kudos
DiveshGoyal
Esri Regular Contributor
Actually, we put in an enhancement at v2.1 of the SDK to prevent the map from panning outside the map's maxEnvelope property. By default, this is set to the full envelope of the basemap layer.

So, if you're using v2.1 or higher, you shouldn't have to do anything really.

Can you check the maxEnvelope property of your map and ensure it is appropriate?
0 Kudos
JamesColeman1
New Contributor
I've been using the envelope that's specified by the included Bing Maps layer since my layer uses the same WKID. That envelope is basically -20037508.342 to 20037508.342 in both planes. That's not correct for the X plane since that projection doesn't go all the way to the poles, but it should be correct for the Y plane (since the total width of the map is approximately 40075016.704. And with those numbers it exhibits the problem I described.

Interestingly enough I noticed that if I used 1/2 of those numbers, it seemed to be correct. Is it possible that the way the limited panning works is that it's limiting the panning in a way that allows the user to pan so that the edge of the map is near the center point of the screen?
0 Kudos
NimeshJarecha
Esri Regular Contributor
Yes, your understanding is correct. The AGSMapView's maxEnvelope limits the amount by which the map can be panned such that its anchor point (typically the center) never goes outside this envelope.

Hope this helps!

Regards,
Nimesh
0 Kudos
JamesColeman1
New Contributor
So is there a way to limit panning such the viewable screen area can never be panned past the edge of the map? The maxEnvelope property has to be the full size of the map, since if you set it to be smaller then you can pan correctly when zoomed in. But this means that you will be able to pan in such a way that there are white bars surrounding the map.

Is the only way to watch for this happening programmatically and telling the map view to snap back? Or is this already a feature I'm missing in the SDK?
0 Kudos
NimeshJarecha
Esri Regular Contributor
AGSMapView's maxEnvelope is the only option in the SDK to limit the pan/zoom.

Regards,
Nimesh
0 Kudos