Welcome to Advanced GIS, Lecture 7
This is a web page that can be viewed as slides.
→ to move forward
← to go back
Class 7
<iframe width="100%" height="520" frameborder="0"
src="https://thenewschool.carto.com/u/brelsfoeagain/
builder/fd0fea4a-ee46-11e6-8c31-0ecd1babdde5/embed"
allowfullscreen webkitallowfullscreen mozallowfullscreen
oallowfullscreen msallowfullscreen></iframe>
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<body>
<div id="map"></div>
</body>
<script>
$(document).ready(function () {
cartodb.createVis('map', 'https://thenewschool.carto.com/u/brelsfoeagain/api/v2/viz/0f95ca3a-02d9-11e7-b9b0-0ecd1babdde5/viz.json');
});
</script>
$(document).ready(function () {
// Do something
});
$(document).ready(function () {
// Do something
});
cartodb.createVis('map', 'https://thenewschool.carto.com/u/brelsfoeagain/api/v2/viz/0f95ca3a-02d9-11e7-b9b0-0ecd1babdde5/viz.json');
cartodb.createVis('map', 'https://thenewschool.carto.com/u/brelsfoeagain/api/v2/viz/0f95ca3a-02d9-11e7-b9b0-0ecd1babdde5/viz.json');
createVis
function for mealert('hiiiii');
console.log('shhhh');
'maps'.toUpperCase();
<script>
$(document).ready(function () {
cartodb.createVis(your_map_id,
your_visualization_url,
your_options);
});
</script>
<script>
$(document).ready(function () {
cartodb.createVis(your_map_id,
your_visualization_url,
your_options);
});
</script>
<script>
$(document).ready(function () {
cartodb.createVis('map', 'https://thenewschool.carto.com/u/brelsfoeagain/api/v2/viz/0f95ca3a-02d9-11e7-b9b0-0ecd1babdde5/viz.json');
});
</script>
<script>
$(document).ready(function () {
cartodb.createVis('map', your_visualization_url);
});
</script>
<script>
$(document).ready(function () {
cartodb.createVis('map', your_visualization_url);
});
</script>
your_visualization_url
?https://thenewschool.carto.com/u/{username}/api/v2/viz/{mapid}/viz.json
https://thenewschool.carto.com/u/{username}/api/v2/viz/{mapid}/viz.json
{username}
and {mapid}
{mapid}
?/builder/
in the url when you're editing the map79edb122-0374-11e7-b189-0e233c30368f
<script>
$(document).ready(function () {
cartodb.createVis('map', your_visualization_url, {
cartodb_logo: false
});
});
</script>
<script>
$(document).ready(function () {
cartodb.createVis('map', your_visualization_url, {
cartodb_logo: false
});
});
</script>
remove the logo from your map
<script>
$(document).ready(function () {
cartodb.createVis('map', your_visualization_url, {
cartodb_logo: false
});
});
</script>
{
cartodb_logo: false
}
{
cartodb_logo: false,
zoom: 5
}
makes it easier to do some common things in JavaScript
$
is talking to jQuery$('#map')
$('#map').hide()
$('#map').animate({ opacity: 0 })
$('#map').animate({ width: 0 })
$('.public-water').click(function () {
console.log("click");
});
div
with class
"public-water"$('.public-water').click(function () {
console.log("click");
});
$('.public-water').click(function () {
console.log("click");
});
$('.public-water').click(function () {
console.log("click");
});
<button class="public-water">public water</button>
cartodb.createVis(...)
.done(function (vis, layers) {
watsanLayer = layers[1].getSubLayer(0);
});
$('.public-water').click(function () {
...
});
$('.public-water').click(function () {
watsanLayer.setSQL("SELECT * FROM watsan WHERE watsan = 'water_public'");
});
var sql = 'SELECT * FROM watsan';
var size = 5;
var size = 5 * 1000;
var sql = 'SELECT * FROM watsan';
var type = 'urban_agriculture';
var sql = "SELECT * FROM watsan WHERE watsan = '" + type + "'";
copy jsbin.com/hasumo/edit into Brackets and select a different watsan
<select class="type-picker">
<option value="all">All types</option>
<option value="bathroom">bathroom</option>
<option value="other">other</option>
</select>
$('.type-picker').change(function () {
});
$('.type-picker').change(function () {
var type = $(this).val();
var sql;
if (type === 'all') {
sql = "SELECT * FROM watsan";
}
else {
sql = "SELECT * FROM watsan WHERE watsan = '" + type + "'";
}
dataLayer.setSQL(sql);
});
$('.type-picker').change(function () {
var type = $(this).val();
});
$('.type-picker').change(function () {
var type = $(this).val();
});
$('.type-picker').change(function () {
var type = $(this).val();
var sql;
if (type === 'all') {
sql = "SELECT * FROM watsan";
}
});
$('.type-picker').change(function () {
var type = $(this).val();
var sql;
if (type === 'all') {
sql = "SELECT * FROM watsan";
}
});
$('.type-picker').change(function () {
var type = $(this).val();
var sql;
if (type === 'all') {
sql = "SELECT * FROM watsan";
}
else {
sql = "SELECT * FROM watsan WHERE watsan = '" + type + "'";
}
dataLayer.setSQL(sql);
});