-
Notifications
You must be signed in to change notification settings - Fork 0
/
address.html
70 lines (66 loc) · 2.2 KB
/
address.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
<!DOCTYPE html>
<html>
<head>
<script src="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js"></script>
<script src="https://unpkg.com/@mapbox/mapbox-sdk/umd/mapbox-sdk.min.js"></script>
<script src="https://unpkg.com/@rtirl/api@latest/lib/index.min.js"></script>
<script defer src="css.js"></script>
<link
href="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css"
rel="stylesheet"
/>
</head>
<body>
<div id="text"></div>
<script>
function wrappedEval(textExpression, contextData) {
let fn = Function(
`"use strict"; var data = this;return (${textExpression})`
);
return fn.bind(contextData)();
}
var mapboxClient = mapboxSdk({
accessToken:
"pk.eyJ1IjoiampqampqampqampqampqampqaiIsImEiOiJjbDU4b3UzejQwMmQwM2VxcWpxcGwzY2pxIn0.DiKbniZAe4dj4LegD3iBqA",
});
var i = 0;
var params = new URLSearchParams(window.location.search);
var pullKey = params.get("key");
var format = params.get("format")
? atob(params.get("format"))
: "${data.place?.text}";
RealtimeIRL.forPullKey(pullKey).addLocationListener(function (location) {
if (i++ % 50 == 0) {
mapboxClient.geocoding
.reverseGeocode({
query: [location.longitude, location.latitude],
language: [params.get("lang") || "en"],
})
.send()
.then((response) => {
var context = {};
for (var param of [
"country",
"region",
"postcode",
"district",
"place",
"locality",
"neighborhood",
"address",
"poi",
]) {
context[param] = response.body.features.find((feature) =>
feature.place_type.includes(param)
);
}
var result = wrappedEval("`" + format + "`", context);
if (!result.includes("undefined")) {
document.getElementById("text").innerText = result;
}
});
}
});
</script>
</body>
</html>