Events and gestures

VERSION 0.2.1455
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. By default the map supports:

  • 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 - shoving (moving two fingers up or down on the map in parallel).

Delegates

The Map Display module provides a few map events that can be listened to by implementing the appropriate delegate method.

Conform your class to TomTomMapDelegate, set the map delegate to your class, and add the tomTomMap(_ map: TomTomMap, didTapOn coordinate: CLLocationCoordinate2D) protocol method. Once these steps are done, the tomTomMap(_ map: TomTomMap, 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 tomTomMap(_: TomTomMap, didTapOn _: CLLocationCoordinate2D) {
2 /* YOUR CODE GOES HERE */
3}

In order to listen to other events you have to complete the same steps, and then implement a corresponding method.

1func tomTomMap(_: TomTomMap, didTapOnCurrentLocation _: CLLocationCoordinate2D) {
2 /* YOUR CODE GOES HERE */
3}
4
5func tomTomMap(_: TomTomMap, didDoubleTapOn _: CLLocationCoordinate2D) {
6 /* YOUR CODE GOES HERE */
7}
8
9func tomTomMap(_: TomTomMap, didTwoFingerTapOn _: CLLocationCoordinate2D) {
10 /* YOUR CODE GOES HERE */
11}
12
13func tomTomMap(_: TomTomMap, didLongPressOn _: CLLocationCoordinate2D) {
14 /* YOUR CODE GOES HERE */
15}

The last delegate method that can be implemented is tomTomMap(_ map: TomTomMap, gesture: Gesture, didSendEvent gestureEvent: GestureEvent). It allows listening to the continuous gesture states.

1func tomTomMap(_: TomTomMap, gesture: Gesture, didSendEvent gestureEvent: GestureEvent) {
2 if gesture == .pan, gestureEvent == .begin {
3 /* YOUR CODE GOES HERE */
4 }
5}

Enabling / Disabling gestures

In the Map Display module, you can explicitly disable specific gestures. To do so, set the array of disabled gestures:

tomTomMap.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 https://developer.tomtom.com/assets/downloads/tomtom-sdks/ios/api-reference/0.2.1455/TomTomSDKMapsDisplay/Protocols/MapActions.htmlsetExclusiveGestures(gesture: GestureType, blockedGestures: [GestureType)] method. The gesture parameter is the action whose behaviour is restricted when gestures from the exclusions set are being performed.

For example: You can change the pan gesture exclusions as follows:

tomTomMap.setExclusiveGestures(gesture: .pan, blockedGestures: [.pinch])

Then when you start scaling the map, panning it 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.

tomTomMap.setExclusiveGestures(gesture: .rotate, blockedGestures: [])