UNPKG

1.64 kBJavaScriptView Raw
1// import React from 'react';
2// import { render } from 'react-dom';
3
4import { render as changesetMap } from '../lib/render';
5
6// render(
7// <div>
8// <h1 />
9// </div>,
10// document.getElementById('root')
11// );
12
13var cMap;
14
15var containerWidth = window.innerWidth + 'px';
16var containerHeight = window.innerHeight + 'px';
17
18if (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
31document
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
45cMap.on('featureChange', function(geometryType, featureId) {
46 clearHash();
47 if (geometryType && featureId) {
48 updateHash(geometryType, featureId);
49 }
50});
51
52function updateHash(osmType, featureId) {
53 clearHash();
54
55 location.hash += '/' + osmType;
56 location.hash += '/' + featureId;
57}
58
59function clearHash() {
60 var changesetId = location.hash.split('/')[0].replace('#', '');
61
62 location.hash = changesetId;
63}