Welcome to Advanced GIS, Lecture 9
This is a web page that can be viewed as slides.
→ to move forward
← to go back
Class 9
<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'");
});
SELECT *
FROM watsan
WHERE watsan = 'urban_agriculture'
SELECT *
FROM watsan
WHERE watsan = 'toilet_public'
<select class="type-picker">
<option value="all">All types</option>
<option value="bathroom">bathroom</option>
<option value="biocentre">biocentre</option>
<option value="dumping_site">dumping site</option>
</select>
$('.type-picker').change(function () {
...
});
SELECT *
FROM watsan
WHERE watsan = 'urban_agriculture'
SELECT *
FROM watsan
WHERE watsan = 'toilet_public'
$('.type-picker').val()
var type = $('.type-picker').val();
var sql = "SELECT * FROM watsan WHERE watsan = " + type;
var type = $('.type-picker').val();
var sql = "SELECT * FROM watsan WHERE watsan = '" + type + "'";
var types = [
'urban_agriculture',
'biocentre',
'toilet_public'
];
var ratings = [
5,
3,
4.5
];
var types = [
'urban_agriculture',
'biocentre',
'toilet_public'
];
var types = [
'urban_agriculture',
'biocentre',
'toilet_public'
];
types[0]
is 'urban_agriculture'
var types = [
'urban_agriculture',
'biocentre',
'toilet_public'
];
types[1]
is 'biocentre'
var coordinates = {
latitude: 41.56,
longitude: -73.29
};
var coordinates = {
latitude: 41.56,
longitude: -73.29
};
coordinates.latitude
is 41.56
var coordinates = {
"latitude": 41.56,
"longitude": -73.29
};
var data = {
"rows": [
{"count":208}
],
"time":0.006,
"fields": {
"count": {"type":"number"}
},
"total_rows":1
};
var data = {
"rows": [
{"count":208}
],
"time":0.006,
"fields": {
"count": {"type":"number"}
},
"total_rows":1
};
data.rows
is [
{"count":208}
]
var data = {
"rows": [
{"count":208}
],
"time":0.006,
"fields": {
"count": {"type":"number"}
},
"total_rows":1
};
data.rows[0]
is {"count":208}
var data = {
"rows": [
{"count":208}
],
"time":0.006,
"fields": {
"count": {"type":"number"}
},
"total_rows":1
};
data.rows[0].count
is 208
var data = {
"rows": [
{"count":208}
],
"time":0.006,
"fields": {
"count": {"type":"number"}
},
"total_rows":1
};
+ tons of other sites with maps on them
1. load leaflet's code
2. make a div
for your map
3. tell leaflet to create the map
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
div
for your map<body>
<div id="map"></div>
</body>
var map = L.map('map').setView([40.70, -73.96], 11);
L.tileLayer('https://{s}.tiles.mapbox.com/v3/ebrelsford.ho06j5h0/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox'
}).addTo(map);