Skip to content

Commit 76d553a

Browse files
authored
add osmApiUrl param for custom osm servers (#77)
1 parent 7aede7f commit 76d553a

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/apis.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
let apis = {
1+
const osmApiUrl = new URLSearchParams(location.search).get('osmApiUrl') || 'https://api.openstreetmap.org/api/0.6';
2+
const apis = {
23
bounding: {
3-
api:'https://api.openstreetmap.org/api/0.6/map?bbox=',
4+
api: osmApiUrl + '/map?bbox=',
45
url: (left, bottom, right, top) => {
56
return apis.bounding.api + left + ',' + bottom + ',' + right + ',' + top;
67
},
78
},
89
getRelation: {
9-
api:'https://api.openstreetmap.org/api/0.6/relation/',
10-
parameters:'/full',
10+
api: osmApiUrl + '/relation/',
11+
parameters: '/full',
1112
url: (relationId) => {
1213
return apis.getRelation.api + relationId + apis.getRelation.parameters;
1314
},
1415
},
1516
getWay: {
16-
api:'https://api.openstreetmap.org/api/0.6/way/',
17-
parameters:'/full',
17+
api: osmApiUrl + '/way/',
18+
parameters: '/full',
1819
url: (wayId) => {
1920
return apis.getWay.api + wayId + apis.getWay.parameters;
2021
},

src/index.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,18 @@ function init() {
4040

4141
window.printError = printError;
4242

43-
if (window.location.search.substr(1) !== null) {
44-
window.location.search.substr(1).split('&')
45-
.forEach(function(item) {
46-
const tmp = item.split('=');
47-
if (tmp[0] === 'type') {
48-
type = decodeURIComponent(tmp[1]);
49-
} else if (tmp[0] === 'id') {
50-
id = decodeURIComponent(tmp[1]);
51-
} else if (tmp[0] === 'info') {
52-
displayInfo = true;
53-
} else if (tmp[0] === 'errorBox') {
54-
errorBox = true;
55-
}
56-
});
43+
const params = new URLSearchParams(window.location.search);
44+
if (params.has('type')) {
45+
type = params.get('type');
46+
}
47+
if (params.has('id')) {
48+
id = params.get('id');
49+
}
50+
if (params.has('info')) {
51+
displayInfo = true;
52+
}
53+
if (params.has('errorBox')) {
54+
errorBox = true;
5755
}
5856
Building.create(type, id).then(function(myObj){
5957
mainBuilding = myObj;

0 commit comments

Comments
 (0)