{"version":3,"file":"ajf-core-geolocation.mjs","sources":["../../../projects/core/geolocation/src/geolocation-model.ts","../../../projects/core/geolocation/src/geolocation.ts","../../../projects/core/geolocation/src/public_api.ts","../../../projects/core/geolocation/src/ajf-core-geolocation.ts"],"sourcesContent":["/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nimport {EventEmitter, isDevMode} from '@angular/core';\nimport {Observable} from 'rxjs';\n\nexport class AjfGeolocationModel {\n  private _changed: EventEmitter<string> = new EventEmitter<string>();\n  readonly changed: Observable<string> = this._changed as Observable<string>;\n\n  private _latitude = '';\n  private _longitude = '';\n\n  get longitude() {\n    return this._longitude;\n  }\n  set longitude(value: string) {\n    if (value) {\n      this._longitude = value.toString().replace(',', '.');\n      this._changed.emit(this.toString());\n    }\n  }\n\n  get latitude() {\n    return this._latitude;\n  }\n  set latitude(value: string) {\n    if (value) {\n      this._latitude = value.toString().replace(',', '.');\n      this._changed.emit(this.toString());\n    }\n  }\n\n  toString() {\n    return `${this.latitude},${this.longitude}`;\n  }\n\n  fromString(value: string) {\n    try {\n      let splitted = value.toString().split(',');\n      if (splitted.length == 2) {\n        this.latitude = splitted[0];\n        this.longitude = splitted[1];\n      }\n    } catch (e) {\n      if (isDevMode()) {\n        console.log(e);\n      }\n    }\n  }\n}\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nimport {ChangeDetectorRef, Directive, Input, OnDestroy} from '@angular/core';\nimport {ControlValueAccessor} from '@angular/forms';\nimport {Subscription} from 'rxjs';\n\nimport {AjfGeolocationModel} from './geolocation-model';\n\n@Directive()\nexport abstract class AjfGeolocation implements ControlValueAccessor, OnDestroy {\n  @Input() readonly: boolean = false;\n\n  get geolocation(): AjfGeolocationModel {\n    return this._value;\n  }\n\n  private _value: AjfGeolocationModel = new AjfGeolocationModel();\n  get value(): string {\n    return this._value.toString();\n  }\n\n  set value(value: string) {\n    if (value !== this._value.toString()) {\n      this._value.fromString(value);\n      this._onChangeCallback(value);\n    }\n  }\n\n  get latitude(): string {\n    return this._value.latitude;\n  }\n  set latitude(latitude: string) {\n    this._value.latitude = latitude;\n    this._cdr.detectChanges();\n    this._onChangeCallback(this._value.toString());\n  }\n\n  get longitude(): string {\n    return this._value.longitude;\n  }\n  set longitude(longitude: string) {\n    this._value.longitude = longitude;\n    this._cdr.detectChanges();\n    this._onChangeCallback(this._value.toString());\n  }\n\n  private _onChangeCallback: (_: any) => void = (_: any) => {};\n  private _onTouchedCallback: () => void = () => {};\n  private _valueChangeSub: Subscription = Subscription.EMPTY;\n\n  constructor(protected _cdr: ChangeDetectorRef) {\n    this._valueChangeSub = this._value.changed.subscribe((x: string) => {\n      this._onChangeCallback(x);\n    });\n  }\n\n  getLocation(): void {\n    if (navigator.geolocation) {\n      navigator.geolocation.getCurrentPosition(\n        (position: any) => {\n          if (position) {\n            this.latitude = position.coords.latitude;\n            this.longitude = position.coords.longitude;\n          }\n        },\n        error => console.log(error),\n      );\n    } else {\n      console.log('Geolocation is not supported by this device or browser.');\n    }\n  }\n\n  ngOnDestroy(): void {\n    this._valueChangeSub.unsubscribe();\n  }\n\n  writeValue(value: string) {\n    this._value.fromString(value);\n  }\n\n  registerOnChange(fn: (value: any) => void) {\n    this._onChangeCallback = fn;\n  }\n\n  registerOnTouched(fn: any) {\n    this._onTouchedCallback = fn;\n  }\n\n  focusHandler(): void {\n    this._onTouchedCallback();\n  }\n}\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nexport * from './geolocation';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;AAoBG;MAKU,mBAAmB,CAAA;AAAhC,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,QAAQ,GAAyB,IAAI,YAAY,EAAU;AAC1D,QAAA,IAAA,CAAA,OAAO,GAAuB,IAAI,CAAC,QAA8B;QAElE,IAAS,CAAA,SAAA,GAAG,EAAE;QACd,IAAU,CAAA,UAAA,GAAG,EAAE;;AAEvB,IAAA,IAAI,SAAS,GAAA;QACX,OAAO,IAAI,CAAC,UAAU;;IAExB,IAAI,SAAS,CAAC,KAAa,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