@google/earthengine 1.7.3 → 1.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google/earthengine",
3
- "version": "1.7.3",
3
+ "version": "1.7.9",
4
4
  "description": "JavaScript client for Google Earth Engine API.",
5
5
  "author": "Google LLC",
6
6
  "license": "Apache-2.0",
package/src/apiclient.js CHANGED
@@ -24,7 +24,7 @@ const {trustedResourceUrl} = goog.require('safevalues.index');
24
24
  /** @namespace */
25
25
  const apiclient = {};
26
26
 
27
- const API_CLIENT_VERSION = '1.7.3';
27
+ const API_CLIENT_VERSION = '1.7.9';
28
28
 
29
29
  exports.VERSION = apiVersion.VERSION;
30
30
  exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
@@ -706,9 +706,9 @@ apiclient.getUserAgent = function() {
706
706
  /**
707
707
  * Initializes the data module, setting base URLs.
708
708
  *
709
- * @param {?string=} apiBaseUrl The (proxied) EarthEngine REST API
709
+ * @param {?string=} apiBaseUrl The (proxied) Earth Engine REST API
710
710
  * endpoint.
711
- * @param {?string=} tileBaseUrl The (unproxied) EarthEngine REST tile
711
+ * @param {?string=} tileBaseUrl The (unproxied) Earth Engine REST tile
712
712
  * endpoint.
713
713
  * @param {?string=} xsrfToken A string to pass in the X-XSRF-Token header
714
714
  * of XHRs.
package/src/ee.js CHANGED
@@ -459,6 +459,13 @@ ee.promote_ = function(arg, klass) {
459
459
  default:
460
460
  // Handle dynamically generated classes.
461
461
  if (klass in exportedEE) {
462
+ if (!(exportedEE[klass].prototype instanceof ee.ComputedObject)) {
463
+ // Block things that should not be replaced.
464
+ throw new Error(
465
+ 'Algorithm not an instance of ee.ComputedObject: ' + klass +
466
+ ': ' + arg);
467
+ }
468
+
462
469
  const ctor = ee.ApiFunction.lookupInternal(klass);
463
470
  if (arg instanceof exportedEE[klass]) {
464
471
  // Return unchanged.
@@ -150,7 +150,10 @@ const simpleCorsAllowedContentTypes: readonly string[] = [
150
150
  * by the browser.
151
151
  */
152
152
  // TODO(user): Return a changed copy of params.
153
- export function bypassCorsPreflight(params: MakeRequestParams): void {
153
+ export function bypassCorsPreflight(
154
+ params: MakeRequestParams,
155
+ singleEncode = false,
156
+ ): void {
154
157
  const safeHeaders: {[key: string]: string} = {};
155
158
  const unsafeHeaders: {[key: string]: string} = {};
156
159
  let hasUnsafeHeaders = false;
@@ -196,8 +199,10 @@ export function bypassCorsPreflight(params: MakeRequestParams): void {
196
199
  }
197
200
 
198
201
  if (hasUnsafeHeaders) {
199
- const finalParam =
200
- httpCors.generateEncodedHttpHeadersOverwriteParam(unsafeHeaders);
202
+ const generator = singleEncode
203
+ ? httpCors.generateHttpHeadersOverwriteParam
204
+ : httpCors.generateEncodedHttpHeadersOverwriteParam;
205
+ const finalParam = generator(unsafeHeaders);
201
206
  addQueryParameter(params, httpCors.HTTP_HEADERS_PARAM_NAME, finalParam);
202
207
  }
203
208
  params.headers = safeHeaders;
@@ -253,4 +253,25 @@ describe('bypassCorsPreflight', () => {
253
253
  '$httpMethod': 'PUT',
254
254
  });
255
255
  });
256
+
257
+ it('handles singleEncode=true', () => {
258
+ const params: MakeRequestParams = {
259
+ path: 'v1/whatever',
260
+ httpMethod: 'PUT',
261
+ methodId: 'someservice.whatever.put',
262
+ headers: {'accept-language': 'de', 'foo': 'bar'},
263
+ queryParams: {'hello': 'world'},
264
+ };
265
+ bypassCorsPreflight(params, /** singleEncode= */ true);
266
+ expect(params.headers).toEqual({
267
+ 'accept-language': 'de',
268
+ 'Content-Type': 'text/plain',
269
+ });
270
+ expect(params.httpMethod).toEqual('POST');
271
+ expect(params.queryParams).toEqual({
272
+ 'hello': 'world',
273
+ '$httpHeaders': 'foo:bar\r\nContent-Type:application/json\r\n',
274
+ '$httpMethod': 'PUT',
275
+ });
276
+ });
256
277
  });
@@ -13,51 +13,81 @@ var collection = ee.ImageCollection('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS')
13
13
  var fit = collection.reduce(ee.Reducer.linearFit());
14
14
 
15
15
  // Display trend in red/blue, brightness in green.
