File : routeProviders/BaseRouteProvider.js

1
/*
2
Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/
3
4
This  program is free software;
5
you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation;
7
either version 3 of the License, or any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
*/
18
/*
19
Changes:
20
    - v4.0.0:
21
        - created from v3.6.0
22
Doc reviewed 202208
23
 */
24
25
/* ------------------------------------------------------------------------------------------------------------------------- */
26
/**
27
Base class used for RouteProviders
28
*/
29
/* ------------------------------------------------------------------------------------------------------------------------- */
30
31
class BaseRouteProvider {
32
33
    /**
34
    The user language
35
    @type {String}
36
    */
37
38
    #userLanguage;
39
40
    /**
41
    A reference to the edited route
42
    @type {Route}
43
    */
44
45
    // eslint-disable-next-line no-unused-private-class-members
46
    #route;
47
48
    /**
49
    Call the provider, using the waypoints defined in the route and, on success,
50
    complete the route with the data from the provider
51
    @param {function} onOk the Promise Success handler
52
    @param {function} onError the Promise Error handler
53
54
    */
55
56
    // eslint-disable-next-line no-unused-vars
57
    #getRoute ( onOk, onError ) {
58
59
        // to be implemented in the derived classes
60
    }
61
62
    /**
63
    constructor
64
    */
65
66
    constructor ( ) {
67
        Object.freeze ( this );
68
        this.#userLanguage = 'fr';
69
    }
70
71
    /**
72
    Call the provider, using the waypoints defined in the route and, on success,
73
    complete the route with the data from the provider
74
    @param {Route} route The route to witch the data will be added
75
    @return {Promise} A Promise. On success, the Route is completed with the data given by the provider.
76
    */
77
78
    getPromiseRoute ( route ) {
79
        this.#route = route;
80
        return new Promise ( ( onOk, onError ) => this.#getRoute ( onOk, onError ) );
81
    }
82
83
    /**
84
    The icon used in the ProviderToolbarUI.
85
    Must be overloaded in the derived classes
86
    @type {String}
87
    */
88
89
    get icon ( ) {
90
        return '' +
91
            'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjw' +
92
            'v8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAArSURBVEhL7cyxDQAgAAQh91/67ektTI4BOHumGtWoRjWqUY1qVKMaP9bbBZKXgg' +
93
            'u6NeCUAAAAAElFTkSuQmCC';
94
    }
95
96
    /**
97
    The provider name.
98
    Must be overloaded in the derived classes
99
    @type {String}
100
    */
101
102
    get name ( ) { return ''; }
103
104
    /**
105
    The title to display in the ProviderToolbarUI button.
106
    Must be overloaded in the derived classes
107
    @type {String}
108
    */
109
110
    get title ( ) { return ''; }
111
112
    /**
113
    The possible transit modes for the provider.
114
    Must be overloaded in the derived classes.
115
    Must be a subarray of [ 'bike', 'pedestrian', 'car', 'train', 'line', 'circle' ]
116
    @type {Array.<String>}
117
    */
118
119
    get transitModes ( ) { return [ ]; }
120
121
    /**
122
    A boolean indicating when a provider key is needed for the provider.
123
    Must be overloaded in the derived classes
124
    @type {Boolean}
125
    */
126
127
    get providerKeyNeeded ( ) { return true; }
128
129
    /**
130
    The user language.
131
    @type {String}
132
    */
133
134
    get userLanguage ( ) { return this.#userLanguage; }
135
    set userLanguage ( userLanguage ) {
136
        this.#userLanguage = userLanguage;
137
    }
138
}
139
140
export default BaseRouteProvider;
141
142
/* --- End of file --------------------------------------------------------------------------------------------------------- */
143