|
| 1 | +import { LoaderOptions } from './src/loaders/loader-options.interface'; |
| 2 | +import { |
| 3 | + LazyMapsApiLoader |
| 4 | +} from './src/loaders/lazy-maps-api-loader'; |
| 5 | +import { APP_INITIALIZER, NgModule, ModuleWithProviders } from '@angular/core'; |
| 6 | +import { MapsManager } from './src/services/maps-manager'; |
| 7 | +import {BaseMapsApiLoader, LAZY_LOADER_OPTIONS} from './src/loaders/base-maps-api-loader'; |
| 8 | +import { NoopMapsApiLoader } from './src/loaders/noop-maps-api-loader'; |
| 9 | +import { MapComponent } from './src/directives/map'; |
| 10 | +import { MapDirectionsDirective } from './src/directives/map-directions'; |
| 11 | +import { MapMakerDirective } from './src/directives/map-marker'; |
| 12 | +import { MapPolylineDirective } from './src/directives/map-polyline'; |
| 13 | +export { LoaderOptions } from './src/loaders/loader-options.interface'; |
| 14 | + |
| 15 | +export { |
| 16 | + BaseMapComponent, |
| 17 | + MapComponent, |
| 18 | + MapDirectionsDirective, |
| 19 | + MapMakerDirective, |
| 20 | + MapPolylineDirective, |
| 21 | + IOptionalSetMapMethod |
| 22 | +} from './src/directives'; |
| 23 | +export { |
| 24 | + BaseMapsApiLoader, |
| 25 | + LAZY_LOADER_OPTIONS, |
| 26 | + LazyMapsApiLoader, |
| 27 | + MapsManager, |
| 28 | + NoopMapsApiLoader, |
| 29 | + Animation, |
| 30 | + IAnimation, |
| 31 | + ZoomLevel, |
| 32 | + IZoomLevel, |
| 33 | + LatLng, |
| 34 | + GeoPoint, |
| 35 | + MarkerOptions, |
| 36 | + PolylineOptions |
| 37 | +} from './src/services'; |
| 38 | + |
| 39 | +/** |
| 40 | + * Factory function which builds handler for application initialization |
| 41 | + * @param loader instance of loader, should be passed as dependency |
| 42 | + * @returns {()=>Promise<any>} function is executed by angular application initializer |
| 43 | + * @constructor |
| 44 | + */ |
| 45 | +export function MapsApiLoaderFactory(loader: LazyMapsApiLoader) { |
| 46 | + return goLoad; |
| 47 | + |
| 48 | + function goLoad(): Promise<any> { |
| 49 | + return loader.load(); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +@NgModule({ |
| 54 | + declarations: [ |
| 55 | + MapComponent, |
| 56 | + MapDirectionsDirective, |
| 57 | + MapMakerDirective, |
| 58 | + MapPolylineDirective |
| 59 | + ], |
| 60 | + exports: [ |
| 61 | + MapComponent, |
| 62 | + MapDirectionsDirective, |
| 63 | + MapMakerDirective, |
| 64 | + MapPolylineDirective |
| 65 | + ] |
| 66 | +}) |
| 67 | +export class HereMapsModule { |
| 68 | + /** |
| 69 | + * Used to register in top level or shared module in your application. Loader Options are mandatory. |
| 70 | + * {@expample |
| 71 | + * import {NgModule} from '@angular/core'; |
| 72 | + * |
| 73 | + * @NgModule({ |
| 74 | + * declarations: [...], |
| 75 | + * imports: [ |
| 76 | + * ... |
| 77 | + * HereMapsModule.forRoot(<LoaderOptions>{ |
| 78 | + * apiKey: "your heremaps API key |
| 79 | + * libraries: ["places", "geometry"] |
| 80 | + * }), |
| 81 | + * ... |
| 82 | + * ], |
| 83 | + * // optional, you can import module like below if your module depends only on component and directives |
| 84 | + * exports: [ |
| 85 | + * HereMapsModule |
| 86 | + * ] |
| 87 | + * }) |
| 88 | + * export class MySharedModule { } |
| 89 | + * } |
| 90 | + * |
| 91 | + * @param loaderOptions |
| 92 | + * @returns {ModuleWithProviders} |
| 93 | + */ |
| 94 | + static forRoot(loaderOptions: LoaderOptions): ModuleWithProviders { |
| 95 | + return { |
| 96 | + ngModule: HereMapsModule, |
| 97 | + providers: [ |
| 98 | + { |
| 99 | + provide: LAZY_LOADER_OPTIONS, |
| 100 | + useValue: loaderOptions |
| 101 | + }, |
| 102 | + LazyMapsApiLoader, |
| 103 | + { |
| 104 | + provide: APP_INITIALIZER, |
| 105 | + useFactory: MapsApiLoaderFactory, |
| 106 | + deps: [LazyMapsApiLoader], |
| 107 | + multi: true |
| 108 | + }, |
| 109 | + { provide: MapsManager, useClass: MapsManager } |
| 110 | + ] |
| 111 | + }; |
| 112 | + } |
| 113 | +} |
0 commit comments