This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathOptions.js
80 lines (64 loc) · 1.42 KB
/
Options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {formatResultSupplier, formatType} from './formatter';
export default class Options {
/**
* URL of the Photon API to use
* @type {string}
*/
url = 'https://photon.komoot.io';
/**
* Limit number of results
* @type {number}
*/
limit = 5;
/**
* Function to control the way features types (amenity, school, etc.) are displayed in the default
* formatResult function
* @type {Function}
*/
formatType = null;
/**
* Function to control the way geojson features are displayed in the results box
* @type {Function}
*/
formatResult = null;
/**
* Latitude to make search with priority to a geo position
* @type {number}
*/
lat = null;
/**
* Longitude to make search with priority to a geo position
* @type {number}
*/
lon = null;
/**
* Preferred language
* @type {string}
*/
lang = null;
constructor(options) {
options && Object.assign(this, options);
}
get api() {
return this.url + '/api/';
}
get reverse() {
return this.url + '/reverse';
}
get formatResultFunc() {
return this.formatResult || formatResultSupplier(this.formatType || formatType);
}
get reqParams() {
let reqParams = {
limit: this.limit
};
if (this.lat && this.lon) {
reqParams.lat = this.lat;
reqParams.lon = this.lon;
}
if (this.lang) {
reqParams.lang = this.lang;
}
return reqParams;
}
}