diff --git a/src/apis.js b/src/apis.js index a4e5d0a..dc54ff1 100644 --- a/src/apis.js +++ b/src/apis.js @@ -1,20 +1,21 @@ -let apis = { +const osmApiUrl = new URLSearchParams(location.search).get('osmApiUrl') || 'https://api.openstreetmap.org/api/0.6'; +const apis = { bounding: { - api:'https://api.openstreetmap.org/api/0.6/map?bbox=', + api: osmApiUrl + '/map?bbox=', url: (left, bottom, right, top) => { return apis.bounding.api + left + ',' + bottom + ',' + right + ',' + top; }, }, getRelation: { - api:'https://api.openstreetmap.org/api/0.6/relation/', - parameters:'/full', + api: osmApiUrl + '/relation/', + parameters: '/full', url: (relationId) => { return apis.getRelation.api + relationId + apis.getRelation.parameters; }, }, getWay: { - api:'https://api.openstreetmap.org/api/0.6/way/', - parameters:'/full', + api: osmApiUrl + '/way/', + parameters: '/full', url: (wayId) => { return apis.getWay.api + wayId + apis.getWay.parameters; }, diff --git a/src/index.js b/src/index.js index 633aa49..8d68b2b 100644 --- a/src/index.js +++ b/src/index.js @@ -40,20 +40,18 @@ function init() { window.printError = printError; - if (window.location.search.substr(1) !== null) { - window.location.search.substr(1).split('&') - .forEach(function(item) { - const tmp = item.split('='); - if (tmp[0] === 'type') { - type = decodeURIComponent(tmp[1]); - } else if (tmp[0] === 'id') { - id = decodeURIComponent(tmp[1]); - } else if (tmp[0] === 'info') { - displayInfo = true; - } else if (tmp[0] === 'errorBox') { - errorBox = true; - } - }); + const params = new URLSearchParams(window.location.search); + if (params.has('type')) { + type = params.get('type'); + } + if (params.has('id')) { + id = params.get('id'); + } + if (params.has('info')) { + displayInfo = true; + } + if (params.has('errorBox')) { + errorBox = true; } Building.create(type, id).then(function(myObj){ mainBuilding = myObj;