16
- var visParams = {min: 0, max: [0.18, 20, -0.18], bands: ['scale', 'offset', 'scale']};
16
+ var visParams = {
17
+ min: 0,
18
+ max: [0.18, 20, -0.18],
19
+ bands: ['scale', 'offset', 'scale']
20
+ };
17
21
  Map.addLayer(fit, visParams);
18
22
 
19
23
  Map.style().set('cursor', 'crosshair');
24
+ Map.setCenter(-95, 38, 4);
20
25
 
21
26
  // Create a map to be used as the zoom box.
22
- var zoomBox = ui.Map({style: {stretch: 'both', shown: false}})
23
- .setControlVisibility(false);
27
+ var zoomBox = ui.Map({style: {stretch: 'both'}});
28
+ zoomBox.setControlVisibility(false);
24
29
  zoomBox.addLayer(fit, visParams);
30
+ zoomBox.setCenter(-115.13, 36.18, 8);
25
31
 
26
- // Update the center of the zoom box map when the base map is clicked.
27
- Map.onClick(function(coords) {
28
- centerZoomBox(coords.lon, coords.lat);
32
+ // Instruction label.
33
+ var instructionLabel = ui.Label('Click the main map to move this view', {
34
+ position: 'top-center',
35
+ padding: '8px',
36
+ color: 'black',
37
+ backgroundColor: 'rgba(255, 255, 255, 0.8)',
38
+ fontWeight: 'bold',
39
+ fontSize: '12px'
29
40
  });
41
+ zoomBox.add(instructionLabel);
42
+
43
+ // Bounds logic.
44
+ var isMapReady = false;
45
+ var isFirstClick = true;
30
46
 
31
- var centerZoomBox = function(lon, lat) {
32
- instructions.style().set('shown', false);
33
- zoomBox.style().set('shown', true);
34
- zoomBox.setCenter(lon, lat, 8);
47
+ var updateOutline = function() {
35
48
  var bounds = zoomBox.getBounds();
36
- var w = bounds[0], e = bounds [2];
37
- var n = bounds[1], s = bounds [3];
38
- var outline = ee.Geometry.MultiLineString([
39
- [[w, s], [w, n]],
40
- [[e, s], [e, n]],
41
- [[w, s], [e, s]],
42
- [[w, n], [e, n]],
43
- ]);
44
- var layer = ui.Map.Layer(outline, {color: 'FFFFFF'}, 'Zoom Box Bounds');
45
- Map.layers().set(1, layer);
49
+ if (!bounds || !Array.isArray(bounds)) return;
50
+
51
+ try {
52
+ var outline = ee.Geometry.Rectangle(bounds);
53
+ var layer = ui.Map.Layer(outline, {color: 'FFFFFF'}, 'Zoom Box Bounds');
54
+ Map.layers().set(1, layer);
55
+ } catch (e) {
56
+ // Ignore geometry errors during initialization
57
+ }
46
58
  };
47
59
 
48
- // Add a label and the zoom box map to the default map.
49
- var instructions = ui.Label('Click the map to see an area in detail.', {
50
- stretch: 'both',
51
- textAlign: 'center',
52
- backgroundColor: '#d3d3d3'
60
+ zoomBox.onChangeBounds(function() {
61
+ if (!isMapReady) return;
62
+ updateOutline();
63
+ });
64
+
65
+ // Delay initial bounds drawing to allow map to initialize.
66
+ ui.util.setTimeout(function() {
67
+ isMapReady = true;
68
+ updateOutline();
69
+ }, 1000);
70
+
71
+ // Interaction.
72
+ Map.onClick(function(coords) {
73
+ if (isFirstClick) {
74
+ zoomBox.remove(instructionLabel);
75
+ isFirstClick = false;
76
+ }
77
+ zoomBox.setCenter(coords.lon, coords.lat, 8);
53
78
  });
79
+
80
+ // Layout.
54
81
  var panel = ui.Panel({
55
- widgets: [zoomBox, instructions],
82
+ widgets: [zoomBox],
56
83
  style: {
57
84
  position: 'top-right',
58
85
  height: '300px',
59
86
  width: '300px',
87
+ border: '1px solid white',
88
+ padding: '0'
60
89
  }
61
90
  });
91
+
62
92
  Map.add(ui.Label('Night Light Trends'));
63
- Map.add(panel);
93
+ Map.add(panel);
package/src/image.js CHANGED
@@ -25,8 +25,8 @@ goog.require('goog.object');
25
25
  /**
26
26
  * An object to represent an Earth Engine image. This constructor accepts a
27
27
  * variety of arguments:
28
- * - A string: an EarthEngine asset id,
29
- * - A string and a number: an EarthEngine asset id and version,
28
+ * - A string: an Earth Engine asset id,
29
+ * - A string and a number: an Earth Engine asset id and version,
30
30
  * - A number or ee.Array: creates a constant image,
31
31
  * - A list: creates an image out of each list element and combines them
32
32
  * into a single image,