-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
155 lines (120 loc) · 4.52 KB
/
example.php
File metadata and controls
155 lines (120 loc) · 4.52 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
include('TileTracker.php');
// Define Login Variables
$USER = 'admin@email.com';
$PASS = 'password123';
$TileTracker = new TileTracker($USER, $PASS);
$user_tiles = $TileTracker->TileRequest('/tiles/tile_states');
$user_tiles_decoded = json_decode($user_tiles, true);
$tiles = array();
foreach ($user_tiles_decoded['result'] as $tile_id) {
$tile_decoded = json_decode($TileTracker->TileRequest('/tiles?tile_uuids=' . $tile_id['tile_id']), true);
$tiles[$tile_id['tile_id']]['full_data'] = $tile_decoded;
$tiles[$tile_id['tile_id']]['uuid'] = preg_replace("/(\W)+/", "", $tile_id['tile_id']);
$tiles[$tile_id['tile_id']]['timestamp'] = $tile_decoded['result'][$tile_id['tile_id']]['last_tile_state']['timestamp'];
$tiles[$tile_id['tile_id']]['name'] = $tile_decoded['result'][$tile_id['tile_id']]['name'];
$tiles[$tile_id['tile_id']]['lon'] = $tile_decoded['result'][$tile_id['tile_id']]['last_tile_state']['latitude'];
$tiles[$tile_id['tile_id']]['lat'] = $tile_decoded['result'][$tile_id['tile_id']]['last_tile_state']['longitude'];
$firstKey = array_key_first($tiles);
}
?>
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>OpenMap Tile</title>
<script src="node_modules/jquery/dist/jquery.slim.js"></script>
<link rel="stylesheet" href="node_modules/leaflet/dist/leaflet.css"/>
<script src="node_modules/leaflet/dist/leaflet.js"></script>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css"/>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<style media="screen">
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 80vh;
}
.container {
height: 100vh;
overflow: auto;
}
#content {
height: 80vh;
overflow: auto;
}
#footer {
height: 5vh;
}
#header {
height: 10vh;
}
</style>
</head>
<body>
<div class="container">
<div class="row" id="header">
<div class="col-sm-12">
<nav class="navbar navbar-light bg-light">
<span class="navbar-brand mb-0 h1">Tile Tracker</span>
</nav>
</div>
</div>
<div class="row" id="content">
<div class="col-sm-4">
<ul class="list-group">
<?php
foreach ($tiles as $tile) {
echo "<li class=\"list-group-item\">
<a href=\"#\" id=\"_" . $tile['uuid'] . "\">" . $tile['name'] . "</a><br>
<small>UUID: " . $tile['uuid'] . "</small><br>
<small>Updated " . date("d-m-Y H:i:s", ($tile['timestamp'] / 1000)) . "</small>
</li>";
}
?>
</ul>
</div>
<div class="col-sm-8">
<div id="map"></div>
</div>
</div>
<div class="row" id="footer">
<div class="col-sm-12 text-center align-middle"><br><?= "Session expiry in " . round(($TileTracker->USER_UUID_EXPIRE - (time() * 1000)) / 1000 / 60) . " mins<br><br>" ?></div>
</div>
</div>
<script>
let map = L.map('map').setView([<?=$tiles[$firstKey]['lon']?>, <?=$tiles[$firstKey]['lat']?>], 7);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
function markerFunction(id) {
for (let i in markers) {
let markerID = markers[i].options.title;
if (markerID === id) {
let latLngs = [markers[i].getLatLng()];
let markerBounds = L.latLngBounds(latLngs);
map.fitBounds(markerBounds);
markers[i].openPopup();
}
}
}
let markers = [];
let latlngs = [];
<?php
foreach ($tiles as $tile) {
echo "var _" . $tile['uuid'] . " = L.marker([" . $tile['lon'] . ", " . $tile['lat'] . "],{title:'" . $tile['name'] . "'}).addTo(map).bindPopup('" . $tile['name'] . "');";
echo "markers.push(_" . $tile['uuid'] . ");";
echo "var latlng_" . $tile['uuid'] . " = [" . $tile['lon'] . ", " . $tile['lat'] . "];";
echo "latlngs.push(latlng_" . $tile['uuid'] . ");";
}
?>
let bounds = new L.LatLngBounds(latlngs);
map.fitBounds(bounds, {padding: [50, 50]});
$("a").click(function () {
markerFunction($(this)[0].id);
});
</script>
</body>
</html>