@geoapify/angular-geocoder-autocomplete
Version:
Angular component for the Geoapify Geocoder Autocomplete library
327 lines (320 loc) • 15.2 kB
JavaScript
import * as i0 from '@angular/core';
import { InjectionToken, EventEmitter, Output, Input, ViewChild, Inject, Component, NgModule } from '@angular/core';
import { GeocoderAutocomplete } from '@geoapify/geocoder-autocomplete';
const GEOAPIFY_CONFIG = new InjectionToken('geoapify.config');
class GeocoderAutocompleteComponent {
constructor(config) {
this.config = config;
this.placeSelect = new EventEmitter();
this.suggestionsChange = new EventEmitter();
this.userInput = new EventEmitter();
this.open = new EventEmitter();
this.close = new EventEmitter();
this.requestStart = new EventEmitter();
this.requestEnd = new EventEmitter();
}
ngOnInit() {
}
ngAfterViewInit() {
const options = {};
if (this.placeholder) {
options.placeholder = this.placeholder;
}
if (this.type) {
options.type = this.type;
}
if (this.lang) {
options.lang = this.lang;
}
if (this.limit) {
options.limit = this.limit;
}
if (this.debounceDelay) {
options.debounceDelay = this.debounceDelay;
}
if (this.skipIcons) {
options.skipIcons = this.skipIcons;
}
if (this.addDetails) {
options.addDetails = this.addDetails;
}
if (this.allowNonVerifiedHouseNumber !== undefined) {
options.allowNonVerifiedHouseNumber = this.allowNonVerifiedHouseNumber;
}
if (this.allowNonVerifiedStreet !== undefined) {
options.allowNonVerifiedStreet = this.allowNonVerifiedStreet;
}
if (this.skipSelectionOnArrowKey !== undefined) {
options.skipSelectionOnArrowKey = this.skipSelectionOnArrowKey;
}
this.autocomplete = new GeocoderAutocomplete(this.container.nativeElement, this.config.apiKey, options);
if (this.value) {
this.autocomplete.setValue(this.value);
}
if (this.countryCodes) {
console.warn("WARNING! Obsolete function called. The 'countryCodes' input has been deprecated, please use the new 'filterByCountryCode' input instead!");
this.autocomplete.addFilterByCountry(this.countryCodes);
}
if (this.position) {
console.warn("WARNING! Obsolete function called. The 'position' input has been deprecated, please use the new 'biasByLocation' input instead!");
this.autocomplete.addBiasByProximity(this.position);
}
if (this.filterByCircle) {
this.autocomplete.addFilterByCircle(this.filterByCircle);
}
if (this.filterByCountryCode) {
this.autocomplete.addFilterByCountry(this.filterByCountryCode);
}
if (this.filterByRect) {
this.autocomplete.addFilterByRect(this.filterByRect);
}
if (this.biasByCircle) {
this.autocomplete.addBiasByCircle(this.biasByCircle);
}
if (this.biasByRect) {
this.autocomplete.addBiasByRect(this.biasByRect);
}
if (this.biasByProximity) {
this.autocomplete.addBiasByProximity(this.biasByProximity);
}
if (this.biasByCountryCode) {
this.autocomplete.addBiasByCountry(this.biasByCountryCode);
}
if (this.preprocessingHook) {
this.autocomplete.setPreprocessHook(this.preprocessingHook);
}
if (this.postprocessingHook) {
this.autocomplete.setPostprocessHook(this.postprocessingHook);
}
if (this.suggestionsFilter) {
this.autocomplete.setSuggestionsFilter(this.suggestionsFilter);
}
if (this.sendGeocoderRequestFunc) {
this.autocomplete.setSendGeocoderRequestFunc(this.sendGeocoderRequestFunc);
}
if (this.sendPlaceDetailsRequestFunc) {
this.autocomplete.setSendPlaceDetailsRequestFunc(this.sendPlaceDetailsRequestFunc);
}
this.autocomplete.on('select', this.onSelect.bind(this));
this.autocomplete.on('suggestions', this.onSuggestions.bind(this));
this.autocomplete.on('input', this.onInput.bind(this));
this.autocomplete.on('open', this.onOpen.bind(this));
this.autocomplete.on('close', this.onClose.bind(this));
this.autocomplete.on('request_start', this.onRequestStart.bind(this));
this.autocomplete.on('request_end', this.onRequestEnd.bind(this));
}
onSelect(value) {
this.placeSelect.emit(value);
}
onSuggestions(value) {
this.suggestionsChange.emit(value);
}
onInput(value) {
this.userInput.emit(value);
}
onOpen(opened) {
this.open.emit(opened);
}
onClose(opened) {
this.close.emit(opened);
}
onRequestStart(value) {
this.requestStart.emit(value);
}
onRequestEnd(value) {
this.requestEnd.emit(value);
}
ngOnChanges(changes) {
if (!this.autocomplete) {
return;
}
if (changes['value'] &&
!changes['value'].isFirstChange()) {
this.autocomplete.setValue(changes['value'].currentValue);
}
if (changes['type'] &&
!changes['type'].isFirstChange()) {
this.autocomplete.setType(changes['type'].currentValue);
}
if (changes['lang'] &&
!changes['lang'].isFirstChange()) {
this.autocomplete.setLang(changes['lang'].currentValue);
}
if (changes['filterByCircle'] &&
!changes['filterByCircle'].isFirstChange()) {
this.autocomplete.addFilterByCircle(changes['filterByCircle'].currentValue);
}
if (changes['filterByCountryCode'] &&
!changes['filterByCountryCode'].isFirstChange()) {
this.autocomplete.addFilterByCountry(changes['filterByCountryCode'].currentValue);
}
if (changes['filterByRect'] &&
!changes['filterByRect'].isFirstChange()) {
this.autocomplete.addFilterByRect(changes['filterByRect'].currentValue);
}
if (changes['biasByCircle'] &&
!changes['biasByCircle'].isFirstChange()) {
this.autocomplete.addBiasByCircle(changes['biasByCircle'].currentValue);
}
if (changes['biasByRect'] &&
!changes['biasByRect'].isFirstChange()) {
this.autocomplete.addBiasByRect(changes['biasByRect'].currentValue);
}
if (changes['biasByProximity'] &&
!changes['biasByProximity'].isFirstChange()) {
this.autocomplete.addBiasByProximity(changes['biasByProximity'].currentValue);
}
if (changes['biasByCountryCode'] &&
!changes['biasByCountryCode'].isFirstChange()) {
this.autocomplete.addBiasByCountry(changes['biasByCountryCode'].currentValue);
}
if (changes['countryCodes'] &&
!changes['countryCodes'].isFirstChange()) {
console.warn("WARNING! Obsolete function called. The 'countryCodes' input has been deprecated, please use the new 'filterByCountryCode' input instead!");
this.autocomplete.addFilterByCountry(changes['countryCodes'].currentValue);
}
if (changes['position'] &&
!changes['position'].isFirstChange()) {
console.warn("WARNING! Obsolete function called. The 'position' input has been deprecated, please use the new 'biasByLocation' input instead!");
this.autocomplete.addBiasByProximity(changes['position'].currentValue);
}
if (changes['limit'] &&
!changes['limit'].isFirstChange()) {
this.autocomplete.setLimit(changes['limit'].currentValue);
}
if (changes['preprocessingHook'] &&
!changes['preprocessingHook'].isFirstChange()) {
this.autocomplete.setPreprocessHook(changes['preprocessingHook'].currentValue);
}
if (changes['postprocessingHook'] &&
!changes['postprocessingHook'].isFirstChange()) {
this.autocomplete.setPostprocessHook(changes['postprocessingHook'].currentValue);
}
if (changes['suggestionsFilter'] &&
!changes['suggestionsFilter'].isFirstChange()) {
this.autocomplete.setSuggestionsFilter(changes['suggestionsFilter'].currentValue);
}
if (changes['allowNonVerifiedHouseNumber'] &&
!changes['allowNonVerifiedHouseNumber'].isFirstChange()) {
this.autocomplete.setAllowNonVerifiedHouseNumber(changes['allowNonVerifiedHouseNumber'].currentValue);
}
if (changes['allowNonVerifiedStreet'] &&
!changes['allowNonVerifiedStreet'].isFirstChange()) {
this.autocomplete.setAllowNonVerifiedStreet(changes['allowNonVerifiedStreet'].currentValue);
}
}
ngOnDestroy() {
this.autocomplete.off('select');
this.autocomplete.off('suggestions');
this.autocomplete.off('input');
this.autocomplete.off('open');
this.autocomplete.off('close');
this.autocomplete.off('request_start');
this.autocomplete.off('request_end');
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: GeocoderAutocompleteComponent, deps: [{ token: GEOAPIFY_CONFIG }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.7", type: GeocoderAutocompleteComponent, isStandalone: false, selector: "geoapify-geocoder-autocomplete", inputs: { value: "value", placeholder: "placeholder", type: "type", skipIcons: "skipIcons", addDetails: "addDetails", lang: "lang", filterByCountryCode: "filterByCountryCode", filterByCircle: "filterByCircle", filterByRect: "filterByRect", biasByCountryCode: "biasByCountryCode", biasByCircle: "biasByCircle", biasByRect: "biasByRect", biasByProximity: "biasByProximity", countryCodes: "countryCodes", position: "position", limit: "limit", debounceDelay: "debounceDelay", allowNonVerifiedHouseNumber: "allowNonVerifiedHouseNumber", allowNonVerifiedStreet: "allowNonVerifiedStreet", skipSelectionOnArrowKey: "skipSelectionOnArrowKey", preprocessingHook: "preprocessingHook", postprocessingHook: "postprocessingHook", suggestionsFilter: "suggestionsFilter", sendGeocoderRequestFunc: "sendGeocoderRequestFunc", sendPlaceDetailsRequestFunc: "sendPlaceDetailsRequestFunc" }, outputs: { placeSelect: "placeSelect", suggestionsChange: "suggestionsChange", userInput: "userInput", open: "open", close: "close", requestStart: "requestStart", requestEnd: "requestEnd" }, viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true }], usesOnChanges: true, ngImport: i0, template: '<div class="geocoder-container" #container></div>', isInline: true, styles: [".geocoder-container{position:relative}\n"] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: GeocoderAutocompleteComponent, decorators: [{
type: Component,
args: [{ selector: 'geoapify-geocoder-autocomplete', template: '<div class="geocoder-container" #container></div>', standalone: false, styles: [".geocoder-container{position:relative}\n"] }]
}], ctorParameters: () => [{ type: undefined, decorators: [{
type: Inject,
args: [GEOAPIFY_CONFIG]
}] }], propDecorators: { container: [{
type: ViewChild,
args: ['container']
}], value: [{
type: Input
}], placeholder: [{
type: Input
}], type: [{
type: Input
}], skipIcons: [{
type: Input
}], addDetails: [{
type: Input
}], lang: [{
type: Input
}], filterByCountryCode: [{
type: Input
}], filterByCircle: [{
type: Input
}], filterByRect: [{
type: Input
}], biasByCountryCode: [{
type: Input
}], biasByCircle: [{
type: Input
}], biasByRect: [{
type: Input
}], biasByProximity: [{
type: Input
}], countryCodes: [{
type: Input
}], position: [{
type: Input
}], limit: [{
type: Input
}], debounceDelay: [{
type: Input
}], allowNonVerifiedHouseNumber: [{
type: Input
}], allowNonVerifiedStreet: [{
type: Input
}], skipSelectionOnArrowKey: [{
type: Input
}], preprocessingHook: [{
type: Input
}], postprocessingHook: [{
type: Input
}], suggestionsFilter: [{
type: Input
}], sendGeocoderRequestFunc: [{
type: Input
}], sendPlaceDetailsRequestFunc: [{
type: Input
}], placeSelect: [{
type: Output
}], suggestionsChange: [{
type: Output
}], userInput: [{
type: Output
}], open: [{
type: Output
}], close: [{
type: Output
}], requestStart: [{
type: Output
}], requestEnd: [{
type: Output
}] } });
class GeoapifyGeocoderAutocompleteModule {
static withConfig(apiKey) {
return {
ngModule: GeoapifyGeocoderAutocompleteModule,
providers: [
{ provide: GEOAPIFY_CONFIG, useValue: { apiKey: apiKey } }
]
};
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: GeoapifyGeocoderAutocompleteModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.1.7", ngImport: i0, type: GeoapifyGeocoderAutocompleteModule, declarations: [GeocoderAutocompleteComponent], exports: [GeocoderAutocompleteComponent] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: GeoapifyGeocoderAutocompleteModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: GeoapifyGeocoderAutocompleteModule, decorators: [{
type: NgModule,
args: [{
declarations: [GeocoderAutocompleteComponent],
imports: [],
exports: [GeocoderAutocompleteComponent]
}]
}] });
/*
* Public API Surface of angular-geocoder-autocomplete
*/
/**
* Generated bundle index. Do not edit.
*/
export { GeoapifyGeocoderAutocompleteModule, GeocoderAutocompleteComponent };
//# sourceMappingURL=geoapify-angular-geocoder-autocomplete.mjs.map