forked from openstreetmap/iD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
79 lines (71 loc) · 2.66 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>iD</title>
<link rel='stylesheet' href='dist/iD.css'/>
<meta name='viewport' content='initial-scale=1.0 maximum-scale=1.0'/>
<meta name='apple-mobile-web-app-capable' content='yes'/>
<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent'/>
<script src='dist/iD.js'></script>
</head>
<body>
<div id='id-container'></div>
<script>
function start(opts) {
// Switch service.
iD.services.osm = iD.services.osmRRA;
id = iD.Context();
id.assetPath('dist/').notifier(opts.notifier);
// Set vars.
id.connection()
.apiUrl('http://localhost:4000')
.projectId(opts.projectId)
.scenarioId(opts.scenarioId);
id.ui()(document.getElementById('id-container'));
return id;
}
function notifier (id, element) {
var events = {};
var _notifier = {
on: function (type, cb) {
if (!events[type]) events[type] = [];
events[type].push(cb);
return _notifier;
},
send: function (type, data) {
data = data || {};
data.id = id;
data.type = type;
element.postMessage(data, '*');
return _notifier;
}
};
window.addEventListener('message', e => {
if (!e.data.type) return;
var cbs = events[e.data.type] || [];
cbs.forEach(function (cb) { cb(e.data); });
});
return _notifier;
}
if (window === window.parent) {
alert('Not inside an iframe. Prompt for ids');
var projId = parseInt(prompt('Insert project id'), 10);
var scId = parseInt(prompt('Insert scenario id'), 10);
start({projectId: projId, scenarioId: scId});
} else {
var n = notifier('rra-editor', window.parent)
.send('loaded')
.on('settings', function (data) {
var id = start({projectId: data.projectId, scenarioId: data.scenarioId, notifier: n});
// Center map on the appropriate place.
id.map().extent([
[ data.bbox[0], data.bbox[1] ],
[ data.bbox[2], data.bbox[3] ]
]);
n.send('ready');
});
}
</script>
</body>
</html>