Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get User's Geolocation #74

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fe/dist/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 31 additions & 9 deletions fe/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,45 @@
<link rel="stylesheet" href="dist/style.css">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;600;700&display=swap" rel="stylesheet">
</head>

<body>
<div class="container my-16">
<h1>LeafletJS Map</h1>
<div id="map"></div>
<div id="map">
<div id="map-loader" class="grid justify-center">
<h4 class="font-medium">Please enable location services...</h4>
<div class="loader mx-auto mt-4"></div>
</div>

</div>
</div>
</body>

<script>
try {
// initialise map
var map = L.map('map').setView([56.461590, -2.971243], 17);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 19, attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'}).addTo(map);
} catch {
// display error if unable to load map
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition((position) => {
try {
// initialise map
var map = L.map('map').setView([position.coords.latitude, position.coords.longitude], 15);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom: 19, attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'}).addTo(map);

// hide loading screen
var mapLoader = document.getElementById('map-loader');
mapLoader.classList.add('hidden');
mapLoader.classList.remove('grid');
} catch {
// display error if unable to load map
var map = document.getElementById('map');
map.innerHTML = '<p>There was an error loading the map</p>';
}
})
} else {
var map = document.getElementById('map');
map.innerHTML = '<p>There was an error loading the map</p>';
map.innerHTML = '<p class="grid justify-center">Geolocation is unavailable for your browser</p>';
}
</script>

</script>
12 changes: 10 additions & 2 deletions fe/src/input.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
@tailwind components;
@tailwind utilities;

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif:wght@400;500;600;700&display=swap');

body {
@apply font-sans;
}
Expand All @@ -15,3 +13,13 @@ h1 {
#map {
@apply h-[700px] mt-8;
}

.loader {
@apply block border-[16px] border-[#F3F3F3] border-t-[16px] border-t-[#808080] rounded-full w-32 h-32;
animation: spin 2s linear infinite;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
Loading