UNPKG

@ng-web-apis/geolocation

Version:

This is a library for declarative use of Geolocation API with Angular

1 lines 4.38 kB
{"version":3,"file":"ng-web-apis-geolocation.mjs","sources":["../../../libs/geolocation/src/tokens/geolocation.ts","../../../libs/geolocation/src/tokens/geolocation-options.ts","../../../libs/geolocation/src/tokens/geolocation-support.ts","../../../libs/geolocation/src/services/geolocation.service.ts","../../../libs/geolocation/src/ng-web-apis-geolocation.ts"],"sourcesContent":["import {inject, InjectionToken} from '@angular/core';\nimport {WA_NAVIGATOR} from '@ng-web-apis/common';\n\nexport const WA_GEOLOCATION = new InjectionToken<Geolocation>('[WA_GEOLOCATION]', {\n factory: () => inject(WA_NAVIGATOR).geolocation,\n});\n\n/**\n * @deprecated: drop in v5.0, use {@link WA_GEOLOCATION}\n */\nexport const GEOLOCATION = WA_GEOLOCATION;\n","import {InjectionToken} from '@angular/core';\n\nexport const WA_POSITION_OPTIONS = new InjectionToken<PositionOptions>(\n '[WA_POSITION_OPTIONS]',\n {factory: () => ({})},\n);\n\n/**\n * @deprecated: drop in v5.0, use {@link WA_POSITION_OPTIONS}\n */\nexport const POSITION_OPTIONS = WA_POSITION_OPTIONS;\n","import {inject, InjectionToken} from '@angular/core';\n\nimport {GEOLOCATION} from './geolocation';\n\nexport const WA_GEOLOCATION_SUPPORT = new InjectionToken<boolean>(\n '[WA_GEOLOCATION_SUPPORT]',\n {\n factory: () => !!inject(GEOLOCATION),\n },\n);\n\n/**\n * @deprecated: drop in v5.0, use {@link WA_GEOLOCATION_SUPPORT}\n */\nexport const GEOLOCATION_SUPPORT = WA_GEOLOCATION_SUPPORT;\n","import {inject, Injectable} from '@angular/core';\nimport {finalize, Observable, shareReplay} from 'rxjs';\n\nimport {GEOLOCATION} from '../tokens/geolocation';\nimport {POSITION_OPTIONS} from '../tokens/geolocation-options';\nimport {GEOLOCATION_SUPPORT} from '../tokens/geolocation-support';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class GeolocationService extends Observable<GeolocationPosition> {\n constructor() {\n const geolocationRef = inject(GEOLOCATION);\n const geolocationSupported = inject(GEOLOCATION_SUPPORT);\n const positionOptions = inject(POSITION_OPTIONS);\n\n let watchPositionId = 0;\n\n super((subscriber) => {\n if (!geolocationSupported) {\n subscriber.error('Geolocation is not supported in your browser');\n }\n\n watchPositionId = geolocationRef.watchPosition(\n (position) => subscriber.next(position),\n (positionError) => subscriber.error(positionError),\n positionOptions,\n );\n });\n\n return this.pipe(\n finalize(() => geolocationRef.clearWatch(watchPositionId)),\n shareReplay({bufferSize: 1, refCount: true}),\n ) as GeolocationService;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;MAGa,cAAc,GAAG,IAAI,cAAc,CAAc,kBAAkB,EAAE;IAC9E,OAAO,EAAE,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,WAAW;AAClD,CAAA,EAAE;AAEH;;AAEG;AACI,MAAM,WAAW,GAAG;;MCRd,mBAAmB,GAAG,IAAI,cAAc,CACjD,uBAAuB,EACvB,EAAC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAC,EACvB;AAEF;;AAEG;AACI,MAAM,gBAAgB,GAAG;;MCNnB,sBAAsB,GAAG,IAAI,cAAc,CACpD,0BAA0B,EAC1B;IACI,OAAO,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;AACvC,CAAA,EACH;AAEF;;AAEG;AACI,MAAM,mBAAmB,GAAG;;ACPnC,MAGa,kBAAmB,SAAQ,UAA+B,CAAA;AACnE,IAAA,WAAA,GAAA;AACI,QAAA,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAC3C,QAAA,MAAM,oBAAoB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AACzD,QAAA,MAAM,eAAe,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAEjD,IAAI,eAAe,GAAG,CAAC,CAAC;AAExB,QAAA,KAAK,CAAC,CAAC,UAAU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