86 lines
2.6 KiB
HTML
86 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Multilayer | CARTO</title>
|
|
<meta name="viewport" content="initial-scale=1.0">
|
|
<meta charset="utf-8">
|
|
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,600,700|Open+Sans:300,400,600" rel="stylesheet">
|
|
<!-- Include Google Maps -->
|
|
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDpVNTQI60ossApFzZ3dwSMZ1LcxOTY-rI&v=3.35"></script>
|
|
<!-- Include CARTO.js -->
|
|
<script src="../../../dist/public/carto.js"></script>
|
|
<link href="../style.css" rel="stylesheet">
|
|
</head>
|
|
|
|
<body>
|
|
<div id="map"></div>
|
|
<!-- Description -->
|
|
<aside class="toolbox">
|
|
<div class="box">
|
|
<header>
|
|
<h1>Add more layers</h1>
|
|
<button class="github-logo js-source-link"></button>
|
|
</header>
|
|
<section>
|
|
<p class="description open-sans">Add multiple CARTO layers to your map.</p>
|
|
</section>
|
|
<footer class="js-footer"></footer>
|
|
</div>
|
|
</aside>
|
|
|
|
<script>
|
|
var map = new google.maps.Map(document.getElementById('map'), {
|
|
center: { lat: 40, lng: 0 },
|
|
zoom: 5,
|
|
fullscreenControl: false,
|
|
gestureHandling: 'cooperative'
|
|
});
|
|
|
|
// Hide the map labels and geometry strokes
|
|
map.set('styles', [{
|
|
elementType: 'labels',
|
|
stylers: [{ visibility: 'off' }]
|
|
}, {
|
|
elementType: 'geometry.stroke',
|
|
stylers: [{ visibility: 'off' }]
|
|
}]);
|
|
|
|
const client = new carto.Client({
|
|
apiKey: 'default_public',
|
|
username: 'cartojs-test'
|
|
});
|
|
|
|
const spainCitiesSource = new carto.source.SQL(`
|
|
SELECT *
|
|
FROM ne_10m_populated_places_simple
|
|
WHERE adm0name = \'Spain\'
|
|
`);
|
|
const spainCitiesStyle = new carto.style.CartoCSS(`
|
|
#layer {
|
|
marker-width: 7;
|
|
marker-fill: #EE4D5A;
|
|
marker-line-color: #FFFFFF;
|
|
}
|
|
`);
|
|
const spainCitiesLayer = new carto.layer.Layer(spainCitiesSource, spainCitiesStyle);
|
|
|
|
const europeCountriesSource = new carto.source.Dataset('ne_adm0_europe');
|
|
const europeCountriesStyle = new carto.style.CartoCSS(`
|
|
#layer {
|
|
polygon-fill: #826DBA;
|
|
polygon-opacity: 0.8;
|
|
::outline {
|
|
line-width: 1;
|
|
line-color: #FFFFFF;
|
|
line-opacity: 0.8;
|
|
}
|
|
}
|
|
`);
|
|
const europeCountriesLayer = new carto.layer.Layer(europeCountriesSource, europeCountriesStyle);
|
|
|
|
client.addLayers([europeCountriesLayer, spainCitiesLayer]);
|
|
map.overlayMapTypes.push(client.getGoogleMapsMapType(map));
|
|
</script>
|
|
</body>
|
|
</html>
|