Events and gestures

VERSION 0.51.1

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.

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 break
6 case let .tappedOnAnnotation(annotation, coordinate):
7 /* YOUR CODE GOES HERE */
8 break
9 case let .tappedOnLocationMarker(coordinate):
10 /* YOUR CODE GOES HERE */
11 break
12 case .tappedOnRecenterButton:
13 /* YOUR CODE GOES HERE */
14 break
15 case let .doubleTapped(coordinate):
16 /* YOUR CODE GOES HERE */
17 break
18 case let .tappedWithTwoFingers(coordinate):
19 /* YOUR CODE GOES HERE */
20 break
21 case let .longPressed(coordinate):
22 /* YOUR CODE GOES HERE */
23 break
24 case let .panned(state):
25 /* YOUR CODE GOES HERE */
26 break
27 case let .pinched(state):
28 /* YOUR CODE GOES HERE */
29 break
30 case let .rotated(state):
31 /* YOUR CODE GOES HERE */
32 break
33 case let .tilted(state):
34 /* YOUR CODE GOES HERE */
35 break
36 default:
37 break
38 }
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: [])