-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
192 lines (155 loc) · 6.76 KB
/
index.html
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<html lang="en">
<head>
<title>Mausgrid</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="title" content="Mausgrid">
<meta name="description" content="Mousescale grids for your mousescale adventures">
<meta property="og:type" content="website">
<meta property="og:url" content="https://alxwrd.co.uk/mausgrid">
<meta property="og:title" content="Mausgrid">
<meta property="og:description" content="Mousescale grids for your mousescale adventures">
<meta property="og:image" content="https://i.imgur.com/xRmnK9B.png">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://alxwrd.co.uk/mausgrid">
<meta property="twitter:title" content="Mausgrid">
<meta property="twitter:description" content="Mousescale grids for your mousescale adventures">
<meta property="twitter:image" content="https://i.imgur.com/xRmnK9B.png">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="" />
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.js"></script>
<script src='https://unpkg.com/@turf/turf/turf.min.js'></script>
<style>
@font-face {
font-family: "ff-brokenscript-bc-web";
src: url("https://use.typekit.net/af/ed2608/00000000000000003b9b0801/27/l?primer=81a69539b194230396845be9681d114557adfb35f4cccc679c164afb4aa47365&fvd=n7&v=3") format("woff2"), url("https://use.typekit.net/af/ed2608/00000000000000003b9b0801/27/d?primer=81a69539b194230396845be9681d114557adfb35f4cccc679c164afb4aa47365&fvd=n7&v=3") format("woff"), url("https://use.typekit.net/af/ed2608/00000000000000003b9b0801/27/a?primer=81a69539b194230396845be9681d114557adfb35f4cccc679c164afb4aa47365&fvd=n7&v=3") format("opentype");
font-display: auto;
font-style: normal;
font-weight: 700;
}
</style>
</head>
<body>
<div class="flex md:h-36">
<p class="py-3 md:py-12 mx-auto text-6xl md:text-8xl w-5/6 text-center"
style="font-family: ff-brokenscript-bc-web, serif;">Mausgrid</p>
</div>
<div class="flex">
<div class="pt-2 relative mx-auto text-gray-600">
<form onsubmit="performSearch(event)">
<input class="border-b-2 border-gray-300 bg-white h-10 px-5 pr-16 text-sm focus:outline-none" type="search"
name="search" placeholder="Search">
<button type="submit" class="absolute right-0 top-0 mt-5 mr-4">
<svg class="text-gray-600 h-4 w-4 fill-current" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px"
viewBox="0 0 56.966 56.966" style="enable-background:new 0 0 56.966 56.966;" xml:space="preserve"
width="512px" height="512px">
<path
d="M55.146,51.887L41.588,37.786c3.486-4.144,5.396-9.358,5.396-14.786c0-12.682-10.318-23-23-23s-23,10.318-23,23 s10.318,23,23,23c4.761,0,9.298-1.436,13.177-4.162l13.661,14.208c0.571,0.593,1.339,0.92,2.162,0.92 c0.779,0,1.518-0.297,2.079-0.837C56.255,54.982,56.293,53.08,55.146,51.887z M23.984,6c9.374,0,17,7.626,17,17s-7.626,17-17,17 s-17-7.626-17-17S14.61,6,23.984,6z" />
</svg>
</button>
</form>
</div>
</div>
<div style="height: 75%">
<div class="flex h-full">
<div id="map" class="shadow-md rounded-lg mx-auto w-5/6 lg:w-1/2 h-full md:h-5/6"></div>
</div>
</div>
<script>
let map;
let hexLayer;
function performSearch(event) {
event.preventDefault();
locateOnMap(event.target.elements.search.value);
event.target.elements.search.value = '';
}
function locateOnMap(location) {
fetch(`https://nominatim.openstreetmap.org/search.php?q=${location}&format=jsonv2`)
.then(response => response.json())
.then(data => {
const first = data.shift();
if (!first) {
return;
}
updateLocation({ lat: parseFloat(first.lat), lng: parseFloat(first.lon) }, { persist: false, updateUrl: true })
});
}
function getBoundingBox(latlng, distanceInKm) {
const deltaLat = distanceInKm / 110.574235;
const deltaLong = distanceInKm / (110.572833 * Math.cos(latlng.lat * Math.PI / 180));
return [
latlng.lng - deltaLong, latlng.lat + deltaLat,
latlng.lng + deltaLong, latlng.lat - deltaLat
];
}
function updateLocation(location, options) {
drawgrid(location, hexLayer);
if (options && options.persist) {
localStorage.setItem('mausgrid', JSON.stringify(location));
}
const url = new URL(window.location);
url.searchParams.set('search', `${location.lat.toFixed(6)},${location.lng.toFixed(6)}`);
document.title = `Mausgrid @ ${location.lat.toFixed(6)},${location.lng.toFixed(6)}`
if (options && options.updateUrl) {
window.history.replaceState({}, window.title, url);
}
map.setView([location.lat + 0.003, location.lng], 12);
}
function drawgrid(latlng, layer) {
layer.clearLayers();
var hexgrid = turf.hexGrid(
getBoundingBox(latlng, 3 * 1.609),
0.5,
{
units: 'miles',
mask: turf.circle(
[latlng.lng, latlng.lat],
1.6,
{ 'steps': 6, units: 'miles' }
)
}
);
L.geoJson(hexgrid.features,
{
style: {
weight: 1,
color: "#333333",
opacity: 1,
fillOpacity: 0
}
}).addTo(hexLayer);
}
document.addEventListener('DOMContentLoaded', function () {
let center = { lat: 53.05958046317886, lng: -1.6131019592285156 };
if (localStorage.getItem('mausgrid')) {
center = JSON.parse(localStorage.getItem('mausgrid'));
}
map = L.map(
'map',
{
zoomControl: false,
maxZoom: 18,
minZoom: 5,
}
)
hexLayer = L.layerGroup().addTo(map);
map.on('click', (event) => {
updateLocation(event.latlng, { persist: true, updateUrl: true });
})
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
const url = new URL(window.location);
const searchParam = encodeURIComponent(url.searchParams.get('search'));
if (searchParam !== "null") {
locateOnMap(searchParam);
return;
}
updateLocation(center, { persist: false, updateUrl: false })
}, false);
</script>
</body>
</html>