Configure Map Options
The MapTiles API suite has four core components: style, vector tiles, fonts, and sprites.
Style
Vector Tiles
Fonts
Sprites
Basic setup
Fetch the Grab style with an OAuth access token, convert the response to JSON, and pass that object to MapLibre as the map style.
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
// Obtain an access token from your server before loading the map.
const accessToken = '<ACCESS_TOKEN>';
fetch('https://api.maps.grab.com/api/v1/styles/urban-light-partner/descriptor', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
})
.then(response => {
if (!response.ok) {
throw new Error('Request failed with HTTP ' + response.status);
}
return response.json();
})
.then(style => {
const map = new maplibregl.Map({
container: 'map',
style: style,
center: [103.8198, 1.3521],
zoom: 12,
transformRequest: (url) => {
const resourceUrl = new URL(url, window.location.href);
return resourceUrl.origin === 'https://api.maps.grab.com'
? { url, headers: { Authorization: `Bearer ${accessToken}` } }
: { url };
},
});
map.addControl(new maplibregl.NavigationControl(), 'top-right');
});Map options
| Option | Type | Description |
|---|---|---|
container | string | HTMLElement | Required. CSS selector or DOM element for the map container. |
style | object | Parsed style JSON from /api/v1/styles/{Style}/descriptor. |
center | [lng, lat] | Initial map center. |
zoom | number | Initial zoom level. |
pitch | number | Camera pitch in degrees. |
bearing | number | Camera bearing in degrees. |
minZoom / maxZoom | number | Clamp available zoom levels. |
maxBounds | LngLatBoundsLike | Restrict panning to a geographic area. |
Controls and attribution
| Control | Usage |
|---|---|
NavigationControl | Add zoom and compass controls. |
AttributionControl | Display map attribution in a compact or expanded format. |
GeolocateControl | Let users center the map on their current location. |
ScaleControl | Show a distance scale for the current viewport. |
Choose a named map style
Include the style name in /api/v1/styles/{Style}/descriptor. Use urban-light-partner as the default.
const styleName = 'urban-light-partner';
const response = await fetch(
`https://api.maps.grab.com/api/v1/styles/${styleName}/descriptor`,
{
headers: {
Authorization: 'Bearer <ACCESS_TOKEN>'
}
}
);
if (!response.ok) {
throw new Error('Request failed with HTTP ' + response.status);
}
const style = await response.json();
map.setStyle(style);Adding data layers
Add GeoJSON sources and layers inside the map's load event to render places, routes, or other shapes.
map.on('load', () => {
map.addSource('route-line', {
type: 'geojson',
data: routeGeoJson
});
map.addLayer({
id: 'route-line-layer',
type: 'line',
source: 'route-line',
paint: {
'line-color': '#1FBF7F',
'line-width': 6
}
});
});Full configuration example
Copy this to get a map with viewport, controls, attribution, and an empty places layer.
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
async function initMap() {
// Obtain an access token from your server before loading the map.
const accessToken = '<ACCESS_TOKEN>';
const apiOrigin = new URL('https://api.maps.grab.com/api/v1/styles/urban-light-partner/descriptor').origin;
const response = await fetch('https://api.maps.grab.com/api/v1/styles/urban-light-partner/descriptor', {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
if (!response.ok) {
throw new Error('Request failed with HTTP ' + response.status);
}
const style = await response.json();
const map = new maplibregl.Map({
container: 'map',
style,
center: [103.8198, 1.3521],
zoom: 12,
pitch: 0,
bearing: 0,
minZoom: 3,
maxZoom: 20,
attributionControl: false,
interactive: true,
transformRequest: (url) => {
const resourceUrl = new URL(url, window.location.href);
return resourceUrl.origin === apiOrigin
? { url, headers: { Authorization: `Bearer ${accessToken}` } }
: { url };
}
});
map.addControl(new maplibregl.NavigationControl({ visualizePitch: true }), 'top-right');
map.addControl(new maplibregl.AttributionControl({ compact: true }), 'bottom-right');
map.on('load', () => {
map.addSource('selected-places', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: []
}
});
map.addLayer({
id: 'selected-places-point',
type: 'circle',
source: 'selected-places',
paint: {
'circle-radius': 8,
'circle-color': '#1FBF7F',
'circle-stroke-color': '#ffffff',
'circle-stroke-width': 2
}
});
});
return map;
}Configuration endpoints
API endpoints used for MapLibre style configuration.
Get Map Style
/api/v1/styles/{Style}/descriptorReturns a Mapbox Style Specification-compatible JSON document for the selected named style, including its sources, sprites, glyphs, and layers. Use urban-light-partner as the default style.
Request Parameters
| Parameter | Type | Description |
|---|---|---|
Style | string | Required. Specifies the style name. Possible values: |
Request Sample
curl --request GET \
'https://api.maps.grab.com/api/v1/styles/urban-light-partner/descriptor' \
--header 'Authorization: Bearer <ACCESS_TOKEN>'Response Parameters
The response is a Mapbox Style Specification-compatible document. For complete field behavior, see Mapbox Style.
| Field | Type | Description |
|---|---|---|
version | number | The version of the style. |
name | string | The name of the style. |
metadata | object | The metadata of the style. |
sources | object | The sources used by the style. |
sprite | string | The sprite resource URL for the style. |
glyphs | string | The glyph resource URL template for the style. |
layers | array | The layers included in the style. |
Get Sprites
/api/v1/styles/{Style}/sprites/{FileName}Returns the requested sprite sheet image or JSON index for a map style, depending on the FileName parameter.
Request Parameters
| Parameter | Type | Description |
|---|---|---|
Style | string | Required. The name of the style. Possible values: |
FileName | string | Required. The sprite file. Possible values: |
Request Sample
curl --request GET \
'https://api.maps.grab.com/api/v1/styles/{Style}/sprites/{FileName}' \
--header 'Authorization: Bearer <ACCESS_TOKEN>'Response Parameters
This API returns the sprite JSON index or PNG sprite sheet, depending on the FileName parameter. For more details, see Mapbox Sprites.
Get Glyphs
/api/v1/glyphs/{FontStack}/{FontUnicodeRange}Returns font glyphs for a 256-code-point Unicode range in PBF format for rendering map labels.
Request Parameters
| Parameter | Type | Description |
|---|---|---|
FontStack | string | Required. The font family. Possible values: |
FontUnicodeRange | string | Required. A range of 256 Unicode code points. The starting range is 0-255, the ending range is 65280-65535, and the start and end values must always be 256 code points apart. |
Request Sample
curl --request GET \
'https://api.maps.grab.com/api/v1/glyphs/{FontStack}/{FontUnicodeRange}' \
--header 'Authorization: Bearer <ACCESS_TOKEN>'Response Parameters
The response Content-Type is application/x-protobuf. The body contains the requested glyph range encoded with Protocol Buffers.
Get Vector Tiles
/api/v1/tiles/{Tileset}/{Z}/{X}/{Y}Returns MVT-formatted vector map data in PBF format for a tileset and tile coordinate.
Request Parameters
| Parameter | Type | Description |
|---|---|---|
Tileset | string | Required. The source of vector data. Possible values: |
Z | integer | Required. The zoom level. Possible values: 0-14. |
X | integer | Required. The x tile coordinate at the specified zoom level. |
Y | integer | Required. The y tile coordinate at the specified zoom level. |
Request Sample
curl --request GET \
'https://api.maps.grab.com/api/v1/tiles/{Tileset}/{Z}/{X}/{Y}' \
--header 'Authorization: Bearer <ACCESS_TOKEN>'Response Parameters
We use the PBF format based on Vector Tiles. For more details, see Vector Tiles.
Previous endpoint paths
The following paths remain supported for backward compatibility. New integrations should use the simplified /api/v1/... paths shown alongside them.
View previous endpoint paths
| Previous path | Recommended path |
|---|---|
/api/style.json | /api/v1/styles/urban-light-partner/descriptor |
/api/maps/tiles/v2/styles/{style}.json | /api/v1/styles/{Style}/descriptor |
/api/maps/tiles/v2/styles/{style}/{file} | /api/v1/styles/{Style}/sprites/{FileName} |
/api/maps/tiles/v2/fonts/{family}/{range}.pbf | /api/v1/glyphs/{FontStack}/{FontUnicodeRange} |
/api/maps/tiles/v2/vector/{source}/{z}/{x}/{y}.pbf | /api/v1/tiles/{Tileset}/{Z}/{X}/{Y} |
