-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathindex.html
More file actions
156 lines (142 loc) · 6.3 KB
/
index.html
File metadata and controls
156 lines (142 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Open Source Routing Machine DEMO</title>
<meta name='viewport' content='initial-scale=1.0 maximum-scale=1.0'>
<link rel="shortcut icon" href="favicon.ico" />
<link rel='stylesheet' href="css/leaflet.css" />
<link rel="stylesheet" href="css/fonts.css" />
<link href='css/site.css' rel='stylesheet' />
<meta name="osrm-environment" content="">
</head>
<body>
<div id='map' class='map'></div>
<script>
// Load runtime configuration (generated by Docker entrypoint from OSRM_* env vars)
// Falls back to bundled defaults if config.json is not available
// OSRM_ENVIRONMENT indicates execution context: 'docker' or undefined (local dev)
window.osrmConfig = {
// OSRM_ENVIRONMENT only set to 'docker' if explicitly running in Docker
// In all other cases (dev, browser), leave it undefined to use public services
OSRM_CENTER: '38.8995,-77.0269',
OSRM_ZOOM: 13,
OSRM_DEFAULT_LAYER: 'streets'
// OSRM_BACKEND and OSRM_MODES will be set by config.json if available
};
(function() {
function loadBundle() {
var script = document.createElement('script');
script.src = 'bundle.js';
document.body.appendChild(script);
}
function loadConfig() {
return new Promise(function(resolve) {
fetch('config.json')
.then(function(response) {
if (!response.ok) {
if (response.status === 404) {
console.warn('config.json not found, using defaults');
} else {
console.warn('Failed to load config.json (HTTP ' + response.status + '), using defaults');
}
resolve();
return;
}
return response.json()
.then(function(config) {
window.osrmConfig = config;
resolve();
});
})
.catch(function(error) {
console.warn('Failed to load config.json due to a network error, using defaults:', error);
resolve();
});
});
}
var envMeta = document.querySelector('meta[name="osrm-environment"]');
if (envMeta && envMeta.content === 'docker') {
loadConfig().then(loadBundle);
} else {
// Not running in Docker — skip fetching config.json to avoid noisy 404s
loadBundle();
}
})();
</script>
<script>
(function(){
function createOverlay(){
if (document.getElementById('osrm-error-overlay')) return;
var o = document.createElement('div');
o.id = 'osrm-error-overlay';
o.style.position = 'fixed';
o.style.top = '0'; o.style.left = '0'; o.style.right = '0'; o.style.bottom = '0';
o.style.background = 'rgba(0,0,0,0.75)';
o.style.color = '#fff';
o.style.zIndex = 100000;
o.style.display = 'flex';
o.style.alignItems = 'center';
o.style.justifyContent = 'center';
o.style.padding = '20px';
o.style.fontFamily = 'sans-serif';
var box = document.createElement('div');
box.style.maxWidth = '800px';
box.style.textAlign = 'left';
var h = document.createElement('h1');
h.textContent = 'Something went wrong';
h.style.margin = '0 0 8px 0';
h.style.fontSize = '18px';
var p = document.createElement('p');
p.style.margin = '0 0 12px 0';
p.textContent = 'The application failed to start or encountered an error. Try enabling cookies/storage and reload the page.';
var btnReload = document.createElement('button');
btnReload.textContent = 'Reload';
btnReload.style.marginRight = '8px';
btnReload.onclick = function(){ window.location.reload(); };
var btnCopy = document.createElement('button');
btnCopy.textContent = 'Copy error details';
btnCopy.onclick = function(){ try{ navigator.clipboard.writeText(window.__osrm_last_error || ''); }catch(e){} };
var pre = document.createElement('pre');
pre.style.whiteSpace = 'pre-wrap';
pre.style.maxHeight = '40vh';
pre.style.overflow = 'auto';
pre.style.marginTop = '12px';
pre.textContent = window.__osrm_last_error || '';
box.appendChild(h);
box.appendChild(p);
box.appendChild(btnReload);
box.appendChild(btnCopy);
box.appendChild(pre);
o.appendChild(box);
document.body.appendChild(o);
window.__osrm_error_overlay_pre = pre;
}
function handleError(evt){
try{
var msg = '';
if (evt && evt.message) msg = evt.message;
else if (evt && evt.reason && evt.reason.message) msg = evt.reason.message;
else if (evt && evt.error && evt.error.message) msg = evt.error.message;
else msg = String(evt);
var details = [];
try{ if (evt && evt.filename) details.push('file: ' + evt.filename); if (evt && evt.lineno) details.push('line: ' + evt.lineno); }catch(e){}
window.__osrm_last_error = (msg + (details.length ? ' (' + details.join(', ') + ')' : '') + (evt && evt.error && evt.error.stack ? '\n' + evt.error.stack : (evt && evt.stack ? '\n' + evt.stack : '')));
console.error('OSRM frontend runtime error', evt);
createOverlay();
if (window.__osrm_error_overlay_pre) window.__osrm_error_overlay_pre.textContent = window.__osrm_last_error;
}catch(e){}
}
window.addEventListener('error', function(e){ handleError(e); });
window.addEventListener('unhandledrejection', function(e){ handleError(e); });
setTimeout(function(){
if (!window.__osrm_app_loaded) {
window.__osrm_last_error = window.__osrm_last_error || 'Application did not finish startup within 5 seconds.';
createOverlay();
if (window.__osrm_error_overlay_pre) window.__osrm_error_overlay_pre.textContent = window.__osrm_last_error;
}
}, 5000);
})();
</script>
</body>
</html>