forked from mkyral/POI-Importer.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
josmHelpers.js
101 lines (96 loc) · 2.28 KB
/
josmHelpers.js
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
var josmHelper = (function()
{
var josmUrl = "http://localhost:8111/";
var openOsmArea = function(area)
{
var url = josmUrl + "load_and_zoom" + area;
var req = new XMLHttpRequest();
req.onreadystatechange = function()
{
if (req.readyState != 4)
return;
else if (req.status != 200)
testJosmVersion();
}
req.open("GET", url, true);
try
{
req.send(null);
}
catch (e)
{
testJosmVersion();
}
};
var importPoint = function(datasetName, tileName, idx)
{
var settings = datasetSettings[datasetName];
var point = tiledData[datasetName][tileName].data[idx];
var timeStr = (new Date()).toISOString();
var url = josmUrl + "load_data?data=";
var xml = "<osm version='0.6' generator='POI_importer'>";
xml += "<node id='-1' "+
"lat='" + point.coordinates.lat + "' " +
"lon='" + point.coordinates.lon + "' " +
"version='0' "+
"timestamp='" + timeStr + "' " +
"uid='1' user=''>";
for (var t = 0; t < settings.tagmatch.length; t++)
{
var tag = settings.tagmatch[t];
if (!point.properties[tag.key])
continue;
xml += "<tag k='" + escapeXML(tag.key) + "' v='" + escapeXML(point.properties[tag.key]) + "'/>"
}
xml += "</node>"
xml += "</osm>"
var req = new XMLHttpRequest();
req.onreadystatechange = function()
{
if (req.readyState != 4)
return;
else if (req.status != 200)
testJosmVersion();
}
req.open("GET", url + encodeURIComponent(xml), true);
try
{
req.send(null);
}
catch (e)
{
testJosmVersion();
}
};
var testJosmVersion = function() {
var defaultAlert = "Ujistěte se prosím, že JOSM běží a je povoleno dálkové ovládání.";
var req = new XMLHttpRequest();
req.onreadystatechange = function()
{
if (req.readyState != 4)
return;
console.log(req.status);
if (req.status == 0)
alert(defaultAlert);
else if (req.status == 200)
{
var version = JSON.parse(req.responseText).protocolversion;
if (version.minor < 6)
alert("Vaše instalace JOSM nepodporuje požadavek load_data. Prosím, aktualizujte JOSM na verzi 7643 nebo novější");
}
}
req.open("GET", josmUrl + "version", true);
try
{
req.send(null);
}
catch (e)
{
alert(defaultAlert);
}
};
return {
"openOsmArea": openOsmArea,
"importPoint": importPoint,
};
})();