UI Settings and Gestures

The Android Maps SDK provides a comprehensive set of tools for customizing the look and feel of your map, as well as the interactions your users can have with it. With the SDK's UI settings, you can easily customize the visual aspects of your map, such as the color scheme, the visibility of certain UI elements, and more. Additionally, the SDK provides a range of gesture options, allowing you to specify the types of interactions your users can have with the map, such as panning, zooming, and more. With these tools, you can create a truly unique and interactive map experience for your users.

UI settings

UiSettings is an interface to manage views(Compass, Logo, and Attribution), gesture flags, and gesture animations. UiSettings allows developers to

  1. modify the visibility, gravity, and margins to

    • Compass view
    • Logo
    • Attribution view
  2. Enable or disable gestures

    • Rotate
    • Tilt
    • Zoom
    • Scroll
    • Horizontal scroll
    • Double tap
    • Quick zoom
  3. Enable or disable gesture animations

    • Scale velocity animation
    • Rotate velocity animation
    • Fling velocity animation

UI control

The Android Maps SDK offers a comprehensive set of tools for controlling the user interface (UI) of your map, allowing you to customize its appearance and user interactions. With the SDK's UI settings, you have the flexibility to tailor the visual aspects of your map to your specific requirements. You can modify the color scheme, visibility of UI elements and more. One of the key components for managing the UI is the UiSettings interface. It provides developers with the ability to handle various views, gesture flags, and gesture animations associated with the map. With UiSettings, you can:

Manage the visibility, gravity, and margins of the following views:

  • Compass view: Control the display of a compass indicating the map's orientation.
  • Logo: Choose whether to show the logo of the mapping service on the map.
  • Attribution view: Determine the visibility of attribution information on the map.

Enable or disable specific gestures, including:

  • Rotate: Allow users to rotate the map.
  • Tilt: Enable tilting the map for a different perspective.
  • Zoom: Allow users to zoom in and out.
  • Scroll: Enable panning or dragging the map.
  • Horizontal scroll: Enable horizontal panning of the map.
  • Double tap: Allow users to double-tap to zoom in and out quickly.
  • Quick zoom: Enable quick zooming with a two-finger double-tap gesture.

Enable or disable gesture animations, including:

  • Scale velocity animation: Control the animation when scaling the map.
  • Rotate velocity animation: Specify animation behavior when rotating the map.
  • Fling velocity animation: Control the animation when flinging the map.

By leveraging these UI control features, you can create a truly unique and interactive map experience for your users. Take advantage of the Android Maps SDK to customize your map's appearance and define the user interactions that best suit your application's needs.

Gestures

The NextbillionMap supports gestures below:

  1. Rotation gesture

    • Hold two fingers down on the screen and rotate to adjust the bearing
  2. Zoom gesture

    • Hold two fingers and pinch to adjust the zoom level.
  3. Tilt Gesture/Pitch

    • Hold two fingers and move vertically to adjust the tilt/pitch
  4. Scroll gesture

  5. Double tap gesture

    • Double tap with one finger to zoom in, double tap with two fingers to zoom out.
  6. Quick zoom gesture

    • Double tap and drag up to zoom out, and drag down to zoom in.

Enable and disable gestures

1
UiSettings uiSettings = nextbillionMap.getUiSettings();
2
3
//Rotation
4
uiSettings.setRotateGesturesEnabled(enable);
5
6
//Tilt
7
uiSettings.setTiltGesturesEnabled(enable);
8
9
//Zoom
10
uiSettings.setZoomGesturesEnabled(enable);
11
12
//Scroll
13
uiSettings.setScrollGesturesEnabled(enable);
14
15
//Double tap
16
uiSettings.setDoubleTapGesturesEnabled(enable);
17
18
//Quick Zoom
19
uiSettings.setQuickZoomGesturesEnabled(enable);
20
21
//Horizontal Scroll
22
uiSettings.setHorizontalScrollGesturesEnabled(enable);
23
24
//All gestures
25
uiSettings.setAllGesturesEnabled(enable);

The above code is a sample code demonstrating how to enable or disable gestures in the Nextbillion Android Maps SDK. By using the getUiSettings method, you can access the UiSettings interface and control different gestures like rotation, tilt, zoom, scroll, double tap, quick zoom, and horizontal scroll. Additionally, you can also enable or disable all gestures at once by using the setAllGesturesEnabled method with a boolean value as its argument.

Register listener to gesture events

The gesture flags in UiSettings only allow developers to switch a specific gesture on and off, to listen to any of those gestures, we need to register the listener to NextbillionMap

1
public void registerListeners() {
2
nextbillionMap.addOnMoveListener(new NextbillionMap.OnMoveListener() {
3
@Override
4
public void onMoveBegin(@NonNull MoveGestureDetector detector) {
5
}
6
7
@Override
8
public void onMove(@NonNull MoveGestureDetector detector) {
9
}
10
11
@Override
12
public void onMoveEnd(@NonNull MoveGestureDetector detector) {
13
}
14
});
15
16
nextbillionMap.addOnScaleListener(new NextbillionMap.OnScaleListener() {
17
@Override
18
public void onScaleBegin(@NonNull StandardScaleGestureDetector detector) {
19
}
20
21
@Override
22
public void onScale(@NonNull StandardScaleGestureDetector detector) {
23
}
24
25
@Override
26
public void onScaleEnd(@NonNull StandardScaleGestureDetector detector) {
27
}
28
});
29
30
nextbillionMap.addOnRotateListener(new NextbillionMap.OnRotateListener() {
31
@Override
32
public void onRotateBegin(@NonNull RotateGestureDetector detector) {
33
}
34
35
@Override
36
public void onRotate(@NonNull RotateGestureDetector detector) {
37
}
38
39
@Override
40
public void onRotateEnd(@NonNull RotateGestureDetector detector) {
41
}
42
});
43
44
nextbillionMap.addOnShoveListener(new NextbillionMap.OnShoveListener() {
45
@Override
46
public void onShoveBegin(@NonNull ShoveGestureDetector detector) {
47
}
48
49
@Override
50
public void onShove(@NonNull ShoveGestureDetector detector) {
51
}
52
53
@Override
54
public void onShoveEnd(@NonNull ShoveGestureDetector detector) {
55
}
56
});
57
}

This code shows how to register listeners for various gesture types (move, scale, rotate, and shove) on a NextbillionMap. The addOnMoveListener, addOnScaleListener, addOnRotateListener, and addOnShoveListener methods are used to attach a new listener to the map. The listener implements three callback methods for each type of gesture: on[GestureType]Begin, on[GestureType], and on[GestureType]End. These methods are called when the gesture begins, is ongoing, and ends, respectively. By registering these listeners, developers can receive real-time updates about the user's interaction with the map and perform custom actions based on the gestures performed.

© 2024 NextBillion.ai all rights reserved.