2

I'm trying to browserify google earth engine Javascript API.

I installed the module:

npm install --save-dev @google/earthengine

I created a new main.js file for testing purposes:

var md = require('@google/earthengine');
 
module.exports = MDOutSystems;

function MDOutSystems() {
  this.mdInstance = md;
};

MDOutSystems.prototype.data.authenticateViaPrivateKey = function(
    privateKey, opt_success, opt_error, opt_extraScopes,
    opt_suppressDefaultScopes) {
    md.data.authenticateViaPrivateKey(privateKey, opt_success, opt_error, opt_extraScopes,
        opt_suppressDefaultScopes);
};

MDOutSystems.prototype.initialize = function() {
    md.initialize();
};

MDOutSystems.prototype.Image = function(source) {
    md.Image(source);
};

MDOutSystems.prototype.getInstance = function () {
    return this.mdInstance;
}

(I've got an warning that I need to create a d.ts file with declare module '@google/earthengine' )

I used the following code to expose the module I created:

Browserify main.js --standalone MDOutSystems > google-earth-outsystems.js

Although, when I try to call

var ee = new MDOutSystems();

I got an error saying that "MDOutSystems is not defined".

Please, help.

I've tried moving the main.js to insie the folder /node_modules and run the browserify command again. It actually resulted in a totaly different google-earth-outsystems.js file but it still didn't work.

1 Answers1

1

I guess Browserify minifies the code and changes function names.

MDOutSystems() is unknown afterwards.

Attach your method to the window object.

Like this:

function MDOutSystems() {
  this.mdInstance = md;
};

window.MDOutSystems = MDOutSystems;
tom
  • 9,550
  • 6
  • 30
  • 49