Skip to content

Commit

Permalink
v0.1.56
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid authored and michaelfdewitt committed Jun 4, 2015
1 parent c2058ef commit 81ec4b4
Show file tree
Hide file tree
Showing 24 changed files with 1,884 additions and 568 deletions.
327 changes: 177 additions & 150 deletions javascript/build/ee_api_js.js

Large diffs are not rendered by default.

164 changes: 100 additions & 64 deletions javascript/build/ee_api_js_debug.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions javascript/src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,17 @@ ee.Collection.prototype.elementType = function() {
* receives an image or features and returns one. The function is called
* only once and the result is captured as a description, so it cannot
* perform imperative operations or rely on external state.
* @param {boolean=} opt_dropNulls If true, the mapped algorithm is allowed
* to return nulls, and the elements for which it returns nulls will be
* dropped.
* @return {ee.Collection} The mapped collection.
* @export
*/
ee.Collection.prototype.map = function(algorithm) {
ee.Collection.prototype.map = function(algorithm, opt_dropNulls) {
var elementType = this.elementType();
var withCast = function(e) { return algorithm(new elementType(e)); };
return this.castInternal(ee.ApiFunction._call(
'Collection.map', this, withCast));
'Collection.map', this, withCast, opt_dropNulls));
};


Expand Down
102 changes: 74 additions & 28 deletions javascript/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,32 @@ ee.data.reset = function() {
*
* This should be called before the EE library is initialized.
*
* Note that if the user has not previously granted access to the application
* identified by the client ID, by default this will try to pop up a dialog
* window prompting the user to grant the required permission. However, this
* popup can be blocked by the browser. To avoid this, specify the
* opt_onImmediateFailed callback, and in it render an in-page login button,
* then call ee.data.authenticateViaPopup() from the click event handler of
* this button. This stops the browser from blocking the popup, as it is now the
* direct result of a user action.
*
* @param {?string} clientId The application's OAuth client ID, or null to
* disable authenticated calls. This can be obtained through the Google
* Developers Console. The project must have a JavaScript origin that
* corresponds to the domain where the script is running.
* @param {function()} success The function to call if authentication succeeded.
* @param {function(string)=} opt_error The function to call if authentication
* failed, passed the error message.
* failed, passed the error message. If authentication in immediate
* (behind-the-scenes) mode fails and opt_onImmediateFailed is specified,
* that function is called instead of opt_error.
* @param {!Array<string>=} opt_extraScopes Extra OAuth scopes to request.
* @param {function()=} opt_onImmediateFailed The function to call if
* automatic behind-the-scenes authentication fails. Defaults to
* ee.data.authenticateViaPopup(), bound to the passed callbacks.
* @export
*
* TODO(user): Figure out if we need to deal with pop-up blockers.
*/
ee.data.authenticate = function(clientId, success, opt_error, opt_extraScopes) {
ee.data.authenticate = function(
clientId, success, opt_error, opt_extraScopes, opt_onImmediateFailed) {
// Remember the auth options.
var scopes = [ee.data.AUTH_SCOPE_];
if (opt_extraScopes) {
Expand All @@ -222,24 +235,46 @@ ee.data.authenticate = function(clientId, success, opt_error, opt_extraScopes) {
ee.data.authScopes_ = scopes;

// Start the authentication flow as soon as we have the auth library.
var onImmediateFailed = opt_onImmediateFailed || goog.partial(
ee.data.authenticateViaPopup, success, opt_error);
if (goog.isObject(goog.global['gapi']) &&
goog.isObject(goog.global['gapi']['auth']) &&
goog.isFunction(goog.global['gapi']['auth']['authorize'])) {
ee.data.refreshAuthToken_(success, opt_error);
ee.data.refreshAuthToken_(success, opt_error, onImmediateFailed);
} else {
// The library is not loaded; load it now.
var callbackName = goog.now().toString(36);
while (callbackName in goog.global) callbackName += '_';
goog.global[callbackName] = function() {
delete goog.global[callbackName];
ee.data.refreshAuthToken_(success, opt_error);
ee.data.refreshAuthToken_(success, opt_error, onImmediateFailed);
};
goog.net.jsloader.load(
ee.data.AUTH_LIBRARY_URL_ + '?onload=' + callbackName);
}
};


/**
* Shows a popup asking for the user's permission. Should only be called if
* ee.data.authenticate() called its opt_onImmediateFailed argument in the past.
*
* May be blocked by pop-up blockers if called outside a user-initiated handler.
*
* @param {function()=} opt_success The function to call if authentication
* succeeds.
* @param {function(string)=} opt_error The function to call if authentication
* fails, passing the error message.
*/
ee.data.authenticateViaPopup = function(opt_success, opt_error) {
goog.global['gapi']['auth']['authorize']({
'client_id': ee.data.authClientId_,
'immediate': false,
'scope': ee.data.authScopes_.join(' ')
}, goog.partial(ee.data.handleAuthResult_, opt_success, opt_error));
};


/**
* Sets the timeout length for asynchronous API requests.
*
Expand Down Expand Up @@ -1005,45 +1040,56 @@ ee.data.send_ = function(path, params, opt_callback, opt_method) {
* succeeds.
* @param {function(string)=} opt_error The function to call if token refresh
* fails, passing the error message.
* @param {function()=} opt_onImmediateFailed The function to call if
* automatic behind-the-scenes authentication fails.
* @private
*/
ee.data.refreshAuthToken_ = function(opt_success, opt_error) {
ee.data.refreshAuthToken_ = function(
opt_success, opt_error, opt_onImmediateFailed) {
// Set up auth options.
var authArgs = {
'client_id': ee.data.authClientId_,
'immediate': true,
'scope': ee.data.authScopes_.join(' ')
};

// A function to run when we get the authorization result.
var done = function(result) {
if (result['access_token']) {
ee.data.authToken_ = result['token_type'] + ' ' + result['access_token'];
// Set up a refresh timer. This is necessary because we cannot refresh
// synchronously, but since we want to allow synchronous API requests,
// something must ensure that the auth token is always valid.
setTimeout(ee.data.refreshAuthToken_, result['expires_in'] * 1000 / 2);
if (opt_success) opt_success();
} else if (opt_error) {
opt_error(result['error'] || 'Unknown error.');
}
};

// Start the authorization flow, first trying immediate mode, which tries to
// get the token behind the scenes, with no UI shown.
var authorize = goog.global['gapi']['auth']['authorize'];
authorize(authArgs, function(result) {
if (result['error'] == 'immediate_failed') {
// Could not auth invisibly. Auth using a dialog.
authArgs['immediate'] = false;
authorize(authArgs, done);
goog.global['gapi']['auth']['authorize'](authArgs, function(result) {
if (result['error'] == 'immediate_failed' && opt_onImmediateFailed) {
opt_onImmediateFailed();
} else {
done(result);
ee.data.handleAuthResult_(opt_success, opt_error, result);
}
});
};


/**
* Handles the result of gapi.auth.authorize(), filling ee.data.authToken_ on
* success and setting up a refresh timeout.
*
* @param {function()|undefined} success The function to call if token refresh
* succeeds.
* @param {function(string)|undefined} error The function to call if auth fails,
* passing the error message.
* @param {Object} result The result object produced by gapi.auth.authorize().
* @private
*/
ee.data.handleAuthResult_ = function(success, error, result) {
if (result['access_token']) {
ee.data.authToken_ = result['token_type'] + ' ' + result['access_token'];
// Set up a refresh timer. This is necessary because we cannot refresh
// synchronously, but since we want to allow synchronous API requests,
// something must ensure that the auth token is always valid.
setTimeout(ee.data.refreshAuthToken_, result['expires_in'] * 1000 / 2);
if (success) success();
} else if (error) {
error(result['error'] || 'Unknown error.');
}
};


/**
* Convert an object into a goog.Uri.QueryData.
*
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 61 additions & 24 deletions javascript/src/ee_api_js.externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ ee.Collection.prototype.limit = function(max, opt_property, opt_ascending) {
};
/**
* @param {function ((Object|null)): (Object|null)} algorithm
* @param {boolean=} opt_dropNulls
* @return {(ee.Collection|null)}
*/
ee.Collection.prototype.map = function(algorithm) {
ee.Collection.prototype.map = function(algorithm, opt_dropNulls) {
};
/**
* @param {string} property
Expand Down Expand Up @@ -545,7 +546,7 @@ ee.Function.prototype.call = function(var_args) {
};
/**
* @param {(Object|null)} geoJson
* @param {(String|null)=} opt_proj
* @param {(ee.Projection|null)=} opt_proj
* @param {boolean=} opt_geodesic
* @return {?}
* @extends {ee.ComputedObject}
Expand All @@ -554,72 +555,88 @@ ee.Function.prototype.call = function(var_args) {
ee.Geometry = function(geoJson, opt_proj, opt_geodesic) {
};
/**
* @param {(Array<Array<number>>|number)} coordinates
* @param {(Array|null)} coords
* @param {(ee.Projection|null)=} opt_proj
* @param {boolean=} opt_geodesic
* @param {(ee.ErrorMargin|null)=} opt_maxError
* @return {?}
* @extends {ee.Geometry}
* @constructor
*/
ee.Geometry.LineString = function(coordinates) {
ee.Geometry.LineString = function(coords, opt_proj, opt_geodesic, opt_maxError) {
};
/**
* @param {(Array<Array<number>>|number)} coordinates
* @param {(Array|null)} coords
* @param {(ee.Projection|null)=} opt_proj
* @param {boolean=} opt_geodesic
* @param {(ee.ErrorMargin|null)=} opt_maxError
* @return {?}
* @extends {ee.Geometry}
* @constructor
*/
ee.Geometry.LinearRing = function(coordinates) {
ee.Geometry.LinearRing = function(coords, opt_proj, opt_geodesic, opt_maxError) {
};
/**
* @param {(Array<Array<Array<number>>>|number)} coordinates
* @param {(Array|null)} coords
* @param {(ee.Projection|null)=} opt_proj
* @param {boolean=} opt_geodesic
* @param {(ee.ErrorMargin|null)=} opt_maxError
* @return {?}
* @extends {ee.Geometry}
* @constructor
*/
ee.Geometry.MultiLineString = function(coordinates) {
ee.Geometry.MultiLineString = function(coords, opt_proj, opt_geodesic, opt_maxError) {
};
/**
* @param {(Array<Array<number>>|number)} coordinates
* @param {(Array|null)} coords
* @param {(ee.Projection|null)=} opt_proj
* @return {?}
* @extends {ee.Geometry}
* @constructor
*/
ee.Geometry.MultiPoint = function(coordinates) {
ee.Geometry.MultiPoint = function(coords, opt_proj) {
};
/**
* @param {(Array<Array<Array<Array<number>>>>|number)} coordinates
* @param {(Array|null)} coords
* @param {(ee.Projection|null)=} opt_proj
* @param {boolean=} opt_geodesic
* @param {(ee.ErrorMargin|null)=} opt_maxError
* @return {?}
* @extends {ee.Geometry}
* @constructor
*/
ee.Geometry.MultiPolygon = function(coordinates) {
ee.Geometry.MultiPolygon = function(coords, opt_proj, opt_geodesic, opt_maxError) {
};
/**
* @param {(Array<number>|null|number)} coordsOrLon
* @param {number=} opt_lat
* @param {Array<number>} coords
* @param {(ee.Projection|null)=} opt_proj
* @return {?}
* @extends {ee.Geometry}
* @constructor
*/
ee.Geometry.Point = function(coordsOrLon, opt_lat) {
ee.Geometry.Point = function(coords, opt_proj) {
};
/**
* @param {(Array<Array<Array<number>>>|number)} coordinates
* @param {(Array|null)} coords
* @param {(ee.Projection|null)=} opt_proj
* @param {boolean=} opt_geodesic
* @param {(ee.ErrorMargin|null)=} opt_maxError
* @return {?}
* @extends {ee.Geometry}
* @constructor
*/
ee.Geometry.Polygon = function(coordinates) {
ee.Geometry.Polygon = function(coords, opt_proj, opt_geodesic, opt_maxError) {
};
/**
* @param {(Array<number>|null|number)} coordsOrLon1
* @param {number=} opt_lat1
* @param {number=} opt_lon2
* @param {number=} opt_lat2
* @param {(Array|null)} coords
* @param {(ee.Projection|null)=} opt_proj
* @param {boolean=} opt_geodesic
* @param {(ee.ErrorMargin|null)=} opt_maxError
* @return {?}
* @extends {ee.Geometry}
* @constructor
*/
ee.Geometry.Rectangle = function(coordsOrLon1, opt_lat1, opt_lon2, opt_lat2) {
ee.Geometry.Rectangle = function(coords, opt_proj, opt_geodesic, opt_maxError) {
};
/**
* @return {string}
Expand Down Expand Up @@ -745,7 +762,18 @@ ee.InitState.READY;
*/
ee.List = function(list) {
};
ee.MapLayerOverlay;
/**
* @param {string} url
* @param {string} mapId
* @param {string} token
* @param {(Object|null)} init
* @extends {goog.events.EventTarget}
* @implements {goog.disposable.IDisposable}
* @implements {goog.events.Listenable}
* @constructor
*/
ee.MapLayerOverlay = function(url, mapId, token, init) {
};
/**
* @param {(google.maps.Point|null)} coord
* @param {number} zoom
Expand All @@ -766,6 +794,14 @@ ee.MapLayerOverlay.prototype.releaseTile = function(tileDiv) {
*/
ee.MapLayerOverlay.prototype.setOpacity = function(opacity) {
};
/**
* @extends {goog.events.EventTarget}
* @implements {goog.disposable.IDisposable}
* @implements {goog.events.Listenable}
* @constructor
*/
ee.MapTileManager = function() {
};
ee.Number;
/**
* @param {boolean=} opt_isCompound
Expand Down Expand Up @@ -816,9 +852,10 @@ ee.data;
* @param {function (): ?} success
* @param {function (string): ?=} opt_error
* @param {Array<string>=} opt_extraScopes
* @param {function (): ?=} opt_onImmediateFailed
* @return {undefined}
*/
ee.data.authenticate = function(clientId, success, opt_error, opt_extraScopes) {
ee.data.authenticate = function(clientId, success, opt_error, opt_extraScopes, opt_onImmediateFailed) {
};
/**
* @param {string} taskId
Expand Down
4 changes: 2 additions & 2 deletions javascript/src/examples/ImageCollection/ModisCloudMasking.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var getQABits = function(image, start, end, newName) {
var maskEmptyPixels = function(image) {
// Find pixels that had observations.
var withObs = image.select('num_observations_1km').gt(0);
return image.mask(withObs);
return image.mask(image.mask().and(withObs));
};

// A function to mask out cloudy pixels.
Expand All @@ -40,7 +40,7 @@ var maskClouds = function(image) {
// Get the internal_cloud_algorithm_flag bit.
var internalCloud = getQABits(QA, 10, 10, 'internal_cloud_algorithm_flag');
// Return an image masking out cloudy areas.
return image.mask(internalCloud.eq(0));
return image.mask(image.mask().and(internalCloud.eq(0)));
};

// Start with an image collection for a 1 month period.
Expand Down
Loading

0 comments on commit 81ec4b4

Please sign in to comment.