angular2-esri-loader
An Angular 2 service to help you load ArcGIS API for JavaScript modules.
Exposes a service that wraps the functions from the esri-loader library in new functions that return promises.
Install
npm install angular2-esri-loader esri-loader
Usage
Example of using the loader service in a component to lazy load the ArcGIS API and create a map
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { EsriLoaderService } from 'angular2-esri-loader';
@Component({
selector: 'app-esri-map',
templateUrl: './esri-map.component.html',
styleUrls: ['./esri-map.component.css']
})
export class EsriMapComponent implements OnInit {
@ViewChild('map') mapEl: ElementRef;
map: any;
constructor(private esriLoader: EsriLoaderService) { }
ngOnInit() {
return this.esriLoader.load({
url: '//js.arcgis.com/3.18/'
}).then(() => {
this.esriLoader.loadModules(['esri/map']).then(([Map]) => {
this.map = new Map(this.mapEl.nativeElement, {
center: [-118, 34.5],
zoom: 8,
basemap: 'dark-gray'
});
});
});
}
}
For an example of how to use this service to lazy load the ArcGIS API and resolve modules in a route, see
esri-angular-cli-example's esri-map-resolve.service.ts.
Examples
This service is in use in these applications:
Resources
Credit
Thanks to @kgs916 for helping me figure out how to publish a TypeScript library for Angular 2. I'll never do that again.