0.4.1 • Published 6 years ago

esri-promise v0.4.1

Weekly downloads
76
License
ISC
Repository
github
Last release
6 years ago

Version 0.4.1 100% Code Coverage

esri-promise

Lightweight promise wrapper for asynchronous loading of ArcGIS API for JavaScript modules.

This was completely inspired by and modeled after Tom Wayson's very useful library esri-loader. See his blog post on why this sort of thing could be useful here.

Installation

npm install esri-promise

New in 0.4.x:

  • Esri-promise no longer depends on the es6-promise polyfill. You will have to include the Promise constructor in your application at runtime to achieve compatibility with browsers that don't natively support es6 promises.

  • Esri-promise will warn you if the ArcGIS API for JavaScript is going to overwrite an existing global require in your project. It will not prevent it from doing so however, because the ArcGIS API for JavaScript depends on dojo's loader.

  • Added unit tests and switched it to use async/await under the hood. This has no bearing on the public API whatsoever.

New in 0.3.x:

Esri-promise will now use version 4.5 of the ArcGIS JS API by default.

New in 0.2.x:

Now in version 0.2.x, you can pass dojo configuration parameters into esriBootstrap like so:

import esriPromise, { esriBootstrap } from 'esri-promise';

const package_path = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/'));

esriBootstrap('https://js.arcgis.com/4.3/', {
  async: true,
  packages: [
    {
      location: package_path + '/config',
      name: 'config'
    }
  ]
}).then(() => {
    esriPromise([
        'dojo/text!config/test.json'
    ]).then(([
        result
    ]) => {
        console.log(result);
    });
});

This helps you use dojo plugins like text and i18n in conjunction with esri-promise.

Use

By default, esri-promise will use version 4.5 of the ArcGIS API for JavaScript (or whatever version has already been loaded through esriBootstrap('url')):

import { esriPromise } from 'esri-promise';

esriPromise([
    'esri/Map',
    'esri/views/MapView'
]).then(([ Map, MapView ]) => { // Modules come back as an array, so array destructuring is convenient here.
    // Make a map with the Map and MapView modules from the API.
})
.catch((err) => {
    handle(err);
});

function handle(err) {
    // Do something with the error.
}

Alternatively, you can specify a version by calling esriBootstrap('url') (this also returns a promise):

import { esriPromise, esriBootstrap } from 'esri-promise';

esriBootstrap('https://js.arcgis.com/3.20/').then(() => {
  esriPromise([
    'esri/map',
    'esri/views/MapView'
  ]).then(([Map, MapView]) => {
    // Make a map with v3 of the API.
  })
  .catch((err) => {
    // Do something with a module load error.
  });
}).catch((err) => {
  // Shucks, couldn't load the API
});
0.4.1

6 years ago

0.4.0

6 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago