how to disable pan and zoom and use drag

7282
7
08-10-2012 07:31 AM
HamzaHaroon
Occasional Contributor
im using the sketch layer sample, and want to disable pan and zoom when the toolbar items are selected. how do i do this?
also, how can i use drag to draw instead of touch?
0 Kudos
7 Replies
NimeshJarecha
Esri Regular Contributor
You can't disable the pan/zoom of map. You should add a transparent UIView on top of it which will receive all touches and then you can convert those touch point into map point.

Regards,
Nimesh
0 Kudos
ReedHunter
New Contributor III

Once I have used AGSMapView toMapPoint to create the mapPoint object within my custom, transparent UIView's UITapGestureRecognizer event handler, what selector on the mapView can I call with my mapPoint parameter so that the AGSMapView's didClickAtPoint event will be triggered?

There seems no programmatic way to trigger the AGSMapViewTouchDelegate's events.

0 Kudos
ReedHunter
New Contributor III

Some clarification ...

I need to lock down the map mode so users don't switch from Navigation, Compass, or Auto-Center mode to manual pan (AGSLocation/displayAutoPanModeOff) with accidental swipes of the screen.  This has generated user complaints from fans of navigation mode.  I'm trying to implement what I'm calling "locked" navigation, compass, and auto-center modes, each making the map view ignore swipes.

Disabling user interaction is no solution because they need taps to identify and edit features, and they want the tap-hold for accessing the magnifier.

The context for my question above is I'm trying out a transparent UIView above the map view such as outlined here: how to disable pan and zoom and use drag​, only passing the taps and the tap-holds through to the map. I'm not seeing a way though to call the map view programmatically from my UIView's gesture handlers to make it think it's been tapped.

Since that hasn't worked, I'm also looking into overriding the map view's gesture handlers to ignore swipes.

Thanks

0 Kudos
ReedHunter
New Contributor III

I came up with a solution that's working well, but will require my review each time the iOS SDK is updated to a new version: remove any array elements from AGSMapView.gestureRecognizers that handle the user interaction I want to restrict.  At the current release, there are seven gestureRecognizers, and the three I keep are the UILongPressGestureRecognizer (I have enabled the magnifier) and the two UITapGestureRecognizers.  This lets the map support identify, editing, and the magnifier without letting the users accidentally pan the map out of the navigation, auto-center, or compass modes.  I save the others in a module level array in my view controller, adding them back to the AGSMapView's gestureRecognizers when the user picks a "non-locked" map mode from the UI picker I made.

The ones I set aside are UIPanGestureRecognizer, AGSMultiTapGestureRecognizer, UIPinchGestureRecognizer, and UIRotationGestureRecognizer.  This routine below is what I call to "lock" the current map mode, and I have another written in the reverse logic to "unlock" the map mode.

- (void) removePanGesturesFromMap {

     NSMutableArray * mutableGestureRecognizers = [[NSMutableArray alloc] initWithArray:self.mapView.gestureRecognizers];

     NSMutableArray *recognizersToRemove = [[NSMutableArray alloc] init];

     for (UIGestureRecognizer * gestureRecognizer in self.mapView.gestureRecognizers) {

          if (![gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]

            && ![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] ) {

               [recognizersToRemove addObject:gestureRecognizer];

          }

     }

     if (recognizersToRemove.count > 0) {

          [mutableGestureRecognizers removeObjectsInArray:(NSArray*) recognizersToRemove];

          self.preservedMapPanGestureHandlers = recognizersToRemove;

          self.mapView.gestureRecognizers = (NSArray*)mutableGestureRecognizers;

     }

}

0 Kudos
HamzaHaroon
Occasional Contributor
thanks. im using an opengl view so that i can free hand draw. only problem im having is making the drawing stay at certain geological coordinates. to convert an agspoint to a cgpoint do i have to implement the toScreenPoint: method myself, or i just have to call it. is there any example of this method?
0 Kudos
NimeshJarecha
Esri Regular Contributor
Normal UIView is good enough for a free hand draw. AGSMapView has toScreenPoint method.

Regards,
Nimesh
0 Kudos
AkhilChoran_Balan
New Contributor

Can we have this as a feature to AGSMapView? MapKit framework has scrollEnabled property to do this. A similar property can be added to AGSMapView so that scroll and pan can be disabled and user can still tap on Graphics on the screen. I am sure this would be a common use case when people are doing free hand drawing/geo fence on maps.

Regards,

Akhil

0 Kudos