Loading Data

Once you’ve setup the SDK either for the browser or as an NPM module, getting data into your application is easy using the AerisWeather class.

Creating an AerisWeather instance initialized with your access keys will provide you with convenience entry points to quickly access the primary pieces of functionality within the SDK, such as creating an API data or Aeris Maps (AMP) image request. The following are the two primary entry points you’ll be working with on your AerisWeather instance:

Method Description
api() Returns a new API data request instance that can be configured for a specific endpoint and data request.
map() Returns a new AMP image request instance that can be configured to return a specific image.

The SDK returns a JavaScript Promise object when performing the asynchronous requests when calling get() on a request, either API or AMP request. This allows you to handle the response’s result on completion of the request. Furthermore, you can also use JavaScript’s async/await operators to mimic syncronous requests for data instead of relying on a Promise callback function.

API Data

Make sure you’ve initialized the SDK with your access keys as described in step two. Then, use the api() method to request weather data from the Aeris Weather API, which will return a new data request instance that you can configure further:

// create the request instance
var request = aeris.api();

// configure the request endpoint
request.endpoint('forecasts');

// set the place to request data for
request.place('seattle,wa');

// configure the request options
request.filter('daynight').limit(2);

// perform the request and output the data
request.get().then((result) => {
    // returned data will be accessible on `result.data`
    console.log(result.data);
});

The result that is returned to your Promise callback (or variable assignment when using async/await) will be an instance of ApiResult, which contains not only the data returned in the response, but other information about the response. You will typically only be accessing the result.data property as that is the actual data returned by the API for your request.

AMP Imagery

Make sure you’ve initialized the SDK with your access keys as described in step two. Then, use the map() method to request weather imagery from the Aeris Maps Platform (AMP), which will return a new map request instance that you can configure further:

// create the request instance
var request = aeris.map();

// set the map layers to include
request.layers('flat,radar,counties,admin');

// set the desired center coordinate and zoom level
request.center('seattle,wa').zoom(8);

// set the desired image size to 500x300 pixels
request.size(500, 300);

// perform the request and add the image to the DOM
request.get().then((result) => {
    // returned map image will be accessible on `result.image`
    var target = document.createElement('div');
    target.appendChild(result.image);
    document.body.appendChild(target);
});

The result that is returned to your Promise callback (or variable assignment when using async/await) will be an instance of MapResult, which contains not only the image returned by the response, but other information about the response. You will typically only be accessing the result.image property as that is the image element returned by AMP for your request.