Where-in-the-World-is-Ben/resources/views/tracker.blade.php

147 lines
6.3 KiB
PHP
Raw Normal View History

2022-08-23 19:11:43 +00:00
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tracking | Ben Goldsworthy</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js"
integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
crossorigin=""></script>
2022-08-24 10:41:23 +00:00
<link rel="stylesheet" href="/css/app.css" />
2022-08-23 19:11:43 +00:00
</head>
2022-08-24 10:41:23 +00:00
<body>
2022-08-23 19:11:43 +00:00
2022-10-19 22:34:34 +00:00
<header class="page-header">
2022-09-24 19:36:06 +00:00
<h1 class="page-title">Where in the World is Ben?</h1>
<nav class="other-links">
<ul>
<li><p><a href="/past-trips">Past trips</a></p></li>
</ul>
</nav>
<section class="trip-meta">
<p>
<span> Tracking started: {{ date('j M Y (G:H)', strtotime($trip->date_start)) }}</span> |
<span class="{{ ($trip->is_active) ? "positive" : "negative" }}">{{ ($trip->is_active) ? "Active" : "Ended" }}</span> |
@if ($trip->is_active)
2022-09-24 19:36:06 +00:00
<span class="{{ ($trip->is_tracking) ? "positive" : "negative" }}">{{ ($trip->is_tracking) ? "Currently tracking" : "Not currently tracking" }}</span>
@endif
2022-09-24 19:36:06 +00:00
<span class="small">(Last update: {{ date('j M Y (G:H)', strtotime($trip->updated_at)) }})</span>
</p>
</section>
2022-08-23 19:11:43 +00:00
</header>
<main id="routeContainer">
2022-10-19 21:14:10 +00:00
<section id="mapContainer">
<div id="map"></div>
</section>
2022-08-23 19:11:43 +00:00
<section id="checkinList">
2022-10-19 21:14:10 +00:00
<ol start="{{ count($trip->checkins) }}" reversed>
@foreach(array_slice(array_reverse($trip->checkins), 0, 15) as $checkin)
2022-10-19 21:14:10 +00:00
<li>
2022-10-19 22:34:34 +00:00
<details class="checkin" id="{{ $checkin->id }}" ontoggle="toggleCheckin(this.open, this.id)">
<summary class="checkin__summary">
<h2 class="checkin__title">{{ $checkin->title ?? "[No title]" }}</h2>
<p class="checkin__meta">{{ date('j M Y (G:H)', strtotime($checkin->date)) }}</p>
</summary>
2022-10-19 21:14:10 +00:00
{{ $checkin->note ?? "[No note]" }}
@if($checkin->image_url)
<img class="popup__image" loading="lazy" src="{{ $checkin->image_url }}">
@endif
</details>
</li>
2022-08-23 19:11:43 +00:00
@endforeach
2022-10-19 21:14:10 +00:00
</ol>
2022-08-23 19:11:43 +00:00
</section>
</main>
<footer>
<script>
2022-10-19 22:35:02 +00:00
/*
* Initialise the map
*/
var map = L.map('map');//.setView([{{ end($trip->locations)->latitude }}, {{ end($trip->locations)->longitude }}], 7);
2022-08-23 19:11:43 +00:00
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: 'OpenStreetMap'
}).addTo(map);
2022-10-19 22:35:02 +00:00
/*
* Populate the route line.
*/
2022-08-23 19:11:43 +00:00
var routePoints = L.polyline([
@foreach($trip->locations as $location)
[{{ $location->latitude }}, {{ $location->longitude }}],
@endforeach
]).addTo(map);
2022-10-19 22:35:02 +00:00
/*
* Populate all the checkins and popup texts.
*/
2022-08-23 19:11:43 +00:00
var checkinMarkers = [];
var marker = null, popupMarkup = null;
@foreach($trip->checkins as $checkin)
marker = L.marker([{{ $checkin->location->latitude }}, {{ $checkin->location->longitude }}]).addTo(map);
popupMarkup = '<h2 class="popup__title">{{ $checkin->title ?? "No Title" }}</h2>';
2022-08-29 21:35:04 +00:00
popupMarkup += `<p class="popup__note">{{ $checkin->note }}</p>`;
2022-08-23 19:11:43 +00:00
popupMarkup += '<img class="popup__image" src="{{ $checkin->image_url }}">';
marker.bindPopup(popupMarkup).openPopup();
checkinMarkers[{{ $checkin->id }}] = marker;
@endforeach
2022-08-29 21:34:48 +00:00
2022-10-19 22:35:02 +00:00
/*
* Fit the map to the last 25 locations, and then zoom out
* (to help provide context).
*/
map.fitBounds([
@foreach(array_slice(array_reverse($trip->locations), 0, 25) as $location)
[{{ $location->latitude }}, {{$location->longitude }}],
@endforeach
]);
map.zoomOut(2);
/*
* Add the current location marker.
*
* If this goes before the `fitBounds()`, it ends up uncentered.
* TODO: Revisit once fixed with other popups.
*/
var currLocationMarker = L.icon({
iconUrl: 'current-location-icon.png',
iconSize: [30, 45],
});
2022-08-29 21:34:48 +00:00
var currLocation = L.marker(
[{{ end($trip->locations)->latitude }}, {{ end($trip->locations)->longitude }}],
2022-10-19 22:35:02 +00:00
{icon: currLocationMarker}
2022-08-29 21:34:48 +00:00
).addTo(map).setZIndexOffset(1000);
currLocation.bindPopup('<p>Current location</p>').openPopup();
2022-10-19 22:35:02 +00:00
/*
* Changes the currently-selected popup.
*/
2022-08-24 10:41:23 +00:00
function toggleCheckin(isOpen, checkinId) {
if (isOpen) {
var checkins = document.querySelectorAll('details');
checkinMarkers[checkinId].openPopup();
checkins.forEach(checkin => {
if (checkin.id != checkinId && checkin.open) checkin.open = false;
});
} else {
checkinMarkers[checkinId].closePopup();
}
2022-08-23 19:11:43 +00:00
}
</script>
</footer>
</body>
</html>