mirror of
https://github.com/cjdenio/uta-trax-api.git
synced 2026-10-03 16:06:19 +00:00
schema
This commit is contained in:
2 files changed
+17
-17
No files matched your search
@@ -128,6 +128,10 @@ func main() {
|
|||||||
|
|
||||||
http.Handle("/", http.FileServer(http.Dir("./static")))
|
http.Handle("/", http.FileServer(http.Dir("./static")))
|
||||||
|
|
||||||
|
http.HandleFunc("/schema.proto", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.ServeFile(w, r, "./proto/schema.proto")
|
||||||
|
})
|
||||||
|
|
||||||
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
|
||||||
vehicles, err := getVehicles()
|
vehicles, err := getVehicles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+13
-17
@@ -43,25 +43,21 @@
|
|||||||
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
protobuf
|
protobuf.load("/schema.proto").then(async (root) => {
|
||||||
.load(
|
const bin = await fetch("/api").then((r) => r.arrayBuffer());
|
||||||
"https://raw.githubusercontent.com/cjdenio/uta-trax-api/refs/heads/main/proto/schema.proto"
|
const { vehicles } = root
|
||||||
)
|
.lookupType("VehicleFeed")
|
||||||
.then(async (root) => {
|
.decode(new Uint8Array(bin));
|
||||||
const bin = await fetch("/api").then((r) => r.arrayBuffer());
|
|
||||||
const { vehicles } = root
|
|
||||||
.lookupType("VehicleFeed")
|
|
||||||
.decode(new Uint8Array(bin));
|
|
||||||
|
|
||||||
vehicles.forEach((vehicle) => {
|
vehicles.forEach((vehicle) => {
|
||||||
L.circle([vehicle.lat, vehicle.lon], {
|
L.circle([vehicle.lat, vehicle.lon], {
|
||||||
fillColor: COLORS[vehicle.line],
|
fillColor: COLORS[vehicle.line],
|
||||||
color: COLORS[vehicle.line],
|
color: COLORS[vehicle.line],
|
||||||
fillOpacity: 0.5,
|
fillOpacity: 0.5,
|
||||||
radius: 200,
|
radius: 200,
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in new issue
Block a user