Skip to content

Instantly share code, notes, and snippets.

@IagoLast
Created April 12, 2018 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IagoLast/e4a469f95e99bad5e179e6e9d0cf8518 to your computer and use it in GitHub Desktop.
Save IagoLast/e4a469f95e99bad5e179e6e9d0cf8518 to your computer and use it in GitHub Desktop.
CARTO VL Example
<!DOCTYPE html>
<html>
<head>
<title>Multi layer | CARTO</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<!-- Include CARTO VL JS -->
<script src="https://unpkg.com/@carto/carto-vl"></script>
<!-- Include Mapbox GL JS -->
<script src="https://unpkg.com/@carto/mapbox-gl"></script>
<!-- Include Mapbox GL CSS -->
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.css" rel="stylesheet" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
const map = new mapboxgl.Map({
container: 'map',
style: 'https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json',
center: [0, 40],
zoom: 4,
dragRotate: false
});
carto.setDefaultAuth({
user: 'cartogl',
apiKey: 'YOUR_API_KEY'
});
const spainCitiesSource = new carto.source.SQL(`
SELECT *
FROM ne_10m_populated_places_simple
WHERE adm0name = \'Spain\'
`);
const spainCitiesStyle = new carto.Style(`
width: 6
color: rgb(237, 76, 89)
strokeWidth: 1
strokeColor: rgb(255, 255, 255)
`);
const spainCitiesLayer = new carto.Layer('spainCitiesLayer', spainCitiesSource, spainCitiesStyle);
const europeCountriesSource = new carto.source.Dataset(`
ne_adm0_europe
`);
const europeCountriesStyle = new carto.Style(`
color: rgba(127, 110, 186, 0.8)
`);
const europeCountriesLayer = new carto.Layer('europeCountriesLayer', europeCountriesSource, europeCountriesStyle);
spainCitiesLayer.addTo(map, 'watername_ocean');
europeCountriesLayer.addTo(map, 'spainCitiesLayer');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment