In-class Excercises: Templates, Turf
Part 1: Using Mustache
- Start with this example jsbin.
- Change the
context
object to change the name and job.
Part 2: Mustache templates in HTML
- Use this jsbin as an example. Look at how it stores the template in HTML.
- Using the code from Part 1, move the template from JavaScript to HTML:
- Add a
script
element in your HTML. - Move the template from the JavaScript into the new
script
element. - Get the template from the HTML in your JavaScript by calling
$('#template').html()
. The selector will be different depending on yourscript
element's id.
- Add a
Part 3: Mustache template loops
- Start with this example jsbin.
- Change the SQL to select rows from one of your tables.
- Change the template to show data from the rows in your tables.
Part 4: Mustache templates in Leaflet popups
- Start with this example jsbin.
- We want each popup to include a link to the Airbnb listing. These URLs look like this:
for example: https://www.airbnb.com/rooms/10790927. The id is thehttps://www.airbnb.com/rooms/id
id
field in the data from CartoDB. - Change the popups' templates to include a link to the Airbnb listing associated with the point on the map.
Part 5: Turf, buffer
Starting with this jsbin, add a buffer to each feature in a GeoJSON file loaded from GitHub.
This jsbin contains a working example if you get stuck.
Part 6: Turf, convex hull
Use Turf to add the convex hull of a polygon to a map, starting with this jsbin.
This jsbin contains a working example if you get stuck.