-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcyclingPointsRequests.js
More file actions
58 lines (51 loc) · 1.78 KB
/
Copy pathcyclingPointsRequests.js
File metadata and controls
58 lines (51 loc) · 1.78 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
export const OverpassInstance = 'https://overpass-api.de/api/interpreter'
//const OverpassInstance = 'https://overpass.kumi.systems/api/interpreter'
//export const OverpassInstance = 'https://overpass.openstreetmap.fr/api/interpreter'
//TODO dunno why I get Error: runtime error: The dispatcher (i.e. the database management system) is turned off.
const testHasLevel = (name) => /.+\.\d$/.test(name)
const splitName = (name) => name.split('.')
export const processName = (name) =>
testHasLevel(name) ? splitName(name)[0] : name
export const request = (name, requestCore) => {
const isId = /^\d+$/.test(name)
const hasLevel = testHasLevel(name)
const processedName = processName(name),
level = hasLevel && splitName(name)[1],
levelModifier = hasLevel ? `[admin_level="${level}"]` : ''
return `
[out:json][timeout:25];
( ${
isId
? `area(${3600000000 + +name})`
: `area[name="${processedName}"]${levelModifier}`
}; )->.searchArea;
(
${requestCore}
);
// print results
out body;
>;
out skel qt;
`
}
export const requestCores = {
stops: `
//node["amenity"="pharmacy"](area.searchArea);
// node["shop"="bakery"](area.searchArea);
//node["public_transport"="stop_position"](area.searchArea);
// Beware, a lot of stop positions (where the bus precisely stops, are not available, whereas bus stops are, on the test region of Bretagne, e.g. Lorient and Saint-Brieuc
node["highway"="bus_stop"](area.searchArea);
`,
townhalls: `
node["amenity"="townhall"](area.searchArea);
way["amenity"="townhall"](area.searchArea);
relation["amenity"="townhall"](area.searchArea);
`,
}
export const overpassRequestURL = (city, requestCoreName) => {
const requestContent = request(
decodeURIComponent(city),
requestCores[requestCoreName]
)
return encodeURI(`${OverpassInstance}?data=${requestContent}`)
}