Events and gestures
The map component provided by the TomTom Map Display module reacts to different gestures with predefined behaviors, but you can also customize these gestures. The map supports the following gestures by default:
- Panning - moving one finger to drag the map.
- Zooming:
- Pinching to zoom in or out (scaling).
- Double-tapping to zoom in (scaling).
- Double-tapping and dragging to zoom in or out.
- Two-finger tap to zoom out.
- Rotating - rotating two fingers around each other.
- Tilting - moving two fingers up or down on the map in parallel.
Delegates
The Map Display module provides several map events called MapInteraction
.
- Map interactions -
MapDelegate.map(_:onInteraction:)
To implement a delegate method:
First, conform your class to MapDelegate
.
Then set the map delegate to your class.
Next, add the MapDelegate.map(_:onInteraction:)
protocol method. After these steps are completed, the MapDelegate.map(_:onInteraction:)
method is triggered whenever the user interacts with the map.
1func map(_ map: TomTomMap, onInteraction interaction: MapInteraction) {2 switch interaction {3 case let .tapped(coordinate):4 /* YOUR CODE GOES HERE */5 break6 case let .tappedOnAnnotation(annotation, coordinate):7 /* YOUR CODE GOES HERE */8 break9 case let .tappedOnLocationMarker(coordinate):10 /* YOUR CODE GOES HERE */11 break12 case .tappedOnRecenterButton:13 /* YOUR CODE GOES HERE */14 break15 case let .doubleTapped(coordinate):16 /* YOUR CODE GOES HERE */17 break18 case let .tappedWithTwoFingers(coordinate):19 /* YOUR CODE GOES HERE */20 break21 case let .longPressed(coordinate):22 /* YOUR CODE GOES HERE */23 break24 case let .panned(state):25 /* YOUR CODE GOES HERE */26 break27 case let .pinched(state):28 /* YOUR CODE GOES HERE */29 break30 case let .rotated(state):31 /* YOUR CODE GOES HERE */32 break33 case let .tilted(state):34 /* YOUR CODE GOES HERE */35 break36 default:37 break38 }39}
Disabling gestures
In the Map Display module, you can explicitly disable specific gestures. To do this, set the array of disabled gestures:
map.disabledGestures = [.doubleTap, .tap]
Gesture exclusions
The Map Display module includes functionality to choose circumstances where specific gestures are ignored. For example, if the map is being scaled (zoomed in or out), the user can’t pan it until the scaling is complete. To set a gesture exclusion, use the setExclusiveGestures(gesture: GestureType, blockedGestures: [GestureType])
method. Use the gesture parameter to specify which gesture is to be ignored.
For example: You can change the pan gesture exclusions as follows:
map.setExclusiveGestures(gesture: .pan, blockedGestures: [.pinch])
Then when you start scaling the map, panning is disabled. The Map Display module uses the following default configuration for gesture exclusion:
- Tilting excludes rotating and scaling.
- Rotating excludes tilting and scaling.
- Scaling excludes tilting.
- Moving excludes tilting.
- Long pressing excludes rotation, scaling, tilting, and double-tapping.
- Double tapping excludes scaling.
You can also lift all restrictions for a specific GestureType
by giving it an empty exclusion set.
map.setExclusiveGestures(gesture: .rotate, blockedGestures: [])