-
Notifications
You must be signed in to change notification settings - Fork 3
/
Javascript Syntax and Loading a Landsat Image Collection
64 lines (41 loc) · 1.98 KB
/
Javascript Syntax and Loading a Landsat Image Collection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// This is a quick and totally insufficient introduction to Javascript syntax
// Line comments start with two forward slashes. Like this line. I try to
// only use these for actuall in-line comments on the code
/*
Multi line comments start with a forward slash and an asterisk,
and end with an asterisk and a forward slash. For the most part, you will be
running the sample script, as is, then uncommenting block
commented code to see what it does
*/
// Variables are used to store objects, and are defined using the keyword var.
var the_answer = 42;
// String objects start and end with a single quote.
var my_variable = 'I am a string';
// String objects can also start and end with double quotes.
// But don't mix and match them.
var my_other_variable = "I am also a string";
// Statements should end in a semi-colon, or the editor complains.
var test = 'I feel incomplete...'
// Parentheses are used to pass parameters to functions.
print(test);
// Square brackets are used for selecting items within a list.
// The zero index refers to the first item in the list.
var my_list = ['eggplant', 'apple', 'wheat'];
print(my_list[0]);
// Curly brackets (or braces) can be used to define dictionaries (key:value pairs)
var my_dict = {'food': 'bread', 'color': 'red', 'number': the_answer};
// Square brackets can be used to access dictionary items by key.
print(my_dict['color']);
// Or you can use the dot notation to get the same result.
print(my_dict.color);
// Functions can be defined as a way to reuse code and make it easier to read
var my_hello_function = function(string) {
return 'Hello ' + string + '!';
};
print(my_hello_function('world'));
////////////////DISPLAYING AND FILTERING AN IMAGE COLLECTION////////////////
///////////////////////////LANDSAT 8////////////////////////////////////////
// Filter the image collection to a date range.
var filtered = l8.filterDate('2017-07-01', '2017-07-31');
// Add to the map as a most-recent pixel mosaic.
Map.addLayer(filtered, {}, 'filtered');