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

Commit 70443c2

Browse files
Merge pull request #1 from tomwayson/master
update
2 parents dd3d0dd + 141788b commit 70443c2

File tree

4 files changed

+76
-17
lines changed

4 files changed

+76
-17
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# angular-esri-loader Change Log
2+
All notable changes to this project will be documented in this file.
3+
This project adheres to [Semantic Versioning](http://semver.org/).
4+
5+
## 0.1.11
6+
### Changed
7+
- Removed index.ts as main entry point

README.md

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,86 @@
11
# angular2-esri-loader
2-
An Angular 2 service to help you load [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/) Modules
2+
An [Angular](https://angular.io/) library to help you load [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/) modules.
3+
4+
Exposes a service that wraps the functions from the [esri-loader](https://github.com/tomwayson/esri-loader) library in new functions that return promises.
5+
6+
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).
37

48
## Install
59
```bash
610
npm install angular2-esri-loader esri-loader
711
```
812

913
## Usage
10-
Example of using the loader service in a resolver to lazy load the ArcGIS API and
14+
Example of using the loader service in a component to lazy load the ArcGIS API and create a map
1115

1216
```ts
13-
import { Injectable } from '@angular/core';
14-
import { Resolve } from '@angular/router';
17+
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
1518

1619
import { EsriLoaderService } from 'angular2-esri-loader';
1720

18-
@Injectable()
19-
export class EsriMapResolveService implements Resolve<any> {
21+
@Component({
22+
selector: 'app-esri-map',
23+
templateUrl: './esri-map.component.html',
24+
styleUrls: ['./esri-map.component.css']
25+
})
26+
export class EsriMapComponent implements OnInit {
27+
@ViewChild('map') mapEl: ElementRef;
28+
29+
map: any;
2030

2131
constructor(private esriLoader: EsriLoaderService) { }
2232

23-
resolve() {
24-
// only load the ArcGIS API for JavaScript when we get to this route
33+
ngOnInit() {
34+
// only load the ArcGIS API for JavaScript when this component is loaded
2535
return this.esriLoader.load({
2636
// use a specific version of the API instead of the latest
2737
url: '//js.arcgis.com/3.18/'
2838
}).then(() => {
2939
// load the map class needed to create a new map
30-
// and make it available in the route's data
31-
return this.esriLoader.loadModules(['esri/map']);
40+
this.esriLoader.loadModules(['esri/map']).then(([Map]) => {
41+
// create the map at the DOM element in this component
42+
this.map = new Map(this.mapEl.nativeElement, {
43+
center: [-118, 34.5],
44+
zoom: 8,
45+
basemap: 'dark-gray'
46+
});
47+
});
3248
});
3349
}
3450
}
3551
```
36-
52+
53+
### In an Angular CLI Application
54+
55+
To use this library in an [Angular CLI](https://github.com/angular/angular-cli) application, the best place to start is to follow the instructions in [this gist](https://gist.github.com/tomwayson/e6260adfd56c2529313936528b8adacd).
56+
57+
For an example of how to use this service to lazy load the ArcGIS API and resolve modules in a route, see
58+
[esri-angular-cli-example's esri-map-resolve.service.ts](https://github.com/tomwayson/esri-angular-cli-example/blob/ab4540912904cf78ccfd904fb3bfa4c69b4aa1da/src/app/esri-map/esri-map-resolve.service.ts).
59+
60+
### In an angular2-webpack-starter Application
61+
62+
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.
63+
64+
## ArcGIS Types
65+
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.
66+
67+
### 4.x Types
68+
Follow [these instructions](https://github.com/Esri/jsapi-resources/tree/master/4.x/typescript) to install the 4.x types.
69+
70+
For Angular CLI applications, you will also need to add "arcgis-js-api" to `compilerOptions.types` in src/tsconfig.app.json and src/tsconfig.spec.json [as shown here](https://gist.github.com/tomwayson/e6260adfd56c2529313936528b8adacd#adding-the-arcgis-api-for-javascript-types).
71+
72+
Then you can use the `__esri` namespace for the types as seen in [this example](https://github.com/kgs916/angular2-esri4-components/blob/68861b286fd3a4814c495c2bd723e336e917ced2/src/lib/esri4-map/esri4-map.component.ts#L20-L26).
73+
74+
### 3.x Types
75+
Unfortunately the `__esri` namespace is not defined for 3.x types. You can use [these instructions](https://github.com/Esri/jsapi-resources/tree/master/3.x/typescript) to install the 3.x types, but then [you will still need to use `import` statements to get the types](https://github.com/Esri/jsapi-resources/issues/60). This may cause build errors that may or may not result in actual runtime errors depending on your environment.
76+
77+
## Examples
78+
This service is in use in these applications:
79+
- [esri-angular-cli-example](https://github.com/tomwayson/esri-angular-cli-example)
80+
81+
## Resources
82+
* [Using the ArcGIS API for JavaScript in Applications built with webpack](http://tomwayson.com/2016/11/27/using-the-arcgis-api-for-javascript-in-applications-built-with-webpack/)
83+
* [esri-loader](https://github.com/tomwayson/esri-loader)
84+
85+
## Credit
86+
Thanks to [@kgs916](https://github.com/kgs916) for helping me figure out how to publish a TypeScript library for Angular 2. I'll never do that again.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-esri-loader",
3-
"version": "0.1.9",
3+
"version": "0.1.11",
44
"description": "An Angular 2 service to help you load ArcGIS API for JavaScript Modules",
55
"scripts": {
66
"test": "tsc",
@@ -28,9 +28,7 @@
2828
"zone.js": "^0.6.23"
2929
},
3030
"devDependencies": {
31-
"@types/core-js": "^0.9.34",
3231
"typescript": "^2.0.10"
3332
},
34-
"typings": "index.d.ts",
35-
"main": "index.ts"
33+
"typings": "index.d.ts"
3634
}

tsconfig.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
"emitDecoratorMetadata": true,
77
"experimentalDecorators": true,
88
"sourceMap": true,
9-
"declaration": true
9+
"declaration": true,
10+
"lib": [
11+
"es2015",
12+
"dom"
13+
]
1014
},
1115
"files": [
1216
"index.ts"
1317
],
1418
"exclude": [
1519
"node_modules"
1620
]
17-
}
21+
}

0 commit comments

Comments
 (0)