The Android Maps SDK allows developers to create maps in their applications using the NextbillionMapOptions configuration. This configuration class defines the default values and states for a MapView, providing various options for customization. With NextbillionMapOptions, developers can easily configure the maps in their applications to meet their specific needs.
Configurations
The Android Maps SDK offers the following available configurations.
Camera
The below code snippet is a part of the Camera class in the Android Maps SDK. It defines several variables used to control the camera view of a map. The cameraPosition variable stores the current camera position of the map, while the minZoom and maxZoom variables set the minimum and maximum zoom level allowed. The minPitch and maxPitch variables set the minimum and maximum pitch angle of the camera. These variables work together to control the camera view of the map and ensure that it stays within the desired range of values. The values are taken from the NbmapConstants class, which provides constants that define the minimum and maximum values for various parameters in the map view.
cameraPosition: The initial coordinate of a MapView will be at (0, 0), we can configure the initial coordinate with this field.
Meanwhile, cameraPosition has defined these configurable values:
1
public final double bearing;
2
3
/**
4
* The location that the camera is pointing at.
5
*/
6
public final LatLng target;
7
8
/**
9
* The angle, in degrees, of the camera angle from the nadir (directly facing the Earth).
10
*/
11
public final double tilt;
12
13
/**
14
* Zoom level near the center of the screen.
15
*/
16
public final double zoom;
17
18
/**
19
* Padding in pixels. Specified in left, top, right, and bottom order.
20
*/
21
public final double[] padding;
22
The other fields are straightforward, and define a range of supported zoom and pitch/tilt of a MapView.
UI control
1
private boolean compassEnabled = true;
2
private boolean fadeCompassFacingNorth = true;
3
private int compassGravity = Gravity.TOP | Gravity.END;
4
private int[] compassMargins;
5
private Drawable compassImage;
6
7
private boolean logoEnabled = true;
8
private int logoGravity = Gravity.BOTTOM | Gravity.START;
9
private int[] logoMargins;
10
@ColorInt
11
private int attributionTintColor = UNDEFINED_COLOR;
12
private boolean attributionEnabled = true;
13
private int attributionGravity = Gravity.BOTTOM | Gravity.START;
14
private int[] attributionMargins;
The configuration defines gravity, margins, and toggle-flag for Compass, Logo, and Attribution.
The "fadeCompassFacingNorth" flag is set to "true", which means the compass icon on the map view will be hidden when the map view is facing north. When this flag is set to "true", the compass will not be visible on the map when it is rotated to face north.
Gestures
The code defines the flags for various gestures that are supported by a map view. Each flag determines whether the corresponding gesture is enabled or not.
For example, "rotateGesturesEnabled" is set to "true", which means that the map view will support the gesture of rotating. Similarly, "scrollGesturesEnabled" is set to "true", which means the map view will support the gesture of scrolling.
The other flags (horizontalScrollGesturesEnabled, tiltGesturesEnabled, zoomGesturesEnabled, doubleTapGesturesEnabled, and quickZoomGesturesEnabled) have the same purpose and determine whether their respective gestures are supported in the map view.
These are flags to turn on and off for supported gestures.
Base URI & Map Tiles
1
The code is for a mapping application and defines several variables for the SDK.
2
private String apiBaseUri;
3
private boolean prefetchesTiles = true;
4
private int prefetchZoomDelta = 4;
5
@ColorInt
6
private int foregroundLoadColor;
The "apiBaseUri" variable specifies the host for the Maps SDK to connect to. The "prefetchesTiles" and "prefetchZoomDelta" variables control the behavior of map tile prefetching. Finally, the "foregroundLoadColor" variable determines the color of the page before the map tile is loaded.
This code snippet declares three variables related to font handling:
localIdeographFontFamilyEnabled: a boolean variable that determines whether the local ideograph font family is enabled. If set to true, it means that the local ideograph font family is enabled.
localIdeographFontFamily: a string variable that stores the name of the local ideograph font family.
localIdeographFontFamilies: an array of strings that holds the names of the local ideograph font families.
How to configure
Configure from XML
If we add a MapView from XML layout, we can configure the maps in this way:
1
<ai.nextbillion.maps.core.MapView
2
android:id="@id/mapView"
3
android:layout_width="match_parent"
4
android:layout_height="match_parent"
5
app:nbmap_baseUri="https://api.nextbillion.io"
6
app:nbmap_cameraTargetLat="12.99150562"
7
app:nbmap_cameraTargetLng="77.61940507"
8
app:nbmap_cameraZoom="10"/>
This code defines an XML layout that adds a MapView component. This component is part of the NextBillion maps library and is used to display a map on the screen. The MapView component is specified with the following attributes:
android: an ID used to uniquely identify the MapView component in the layout.
android and android: the width and height of the MapView component, respectively. They are set to match_parent which means the component will occupy the entire parent layout.
app: the base URL used to access the NextBillion maps API. The value is set to https://api.nextbillion.io.
app and app: the latitude and longitude of the target location to be displayed on the map, respectively. The values are set to 12.99150562 and 77.61940507.
app: the zoom level of the camera. The value is set to 10, which means that the map will be zoomed in to a level where objects on the map will appear 10 times larger than at the default zoom level.
This XML layout is used to configure the display of the map, including the URL of the API, the location to be displayed, and the zoom level.
Available attributes
The Android Maps SDK provides a rich set of attributes that allow developers to customize the appearance and behavior of maps in their applications. These attributes provide fine-grained control over various aspects of maps, such as camera position, zoom level, map style, and markers. With these attributes, developers can create maps that meet the specific needs of their applications and provide a seamless user experience. By using the available attributes, developers can ensure that their maps are visually appealing and provide accurate and up-to-date information.
The Android Maps SDK provides the ability to programmatically integrate maps into an application by using the MapView class. To configure the map display, developers can create an instance of NextbillionMapOptions and pass it when creating a MapView.
One way to create a default NextbillionMapOptions is by calling the static method NextbillionMapOptions.createFromAttributes(Context context). This method creates an instance of NextbillionMapOptions with default settings based on the current context.
Once an instance of NextbillionMapOptions is created, it can be customized by calling the available setters. For example, in the code snippet:
The NextbillionMapOptions instance is created with the default settings and then modified to set the attribution tint color to blue, the API base URI to https://api.nextbillion.io, to prevent the compass from fading when facing north, and to set the camera position to a specific location with a zoom level of 7 and a tilt of 0 degrees.
Finally, the MapView is created by passing the customized NextbillionMapOptions instance.
Available setters
The Android Maps SDK provides a comprehensive set of setters that allow developers to fully customize the appearance and behavior of maps in their applications. These setters offer fine-grained control over various aspects of maps, such as camera position, zoom level, map style, and markers. With these setters, developers can create maps that meet the specific needs of their applications and provide a seamless user experience.
1
//Camera
2
public NextbillionMapOptions camera(CameraPosition cameraPosition)
3
public NextbillionMapOptions minZoomPreference(double minZoom)
4
public NextbillionMapOptions maxZoomPreference(double maxZoom)
5
public NextbillionMapOptions minPitchPreference(double minPitch)
6
public NextbillionMapOptions maxPitchPreference(double maxPitch)
7
8
//UI control
9
public NextbillionMapOptions compassEnabled(boolean enabled)
10
public NextbillionMapOptions compassGravity(int gravity)
11
public NextbillionMapOptions compassMargins(int[] margins)
12
public NextbillionMapOptions compassFadesWhenFacingNorth(boolean compassFadeWhenFacingNorth)
13
public NextbillionMapOptions compassImage(Drawable compass)
14
public NextbillionMapOptions logoEnabled(boolean enabled)
15
public NextbillionMapOptions logoGravity(int gravity)
16
public NextbillionMapOptions logoMargins(int[] margins)
17
public NextbillionMapOptions attributionEnabled(boolean enabled)
18
public NextbillionMapOptions attributionGravity(int gravity)
19
public NextbillionMapOptions attributionMargins(int[] margins)
20
public NextbillionMapOptions attributionTintColor(@ColorInt int color)
21
22
//Gestures
23
public NextbillionMapOptions rotateGesturesEnabled(boolean enabled)
24
public NextbillionMapOptions scrollGesturesEnabled(boolean enabled)
25
public NextbillionMapOptions horizontalScrollGesturesEnabled(boolean enabled)
26
public NextbillionMapOptions tiltGesturesEnabled(boolean enabled)
27
public NextbillionMapOptions zoomGesturesEnabled(boolean enabled)
28
public NextbillionMapOptions doubleTapGesturesEnabled(boolean enabled)
29
public NextbillionMapOptions quickZoomGesturesEnabled(boolean enabled)
30
31
//Base Uri & Map tile
32
public NextbillionMapOptions apiBaseUri(String apiBaseUri)
33
public NextbillionMapOptions foregroundLoadColor(@ColorInt int loadColor)
34
public NextbillionMapOptions setPrefetchesTiles(boolean enable)
35
public NextbillionMapOptions setPrefetchZoomDelta(@IntRange(from = 0) int delta)
36
37
//Glyphs and Font
38
public NextbillionMapOptions localIdeographFontFamilyEnabled(boolean enabled)
39
public NextbillionMapOptions localIdeographFontFamily(String fontFamily)
40
public NextbillionMapOptions localIdeographFontFamily(String... fontFamilies)