Skip to content
This repository was archived by the owner on Apr 9, 2018. It is now read-only.

It's just angular-esri-loader #16

Merged
merged 4 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 81 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
# angular2-esri-loader
# angular-esri-loader
An [Angular](https://angular.io/) library to help you load [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/) modules.

Exposes a service that wraps the functions from the [esri-loader](https://github.com/tomwayson/esri-loader) library in new functions that return promises.

To understand why this is needed, and the benefits of using esri-loader over other techniques, see the [esri-loader README](https://github.com/tomwayson/esri-loader#why-is-this-needed).

## Install
For Angular 4 and above:

```bash
npm install angular-esri-loader
```

For Angular 2:

```bash
npm install angular2-esri-loader esri-loader
```

**NOTE**: for AngularJS use [angular-esri-map](https://github.com/Esri/angular-esri-map).

## Usage
Example of using the loader service in a component to lazy load the ArcGIS API and create a map

Below is an example of using the loader service in a component to lazy load the ArcGIS API and create a map.

First you need to import the `EsriLoaderModule` into your application:

```ts
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { EsriLoaderModule } from 'angular-esri-loader';

import { AppComponent } from './app.component';
import { EsriMapComponent } from './esri-map.component';

@NgModule({
declarations: [
AppComponent,
EsriMapComponent
],
imports: [
BrowserModule,
EsriLoaderModule,
],
bootstrap: [AppComponent]
})
export class AppModule { }
```

import { EsriLoaderService } from 'angular2-esri-loader';
Then you can use the `EsriLoaderService` in a component to load a map:

```ts
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { EsriLoaderService } from 'angular-esri-loader';

@Component({
selector: 'app-esri-map',
Expand Down Expand Up @@ -61,6 +97,47 @@ For an example of how to use this service to lazy load the ArcGIS API and resolv

See [this gist](https://gist.github.com/jwasilgeo/00855ee002aca822e33abd8a7a031f56) for instructions on how to use this library in an [AngularClass/angular2-webpack-starter](https://github.com/AngularClass/angular2-webpack-starter) application.

### In an Angular 2 Application

Example of using the loader service in a component to lazy load the ArcGIS API and create a map

```ts
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';

import { EsriLoaderService } from 'angular-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() {
// only load the ArcGIS API for JavaScript when this component is loaded
return this.esriLoader.load({
// use a specific version of the API instead of the latest
url: '//js.arcgis.com/3.18/'
}).then(() => {
// load the map class needed to create a new map
this.esriLoader.loadModules(['esri/map']).then(([Map]) => {
// create the map at the DOM element in this component
this.map = new Map(this.mapEl.nativeElement, {
center: [-118, 34.5],
zoom: 8,
basemap: 'dark-gray'
});
});
});
}
}
```

## ArcGIS Types
This service doesn't make any assumptions about which version of the ArcGIS API you are using, so you will have to manually install the appropriate types.

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "angular2-esri-loader",
"name": "angular-esri-loader",
"version": "1.0.0",
"description": "An Angular (2+) service to help you load ArcGIS API for JavaScript Modules",
"scripts": {
"build": "npm run clean && npm run ngc && npm run rollup && npm run copy",
"clean": "rimraf build dist",
"copy": "copyfiles -u 1 \"build/**/*{.d.ts,.js.map,.metadata.json}\" dist && copyfiles -f src/package.json README.md dist",
"ngc": "ngc -p tsconfig.json",
"rollup": "rollup build/angular2-esri-loader.js -o dist/angular2-esri-loader.js",
"rollup": "rollup build/angular-esri-loader.js -o dist/angular-esri-loader.js",
"prepublish": "npm run build",
"preversion": "npm run test && git add README.md CHANGELOG.md",
"test": "ngc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tomwayson/angular2-esri-loader.git"
"url": "git+https://github.com/tomwayson/angular-esri-loader.git"
},
"keywords": [
"Angular",
Expand All @@ -24,9 +24,9 @@
"author": "Tom Wayson <[email protected]> (https://tomwayson.com)",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/tomwayson/angular2-esri-loader/issues"
"url": "https://github.com/tomwayson/angular-esri-loader/issues"
},
"homepage": "https://github.com/tomwayson/angular2-esri-loader#readme",
"homepage": "https://github.com/tomwayson/angular-esri-loader#readme",
"devDependencies": {
"@angular/compiler": "^4.1.1",
"@angular/compiler-cli": "^4.1.1",
Expand Down
12 changes: 6 additions & 6 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "angular2-esri-loader",
"name": "angular-esri-loader",
"version": "0.1.11",
"description": "An Angular (2+) service to help you load ArcGIS API for JavaScript modules",
"repository": {
"type": "git",
"url": "git+https://github.com/tomwayson/angular2-esri-loader.git"
"url": "git+https://github.com/tomwayson/angular-esri-loader.git"
},
"keywords": [
"Angular",
Expand All @@ -14,9 +14,9 @@
"author": "Tom Wayson <[email protected]> (https://tomwayson.com)",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/tomwayson/angular2-esri-loader/issues"
"url": "https://github.com/tomwayson/angular-esri-loader/issues"
},
"homepage": "https://github.com/tomwayson/angular2-esri-loader#readme",
"homepage": "https://github.com/tomwayson/angular-esri-loader#readme",
"dependencies": {
"esri-loader": "^1.0.0"
},
Expand All @@ -25,6 +25,6 @@
"rxjs": "^5.3.0",
"zone.js": "^0.8.5"
},
"module": "angular2-esri-loader.js",
"typings": "angular2-esri-loader.d.ts"
"module": "angular-esri-loader.js",
"typings": "angular-esri-loader.d.ts"
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"skipTemplateCodegen": true,
"flatModuleOutFile": "angular2-esri-loader.js",
"flatModuleId": "angular2-esri-loader"
"flatModuleOutFile": "angular-esri-loader.js",
"flatModuleId": "angular-esri-loader"
}
}