Ask or search…
K
Links
Comment on page

Tileset

This example shows how to visualize a tileset from the CARTO platform with Mapbox GL JS.
CARTO 3
CARTO 2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CARTO + Mapbox GL JS - Tileset</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiY2FydG9kYmluYyIsImEiOiJja202bHN2OXMwcGYzMnFrbmNkMzVwMG5rIn0.Zb3J4JTdJS-oYNXlR3nvnQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
center: [-73.8, 40.73],
zoom: 9
});
map.on('load', async () => {
const tileset = 'cartobq.public_account.nyc_taxi_points_demo_id';
const accessTokenCarto = 'eyJhbGciOiJIUzI1NiJ9.eyJhIjoiYWNfbHFlM3p3Z3UiLCJqdGkiOiI1YjI0OWE2ZCJ9.Y7zB30NJFzq5fPv8W5nkoH5lPXFWQP0uywDtqUg8y8c';
const apiBaseUrl = 'https://gcp-us-east1.api.carto.com';
const connectionName = 'bqconn';
const tilejsonUrl = `${apiBaseUrl}/v3/maps/${connectionName}/tileset?format=tilejson&name=${tileset}&access_token=${accessTokenCarto}`;
map.addLayer({
'id': 'taxi-data',
'type': 'circle',
'source': {
'type': 'vector',
url: tilejsonUrl
},
'source-layer': 'default',
'paint': {
'circle-radius': 2,
'circle-color': [
'step',
['get', 'aggregated_total'],
'#009392',
10,
'#39b185',
1e2,
'#9ccb86',
1e3,
'#e9e29c',
1e4,
'#eeb479',
1e5,
'#e88471',
1e6,
'#cf597e'
]
}
});
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CARTO + Mapbox GL JS - Tileset</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiY2FydG9kYmluYyIsImEiOiJja202bHN2OXMwcGYzMnFrbmNkMzVwMG5rIn0.Zb3J4JTdJS-oYNXlR3nvnQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
center: [-73.8, 40.73],
zoom: 9
});
map.on('load', async () => {
const tileset = 'cartobq.public_account.nyc_taxi_points_demo_id';
const tilejsonUrl = `https://maps-api-v2.us.carto.com/user/public/bigquery/tileset?source=${tileset}&format=tilejson&api_key=default_public&rand=3435334`;
map.addLayer({
'id': 'taxi-data',
'type': 'circle',
'source': {
'type': 'vector',
url: tilejsonUrl
},
'source-layer': 'default',
'paint': {
'circle-radius': 2,
'circle-color': [
'step',
['get', 'aggregated_total'],
'#009392',
10,
'#39b185',
1e2,
'#9ccb86',
1e3,
'#e9e29c',
1e4,
'#eeb479',
1e5,
'#e88471',
1e6,
'#cf597e'
]
}
});
});
</script>
</body>
</html>
Last modified 10mo ago