Initial commit
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Change source | 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 Leaflet -->
|
||||
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
||||
<link href="https://unpkg.com/leaflet/dist/leaflet.css" rel="stylesheet">
|
||||
<!-- Include CARTO.js -->
|
||||
<script src="../../../dist/public/carto.js"></script>
|
||||
<link href="../style.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<aside class="toolbox">
|
||||
<div class="box">
|
||||
<header>
|
||||
<h1>Change the source</h1>
|
||||
<button class="github-logo js-source-link"></button>
|
||||
</header>
|
||||
<section>
|
||||
<p class="description open-sans">Update the source of your layers.</p>
|
||||
<div class="separator"></div>
|
||||
<section class="usage">
|
||||
<header>USAGE</header>
|
||||
<p class="open-sans">Select different sources</p>
|
||||
</section>
|
||||
|
||||
<div id="controls">
|
||||
<ul>
|
||||
<li onclick="setAllCities()">
|
||||
<input type="radio" name="source" checked id="all">
|
||||
<label for="all">All cities</label>
|
||||
</li>
|
||||
<li onclick="setEuropeanCities()">
|
||||
<input type="radio" name="source" id="europe">
|
||||
<label for="europe">European cities</label>
|
||||
</li>
|
||||
<li onclick="setSpanishCities()">
|
||||
<input type="radio" name="source" id="spain">
|
||||
<label for="spain">Spanish cities</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
<footer class="js-footer"></footer>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<script>
|
||||
const map = L.map('map').setView([30, 0], 3);
|
||||
map.scrollWheelZoom.disable();
|
||||
|
||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_nolabels/{z}/{x}/{y}.png', {
|
||||
maxZoom: 18
|
||||
}).addTo(map);
|
||||
|
||||
const client = new carto.Client({
|
||||
apiKey: 'default_public',
|
||||
username: 'cartojs-test'
|
||||
});
|
||||
|
||||
const source = new carto.source.SQL('SELECT * FROM ne_10m_populated_places_simple');
|
||||
const style = new carto.style.CartoCSS(`
|
||||
#layer {
|
||||
marker-width: 7;
|
||||
marker-fill: #EE4D5A;
|
||||
marker-line-color: #FFFFFF;
|
||||
}
|
||||
`);
|
||||
const layer = new carto.layer.Layer(source, style);
|
||||
|
||||
client.addLayer(layer);
|
||||
client.getLeafletLayer().addTo(map);
|
||||
|
||||
function setAllCities() {
|
||||
source.setQuery('SELECT * FROM ne_10m_populated_places_simple');
|
||||
}
|
||||
|
||||
function setEuropeanCities() {
|
||||
source.setQuery(`
|
||||
SELECT *
|
||||
FROM ne_10m_populated_places_simple
|
||||
WHERE adm0name IN (SELECT admin FROM ne_adm0_europe)
|
||||
`);
|
||||
}
|
||||
|
||||
function setSpanishCities() {
|
||||
source.setQuery(`
|
||||
SELECT *
|
||||
FROM ne_10m_populated_places_simple
|
||||
WHERE adm0name = \'Spain\'
|
||||
`);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user