Advanced GIS

In-class Exercise: JavaScript

Part 1: Look at dropdowns

  1. Open this example and copy the HTML (below the map) into a code editor (such as Brackets) and save it.
  2. Open the file in your browser.
  3. After the line
    var type = $('.type-picker').val();
    add the following line
    console.log(type);
  4. Reload the file in your browser, open developer tools, and pick various options in the dropdown. In the console are you should see the value of the dropdown being written out each time it changes.
  5. We're going to do the same thing with the SQL. Just before the line
    watsanLayer.setSQL(sql);
    Use console.log() to log out the value of the variable sql.

Part 2: Arrays

  1. Open a new tab in your browser and open developer tools.
  2. Copy and paste this code into the console:
    var types = [
        'urban_agriculture',
        'biocentre',
        'toilet_public'
    ];
    and press Enter
  3. In the console, type
    types[0]
    and press Enter.
  4. You should see the first item in types.
  5. Do the same for the second and third items in types.

Part 3: Objects

  1. In the developer tools console, copy and paste this code:
    var coordinates = {
        latitude: 41.56,
        longitude: -73.29
    };
  2. Still in the console, type
    coordinates.latitude
    and press Enter.
  3. In a similar way, get the longitude from coordinates.