@@ -16,6 +16,23 @@ import OrsApiClient from 'openrouteservice-js'
16
16
// and uncomment the import line below to use a local and unpacked openrouteservice-js lib
17
17
// import OrsApiClient from '@/ors-js/src'
18
18
19
+ function getCustomEndpointSettings ( apiBaseUrl , endpoint ) {
20
+ let host
21
+ let service
22
+ if ( ! endpoint . startsWith ( 'http' ) ) {
23
+ return [ apiBaseUrl , endpoint ]
24
+ } else {
25
+ let parts = endpoint . split ( '/' )
26
+ if ( parts . includes ( 'ors' ) ) {
27
+ host = parts . slice ( 0 , 4 ) . join ( '/' )
28
+ } else {
29
+ host = parts . slice ( 0 , 3 ) . join ( '/' )
30
+ }
31
+ service = '/' + parts . slice ( - 1 )
32
+ return [ host , service ]
33
+ }
34
+ }
35
+
19
36
/**
20
37
* Get the Directions function accessor
21
38
* @param {Array } places
@@ -25,11 +42,12 @@ import OrsApiClient from 'openrouteservice-js'
25
42
const Directions = ( places , customArgs = null ) => {
26
43
const mapSettings = store . getters . mapSettings
27
44
45
+ const [ host , service ] = getCustomEndpointSettings ( mapSettings . apiBaseUrl , mapSettings . endpoints . directions )
28
46
// Build the ors client object
29
47
const directions = new OrsApiClient . Directions ( {
30
48
api_key : mapSettings . apiKey ,
31
- host : mapSettings . apiBaseUrl ,
32
- service : mapSettings . endpoints . directions ,
49
+ host : host ,
50
+ service : service ,
33
51
timeout : constants . orsApiRequestTimeout
34
52
} )
35
53
@@ -63,10 +81,11 @@ const Directions = (places, customArgs = null) => {
63
81
*/
64
82
const Geocode = ( term , size = 10 ) => {
65
83
const mapSettings = store . getters . mapSettings
84
+ const [ host , service ] = getCustomEndpointSettings ( mapSettings . apiBaseUrl , mapSettings . endpoints . geocodeSearch )
66
85
const client = new OrsApiClient . Geocode ( {
67
86
api_key : mapSettings . apiKey ,
68
- host : mapSettings . apiBaseUrl ,
69
- service : mapSettings . endpoints . geocodeSearch
87
+ host : host ,
88
+ service : service
70
89
} )
71
90
const args = OrsParamsParser . buildPlaceSearchArgs ( term )
72
91
args . size = size
@@ -91,11 +110,12 @@ const Geocode = (term, size = 10) => {
91
110
*/
92
111
const ReverseGeocode = ( lat , lng , size = 10 ) => {
93
112
const mapSettings = store . getters . mapSettings
113
+ const [ host , service ] = getCustomEndpointSettings ( mapSettings . apiBaseUrl , mapSettings . endpoints . reverseGeocode )
94
114
95
115
const client = new OrsApiClient . Geocode ( {
96
116
api_key : mapSettings . apiKey ,
97
- host : mapSettings . apiBaseUrl ,
98
- service : mapSettings . endpoints . reverseGeocode
117
+ host : host ,
118
+ service : service
99
119
} )
100
120
const args = OrsParamsParser . buildReverseSearchArgs ( lat , lng )
101
121
args . size = size
@@ -124,11 +144,12 @@ const ReverseGeocode = (lat, lng, size = 10) => {
124
144
const PlacesSearch = ( term , quantity = 100 , restrictArea = true ) => {
125
145
return new Promise ( ( resolve , reject ) => {
126
146
const mapSettings = store . getters . mapSettings
147
+ const [ host , service ] = getCustomEndpointSettings ( mapSettings . apiBaseUrl , mapSettings . endpoints . geocodeSearch )
127
148
128
149
const client = new OrsApiClient . Geocode ( {
129
150
api_key : mapSettings . apiKey ,
130
- host : mapSettings . apiBaseUrl ,
131
- service : mapSettings . endpoints . geocodeSearch
151
+ host : host ,
152
+ service : service
132
153
} )
133
154
134
155
let promises = [ ]
@@ -293,11 +314,12 @@ const sortFeatures = (features) => {
293
314
*/
294
315
const Pois = ( filters , limit = 100 , distanceBuffer = 500 ) => {
295
316
const mapSettings = store . getters . mapSettings
317
+ const [ host , service ] = getCustomEndpointSettings ( mapSettings . apiBaseUrl , mapSettings . endpoints . pois )
296
318
297
319
const pois = new OrsApiClient . Pois ( {
298
320
api_key : mapSettings . apiKey ,
299
- host : mapSettings . apiBaseUrl ,
300
- service : mapSettings . endpoints . pois
321
+ host : host ,
322
+ service : service
301
323
} )
302
324
303
325
return new Promise ( ( resolve , reject ) => {
@@ -319,11 +341,12 @@ const Pois = (filters, limit = 100, distanceBuffer = 500) => {
319
341
*/
320
342
const Isochrones = ( places ) => {
321
343
const mapSettings = store . getters . mapSettings
344
+ const [ host , service ] = getCustomEndpointSettings ( mapSettings . apiBaseUrl , mapSettings . endpoints . isochrones )
322
345
323
346
const isochrones = new OrsApiClient . Isochrones ( {
324
347
api_key : mapSettings . apiKey ,
325
- host : mapSettings . apiBaseUrl ,
326
- service : mapSettings . endpoints . isochrones ,
348
+ host : host ,
349
+ service : service ,
327
350
timeout : constants . orsApiRequestTimeout
328
351
} )
329
352
return new Promise ( ( resolve , reject ) => {
0 commit comments