0

sorry I am not much of a Javascript programmer so this is a rather noob question. But I was having trouble trying to import the Google Earth Engine api file into another javascript file. All of the examples in the Earth Engine repo use a <script src="/static/ee_api_js.js"></script> in html to access the Earth Engine features, but I want to avoid using html.

I tried to follow standard Javascript procedures. Here is the code that I got.

var mymod = require('/../javascript/ee_api_js');

var image = mymod.Image('srtm90_v4');
var path = image.getDownloadURL({
    'scale': 30,
    'crs': 'EPSG:4326',
    'region': '[[-120, 35], [-119, 35], [-119, 34], [-120, 34]]'
});
print(path);

The error message I got back was:

var image = mymod.Image('srtm90_v4');
                  ^
TypeError: mymod.Image is not a function

The original ee_api_js.js file is located in the github repo at: https://github.com/google/earthengine-api/tree/master/javascript/build

Not sure why this module is not importing correctly? Any ideas.

krishnab
  • 9,270
  • 12
  • 66
  • 123

2 Answers2

2

I suspect your life will be a lot easier if you alias that:

var ee = require('...').ee
Noel Gorelick
  • 489
  • 2
  • 10
1

Okay, I figured it out. For some reason my autocomplete did not pick this up, but the debugger did. You need a mymod.ee. in order to access these functions. I updated the code below.

var mymod = require('/../javascript/ee_api_js');

var image = mymod.ee.Image('srtm90_v4');
krishnab
  • 9,270
  • 12
  • 66
  • 123