Skip to content

Commit

Permalink
update error check
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Sakanoshita committed Jul 11, 2024
1 parent d234604 commit 717fa71
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@

* 2024/07/09
* * 初版公開。OSMのデータはリアルタイム取得とする(後でスタティック化予定)

* 2024/07/11
* * overpass.openstreetmap.jp のメンテナンスに合わせてエラー処理を追加
*
2 changes: 1 addition & 1 deletion data/config-system.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
},
"system": {
"OverPassServer": [
"https://maps.mail.ru/osm/tools/overpass/api/interpreter",
"https://overpass.openstreetmap.jp/api/interpreter",
"https://maps.mail.ru/osm/tools/overpass/api/interpreter",
"https://overpass.kumi.systems/api/interpreter",
"https://overpass-api.de/api/interpreter"
]
Expand Down
4 changes: 3 additions & 1 deletion initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ window.addEventListener("DOMContentLoaded", function () {
let osmids = poiCont.pois().acts.map(act => { return act.osmid })
osmids = osmids.filter(Boolean)
if (osmids.length > 0 && !Conf.static.mode) {
OvPassCnt.getOsmIds(osmids).then(geojson => {
basic.retry(() => OvPassCnt.getOsmIds(osmids),5).then(geojson => {
poiCont.add_geojson(geojson)
poiCont.setActlnglat()
init_close()
}).catch(() => {
console.log("???")
})
} else {
poiCont.setActlnglat()
Expand Down
8 changes: 8 additions & 0 deletions lib/basiclib.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ class Basic {
return Array.from(elems.keys()).filter(Boolean);
}

retry(func, retryCount) { // Promise失敗時にリトライする
let promise = func();
for (let i = 1; i <= retryCount; ++i) {
promise = promise.catch(func);
}
return promise;
}

getWikipedia(lang, url) { // get wikipedia contents
return new Promise((resolve, reject) => {
let encurl = encodeURI(url);
Expand Down
4 changes: 2 additions & 2 deletions lib/overpasslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class OverPassControl {
Object.keys(pois).forEach(category => {
if (pois[category] !== "") params += `${category}(id:${pois[category].slice(0, -1)});`;
});
let url = Conf.system.OverPassServer[OvPassCnt.UseServer] + '?data=[out:json][timeout:30];' + params + ');out body meta;>;out skel;';
let url = Conf.system.OverPassServer[OvPassCnt.UseServer] + '?data=[out:json][timeout:20];' + params + ');out body meta;>;out skel;';
console.log("OvPassCnt: GET: " + url);
$.ajax({ "type": 'GET', "dataType": 'json', "url": url, "cache": false }).done(function (osmxml) {
$.ajax({ "type": 'GET', "dataType": 'json', "url": url, "cache": false, timeout: 20000 }).done(function (osmxml) {
console.log("OvPassCnt: getOsmIds: done.");
if (osmxml.elements.length == 0) { resolve(); return };
let geojson = osmtogeojson(osmxml, { flatProperties: true });
Expand Down

0 comments on commit 717fa71

Please sign in to comment.