1 |
|
2 |
|
3 |
|
4 | import { render as changesetMap } from '../lib/render';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var cMap;
|
14 |
|
15 | var containerWidth = window.innerWidth + 'px';
|
16 | var containerHeight = window.innerHeight + 'px';
|
17 |
|
18 | if (location.hash !== '') {
|
19 | document.getElementById('formContainer').style.display = 'none';
|
20 | var id = location.hash.split('/')[0].replace('#', '');
|
21 | var [, geometryType, featureId] = location.hash.split('/');
|
22 | cMap = changesetMap(document.getElementById('container'), id, {
|
23 | width: containerWidth,
|
24 | height: containerHeight
|
25 | });
|
26 | cMap.on('load', function() {
|
27 | cMap.emit('selectFeature', geometryType, featureId);
|
28 | });
|
29 | }
|
30 |
|
31 | document
|
32 | .getElementById('changesetForm')
|
33 | .addEventListener('submit', function(e) {
|
34 | e.preventDefault();
|
35 | document.getElementById('formContainer').style.display = 'none';
|
36 | var changesetID = document.getElementById('changesetInput').value;
|
37 | location.hash = changesetID;
|
38 | cMap = changesetMap(document.getElementById('container'), changesetID, {
|
39 | hash: location.hash,
|
40 | width: containerWidth,
|
41 | height: containerHeight
|
42 | });
|
43 | });
|
44 |
|
45 | cMap.on('featureChange', function(geometryType, featureId) {
|
46 | clearHash();
|
47 | if (geometryType && featureId) {
|
48 | updateHash(geometryType, featureId);
|
49 | }
|
50 | });
|
51 |
|
52 | function updateHash(osmType, featureId) {
|
53 | clearHash();
|
54 |
|
55 | location.hash += '/' + osmType;
|
56 | location.hash += '/' + featureId;
|
57 | }
|
58 |
|
59 | function clearHash() {
|
60 | var changesetId = location.hash.split('/')[0].replace('#', '');
|
61 |
|
62 | location.hash = changesetId;
|
63 | }
|