Events and gestures

VERSION 0.2.2746
PUBLIC PREVIEW

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.
  • 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 that can be listened to by implementing the appropriate delegate method.

To implement a delegate method:

First, conform your class to MapDelegate.

Then set the map delegate to your class.

Next, add the map(_ map: Map, didTapOn coordinate: CLLocationCoordinate2D) protocol method. After these steps are complete, the map(_ map: Map, didTapOn coordinate: CLLocationCoordinate2D) method is triggered whenever the user taps on the map . The method supplies the coordinates for the point where the map was clicked and for the map object itself.

1func map(_: Map, didTapOn _: CLLocationCoordinate2D) {
2 /* YOUR CODE GOES HERE */
3}

To listen to other events you must complete the same steps, and then implement a corresponding method.

1func map(_: Map, didTapOnCurrentLocation _: CLLocationCoordinate2D) {
2 /* YOUR CODE GOES HERE */
3}
4
5func map(_: Map, didDoubleTapOn _: CLLocationCoordinate2D) {
6 /* YOUR CODE GOES HERE */
7}
8
9func map(_: Map, didLongPressOn _: CLLocationCoordinate2D) {
10 /* YOUR CODE GOES HERE */
11}

The last delegate method that can be implemented is map(_ map: Map, onInteraction interaction: MapInteraction). It is used to listen to all map interactions.

1func map(_ map: Map, onInteraction interaction: MapInteraction) {
2 switch interaction {
3 case let .panned(state):
4 if state == .begin {
5 /* YOUR CODE GOES HERE */
6 }
7 default:
8 break
9 }
10}

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: [])