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

221 lines
11 KiB
PHP
Raw Normal View History

2022-08-23 19:11:43 +00:00
<!DOCTYPE html>
2022-10-29 23:49:19 +00:00
<html itemscope itemtype="https://schema.org/WebSite" lang="{{ str_replace('_', '-', app()->getLocale()) }}">
2022-10-29 23:23:02 +00:00
@include('partials.head')
2022-08-23 19:11:43 +00:00
2022-08-24 10:41:23 +00:00
<body>
2022-10-19 22:34:34 +00:00
<header class="page-header">
2022-10-19 22:53:52 +00:00
<h1 class="page-title">@if ($trip->is_active) Where in the World is Ben? @else {{ $trip->name }} @endif</h1>
2022-09-24 19:36:06 +00:00
<nav class="other-links">
<ul>
2022-10-19 23:28:56 +00:00
@if (!$trip->is_active)
<li><p><a href="/">Current trip</a></p></li>
@endif
2022-09-24 19:36:06 +00:00
<li><p><a href="/past-trips">Past trips</a></p></li>
</ul>
</nav>
<section class="trip-meta">
<p>
<span> Tracking started: {!! render_date_difference($trip->date_start) !!}</span> |
2024-03-14 19:11:55 +00:00
<span class="{{ ($trip->is_active) ? "positive" : "negative" }}">{{ ($trip->is_active) ? "Active" : "Ended" }}</span> |
@if ($trip->is_active)
2024-03-14 19:11:55 +00:00
<span class="{{ ($trip->is_tracking) ? "positive" : "negative" }}">{{ ($trip->is_tracking) ? "Currently tracking" : "Not currently tracking" }}</span>
@endif
2024-11-04 23:11:41 +00:00
<span class="small">(Last update: {!! render_date_difference( $trip->checkins[ count($trip->checkins) - 1 ]->date ) !!})</span>
2022-09-24 19:36:06 +00:00
</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">
2024-07-05 22:28:30 +00:00
<h2 class="section__title">@if ($showAllCheckins) Posts @elseif ($cherryPicked || $toCheckin || $fromCheckin) Selected Posts @else Recent Posts @endif</h2>
<p style="font-weight: bold; text-align: center;">Want to receive a regular email digest of updates?</p>
<p style="text-align: center;">Ask me and I'll add you to the list: weekly, fortnightly and monthly options available (or daily if you're really keen).</p>
2024-07-05 22:28:30 +00:00
<ol @if(!($showAllCheckins || $toCheckin || $fromCheckin || $cherryPicked)) start="{{ count($trip->checkins) }}" @if(!$cherryPicked) reversed @endif @endif>
@if($showAllCheckins || $toCheckin || $fromCheckin || $cherryPicked)
2023-06-12 02:54:33 +00:00
@php $checkinsList = $trip->checkins @endphp
@else
@php $checkinsList = array_slice(array_reverse($trip->checkins), 0, 10) @endphp
@endif
@include('partials.checkins-list')
2022-10-19 21:14:10 +00:00
</ol>
@if (!$showAllCheckins)
<p><a id="allCheckinsLink" href="?show=all">Show all posts</a></p>
2022-10-19 23:28:56 +00:00
@endif
2022-08-23 19:11:43 +00:00
</section>
</main>
<footer>
<script>
2022-10-19 22:35:02 +00:00
/*
* Initialise the map
*/
2024-03-14 18:25:31 +00:00
var map = L.map('map', { fullscreenControl: true });
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);
2023-05-18 19:41:59 +00:00
@for($idx = 3; $idx <= count($trip->locations); $idx += 99)
2023-03-15 22:48:41 +00:00
/*
* Populate the route line.
*/
L.polyline([
@foreach(array_slice($trip->locations, $idx, 100) as $location)
@if(!in_array($location->id, config('app.current_trip_ignore')))
2024-07-05 22:28:10 +00:00
@php
// Privacy zones
$privacyLatLons = config('app.privacy_lat_lons');
$latLon = explode(',', $privacyLatLons[0]);
if (
!(
( $location->latitude - $latLon[0] > 0.01 ) || ( $location->latitude - $latLon[0] < -0.01 ) ||
( $location->longitude - $latLon[1] > 0.01 ) || ( $location->longitude - $latLon[1] < -0.01 )
)
) {
$location->latitude = $location->latitude + ((rand(0,2)-1)/100);
$location->longitude = $location->longitude + ((rand(0,2)-1)/100);
}
@endphp
2024-03-14 21:23:17 +00:00
[{{ $location->latitude }}, {{ $location->longitude }}],
2023-03-15 22:48:41 +00:00
@endif
2024-06-09 13:02:19 +00:00
@if(in_array($location->id, config('app.current_trip_break_locations')))
], {
@php $colour = 180 * ( 1.0 - ( ( $idx - 99 ) / ( count($trip->locations) ) ) ); @endphp
color: 'rgb({{ $colour }}, {{ $colour }}, {{ $colour }})',
weight: 5,
}).addTo(map);
L.polyline([
@endif
2023-03-15 22:48:41 +00:00
@endforeach
], {
2023-03-19 17:34:19 +00:00
@php $colour = 180 * ( 1.0 - ( ( $idx ) / ( count($trip->locations) ) ) ); @endphp
color: 'rgb({{ $colour }}, {{ $colour }}, {{ $colour }})',
weight: 5,
2023-03-15 22:48:41 +00:00
}).addTo(map);
@endfor
2022-08-23 19:11:43 +00:00
2022-10-19 22:35:02 +00:00
/*
* Populate all the checkins and popup texts.
2024-03-14 19:11:55 +00:00
*/
2022-08-23 19:11:43 +00:00
var checkinMarkers = [];
var marker = null, popupMarkup = null;
var markerIcon = L.icon({
iconAnchor: [12, 41],
iconSize: [25, 41],
iconUrl: "images/marker-icon.png",
popupAnchor: [1, -34],
shadowSize: [41, 41],
shadowUrl: "images/marker-shadow.png",
tooltipAnchor: [16, -28]
});
2024-03-14 19:11:55 +00:00
2022-08-23 19:11:43 +00:00
@foreach($trip->checkins as $checkin)
2024-03-14 19:11:55 +00:00
marker = L.marker([{{ $checkin->location->latitude }}, {{ $checkin->location->longitude }}],
{
icon: markerIcon
});
@php
$popupContent = null;
$embed = null;
if (preg_match("/\[\[([^\]]+)\]\]/", $checkin->note, $filepath)) {
if (preg_match("/\.webm/", $filepath[1])) {
2024-08-27 14:57:33 +00:00
$embed = '<video class="popup__video" prefetch="none" controls>';
2024-03-14 19:11:55 +00:00
$embed .= '<source src="' . url("/videos/" . $filepath[1]) . '" type="video/webm">';
$embed .= '<p>Your browser doesn\'t support HTML video. Here is a <a href="';
$embed .= url("/videos/" . $filepath[1]) . '">link to the video</a> instead.</p>';
$embed .= '</video>';
} elseif (preg_match("/\.ogg/", $filepath[1])) {
2024-08-27 14:57:33 +00:00
$embed = '<audio class="popup__audio" prefetch="none" controls>';
2024-03-14 19:11:55 +00:00
$embed .= '<source src="' . url("/audio/" . $filepath[1]) . '" type="audio/ogg">';
$embed .= '<p>Download <a href="' . url("/audio/" . $filepath[1]) . '">OGG</a> audio.</p>';
$embed .= '</audio>';
}
$checkin->note = preg_replace("/\[\[[^\]]+\]\]/", $embed, $checkin->note);
}
$popupContent ='<p class="popup__note">' . $checkin->note . '</p>';
@endphp
popupMarkup = `<h2 class="popup__title">{!! $checkin->title ?? "<i>Untitled</i>" !!}</h2>`;
popupMarkup += `{!! $popupContent !!}`;
@if($checkin->image_url)
popupMarkup += '<img class="popup__image" src="{{ $checkin->image_url }}">';
@endif
marker.bindPopup(popupMarkup).openPopup();
checkinMarkers[{{ $checkin->id }}] = marker;
2022-08-23 19:11:43 +00:00
@endforeach
2024-03-14 19:11:55 +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([
2022-10-19 23:28:56 +00:00
@if ($trip->is_active)
2023-01-14 20:08:56 +00:00
@foreach(array_slice(array_reverse($trip->checkins), 0, 25) as $checkin)
[{{ $checkin->location->latitude }}, {{$checkin->location->longitude }}],
2024-03-14 19:11:55 +00:00
@endforeach
2022-10-19 23:28:56 +00:00
@else
@foreach($trip->locations as $location)
2022-10-19 22:35:02 +00:00
[{{ $location->latitude }}, {{$location->longitude }}],
2024-03-14 19:11:55 +00:00
@endforeach
2022-10-19 23:28:56 +00:00
@endif
2022-10-19 22:35:02 +00:00
]);
@if ($trip->is_active) map.zoomOut(1); @endif
2022-10-19 22:35:02 +00:00
@if($trip->is_active)
/*
* Add the current location marker.
*
* If this goes before the `fitBounds()`, it ends up uncentered.
*/
var currLocationMarker = L.icon({
iconUrl: 'images/current-location-icon.png',
iconSize: [30, 45],
});
2022-10-19 22:35:02 +00:00
var currLocation = L.marker(
[{{ end($trip->locations)->latitude }}, {{ end($trip->locations)->longitude }}],
{
icon: currLocationMarker
}
).addTo(map)
currLocation.bindPopup('<p>Current location</p>', {
width: "400px"
}).openPopup();
@endif
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) {
currLocation.removeFrom(map);
2022-08-24 10:41:23 +00:00
if (isOpen) {
2024-03-14 19:11:55 +00:00
const checkins = document.querySelectorAll('details');
2022-08-24 10:41:23 +00:00
checkinMarkers[checkinId].openPopup();
2024-03-14 19:11:55 +00:00
checkinMarkers[checkinId].addTo(map);
2022-08-24 10:41:23 +00:00
2024-03-14 19:11:55 +00:00
for (checkin of checkins) {
2022-08-24 10:41:23 +00:00
if (checkin.id != checkinId && checkin.open) checkin.open = false;
2024-03-14 19:11:55 +00:00
}
map.setView(new L.LatLng(checkinMarkers[checkinId].getLatLng().lat + 0.03, checkinMarkers[checkinId].getLatLng().lng));
2022-08-24 10:41:23 +00:00
} else {
checkinMarkers[checkinId].closePopup();
2024-03-14 19:11:55 +00:00
checkinMarkers[checkinId].removeFrom(map);
2022-08-24 10:41:23 +00:00
}
2022-08-23 19:11:43 +00:00
}
</script>
</footer>
</body>
</html>