-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatlas.html
More file actions
451 lines (404 loc) · 15.2 KB
/
Copy pathatlas.html
File metadata and controls
451 lines (404 loc) · 15.2 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0" />
<title>Atlas - GeoSpot</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
overflow: hidden;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: #1a1a2e;
color: #eee;
height: 100dvh;
display: flex;
flex-direction: column;
}
/* ── Header ── */
header {
padding: 10px 16px;
background: #16213e;
border-bottom: 1px solid #0f3460;
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
flex-shrink: 0;
}
header h1 { font-size: 1.4rem; font-weight: 800; letter-spacing: 0.08em; color: #e94560; }
header .subtitle { font-size: 0.78rem; color: #888; letter-spacing: 0.04em; }
/* ── Map ── */
#map { flex: 1; width: 100%; position: relative; background: #1a1a2e; }
.leaflet-container { background: #1a1a2e !important; }
.leaflet-interactive { transition: r 0.15s ease, d 0.15s ease; }
/* ── Bottom bar ── */
#bottom-bar {
position: absolute;
bottom: 24px;
left: 50%;
transform: translateX(-50%);
width: min(300px, calc(100vw - 32px));
z-index: 900;
display: flex;
align-items: center;
gap: 8px;
}
#search-wrapper { position: relative; flex: 1; min-width: 0; }
#search-input {
width: 100%;
padding: 12px 18px;
border-radius: 30px;
border: 1px solid #0f3460;
background: rgba(22, 33, 62, 0.92);
color: #eee;
font-size: 1rem;
outline: none;
transition: border-color 0.2s;
backdrop-filter: blur(8px);
box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}
#search-input:focus { border-color: #e94560; }
#search-input::placeholder { color: #888; }
#submit-btn {
flex-shrink: 0;
width: 44px; height: 44px;
border-radius: 50%;
border: none;
background: #e94560;
color: #fff;
font-size: 1.1rem;
cursor: pointer;
box-shadow: 0 4px 16px rgba(0,0,0,0.4);
transition: background 0.2s, transform 0.1s;
display: flex; align-items: center; justify-content: center;
}
#submit-btn:hover { background: #c73652; }
#submit-btn:active { transform: scale(0.93); }
#suggestions {
position: absolute;
bottom: calc(100% + 6px);
left: 0; right: 0;
background: rgba(22, 33, 62, 0.96);
border: 1px solid #0f3460;
border-radius: 16px;
overflow: hidden;
z-index: 9999;
box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
backdrop-filter: blur(8px);
}
.suggestion-item {
padding: 10px 18px;
cursor: pointer;
font-size: 0.9rem;
border-bottom: 1px solid #0f3460;
transition: background 0.15s;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item.active { background: #0f3460; color: #e94560; }
.suggestion-item .name { font-weight: 600; }
.dot-label {
position: absolute;
transform: translateX(-50%);
bottom: -8px;
left: 0;
white-space: nowrap;
font-size: 0.82rem;
font-weight: 700;
text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.7);
pointer-events: none;
letter-spacing: 0.02em;
}
</style>
</head>
<body>
<header>
<h1>GeoSpot</h1>
<div class="subtitle">Atlas</div>
</header>
<div id="map"></div>
<div id="bottom-bar">
<div id="search-wrapper">
<input id="search-input" type="text" placeholder="Recherche une ville…" autocomplete="off" spellcheck="false" />
<div id="suggestions" style="display:none"></div>
</div>
<button id="submit-btn" title="Valider" onclick="submitSearch()"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="https://unpkg.com/@turf/turf@6/turf.min.js"></script>
<script src="borders.js"></script>
<script src="rivers.js"></script>
<script src="landmarks.js"></script>
<script src="cities.js"></script>
<script>
// ── Map ───────────────────────────────────────────────────────────────────
const map = L.map('map', {
center: [46.6, 2.5], zoom: 6,
zoomSnap: 0,
zoomControl: false, dragging: false,
scrollWheelZoom: false, doubleClickZoom: false,
touchZoom: false, boxZoom: false, keyboard: false,
});
const LAT_SOUTH = 41.2;
const LAT_NORTH = 51.2;
const LNG_WEST = -5.2;
const LNG_EAST = 9.6;
const LNG_CENTER = (LNG_WEST + LNG_EAST) / 2;
const PAD_TOP = 30;
const PAD_BOTTOM = 100;
const PAD_SIDES = 16;
const isTouchDevice = navigator.maxTouchPoints > 0;
const SCREEN_H = window.visualViewport ? window.visualViewport.height : window.innerHeight;
function fitLatitudes() {
const mapEl = document.getElementById('map');
const availH = mapEl.clientHeight - PAD_TOP - PAD_BOTTOM;
const availW = mapEl.clientWidth - PAD_SIDES * 2;
const centerLat = (LAT_NORTH + LAT_SOUTH) / 2;
let lo = 0, hi = 18;
for (let i = 0; i < 30; i++) {
const mid = (lo + hi) / 2;
const yS = map.project([LAT_SOUTH, 0], mid).y;
const yN = map.project([LAT_NORTH, 0], mid).y;
if (yS - yN < availH) lo = mid; else hi = mid;
}
const zoomH = lo;
lo = 0; hi = 18;
for (let i = 0; i < 30; i++) {
const mid = (lo + hi) / 2;
const xW = map.project([0, LNG_WEST], mid).x;
const xE = map.project([0, LNG_EAST], mid).x;
if (xE - xW < availW) lo = mid; else hi = mid;
}
const zoomW = lo;
map.setView([centerLat, LNG_CENTER], Math.min(zoomH, zoomW), { animate: false });
}
new ResizeObserver(() => {
const mapEl = document.getElementById('map');
if (mapEl.clientHeight < 50) return;
if (isTouchDevice && mapEl.clientHeight < SCREEN_H * 0.5) return;
map.invalidateSize({ animate: false });
fitLatitudes();
}).observe(document.getElementById('map'));
function updateBottomOffset() {
if (!window.visualViewport) return;
const vv = window.visualViewport;
const base = Math.max(0, window.innerHeight - (vv.offsetTop + vv.height));
document.getElementById('bottom-bar').style.bottom = (24 + base) + 'px';
}
if (window.visualViewport) {
window.visualViewport.addEventListener('resize', updateBottomOffset);
window.visualViewport.addEventListener('scroll', updateBottomOffset);
}
map.createPane('lines'); map.getPane('lines').style.zIndex = 620;
map.createPane('dotsLandmark'); map.getPane('dotsLandmark').style.zIndex = 630;
map.createPane('dotsSearch'); map.getPane('dotsSearch').style.zIndex = 650;
map.createPane('labels'); map.getPane('labels').style.zIndex = 660;
map.getPane('lines').style.pointerEvents = 'none';
map.getPane('labels').style.pointerEvents = 'none';
const COLOR_LANDMARK = '#70a1ff';
const STROKE_LANDMARK = '#a8c8ff';
const COLOR_SEARCH = '#f5a623';
const STROKE_SEARCH = '#f9c87a';
// ── Landmark dots ─────────────────────────────────────────────────────────
function addLandmark(lat, lng, name) {
const latlng = [lat, lng];
const labelIcon = L.divIcon({
className: '',
html: '<span class="dot-label" style="color:' + COLOR_LANDMARK + '">' + escapeHtml(name) + '</span>',
iconSize: [0, 0],
iconAnchor: [0, 18],
});
const labelMarker = L.marker(latlng, { icon: labelIcon, pane: 'labels', interactive: false });
const dot = L.circleMarker(latlng, {
radius: 5,
color: STROKE_LANDMARK,
weight: 1.5,
fillColor: COLOR_LANDMARK,
fillOpacity: 1,
pane: 'dotsLandmark',
}).addTo(map);
dot.on('mouseover', () => { dot.setRadius(7); labelMarker.addTo(map); labelMarker.getElement().style.zIndex = 9999; });
dot.on('mouseout', () => { dot.setRadius(5); map.removeLayer(labelMarker); });
}
// ── Search dot ────────────────────────────────────────────────────────────
let searchLayers = [];
function clearSearchDots() {
searchLayers.forEach(l => map.removeLayer(l));
searchLayers = [];
}
function placeSearchDots(cities) {
clearSearchDots();
cities.forEach(city => {
const [lng, lat] = city.centre.coordinates;
const latlng = [lat, lng];
const icon = L.divIcon({
className: '',
html: '<span class="dot-label" style="color:' + COLOR_SEARCH + '">' + escapeHtml(city.nom) + '</span>',
iconSize: [0, 0],
iconAnchor: [0, 18],
});
const label = L.marker(latlng, { icon, pane: 'labels', interactive: false }).addTo(map);
const dot = L.circleMarker(latlng, {
radius: 6,
color: STROKE_SEARCH,
weight: 2,
fillColor: COLOR_SEARCH,
fillOpacity: 1,
pane: 'dotsSearch',
}).addTo(map);
searchLayers.push(dot, label);
});
}
// ── Tile + layers ─────────────────────────────────────────────────────────
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: '© <a href="https://www.esri.com">Esri</a>, Maxar, Earthstar Geographics',
maxZoom: 19,
}).addTo(map);
setTimeout(() => {
const clippedSegments = [];
RIVERS_GEOJSON.features.forEach(feature => {
const coords = feature.geometry.type === 'LineString'
? [feature.geometry.coordinates] : feature.geometry.coordinates;
coords.forEach(line => {
let seg = [];
line.forEach(coord => {
if (turf.booleanPointInPolygon(turf.point(coord), FRANCE_GEOJSON)) {
seg.push(coord);
} else {
if (seg.length >= 2) clippedSegments.push({ type:'Feature', geometry:{ type:'LineString', coordinates:seg }, properties:{} });
seg = [];
}
});
if (seg.length >= 2) clippedSegments.push({ type:'Feature', geometry:{ type:'LineString', coordinates:seg }, properties:{} });
});
});
L.geoJSON({ type:'FeatureCollection', features:clippedSegments }, {
style: { color:'#ffffff', weight:1.2, opacity:0.25 }, interactive: false,
}).addTo(map);
const mainlandGeoJSON = {
type: 'Feature',
geometry: {
type: 'MultiPolygon',
coordinates: [...FRANCE_GEOJSON.geometry.coordinates].sort((a, b) => b[0].length - a[0].length).slice(0, 3),
},
properties: {},
};
L.geoJSON(mainlandGeoJSON, {
style: { color:'#ffffff', weight:1.5, opacity:0.5, fill: false }, interactive: false,
}).addTo(map);
LANDMARKS.forEach(([lat, lng, name]) => addLandmark(lat, lng, name));
}, 0);
// ── Search ────────────────────────────────────────────────────────────────
const input = document.getElementById('search-input');
const suggestionsEl = document.getElementById('suggestions');
let activeIndex = -1;
let currentResults = [];
let selectedGroup = null;
function normalize(str) {
return str.normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/-/g, ' ').toLowerCase();
}
function normalizeExact(str) {
return str.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
}
function escapeHtml(s) {
return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
}
function searchCities(query) {
const q = normalize(query);
const articlePrefix = /^(le |la |les |l')/;
const byName = new Map();
for (const city of CITIES_DATA) {
const norm = normalize(city.nom);
const normStripped = norm.replace(articlePrefix, '');
if (norm.startsWith(q) || normStripped.startsWith(q)) {
const key = city.nom;
if (!byName.has(key)) byName.set(key, []);
byName.get(key).push(city);
}
}
const groups = Array.from(byName.entries())
.map(([nom, cities]) => ({ nom, cities }))
.sort((a, b) => a.nom.length - b.nom.length);
currentResults = groups.slice(0, 5);
renderSuggestions(currentResults);
}
function renderSuggestions(results) {
activeIndex = -1;
if (!results.length) { hideSuggestions(); return; }
suggestionsEl.innerHTML = results.map((r, i) =>
'<div class="suggestion-item" data-index="' + i + '"><div class="name">' + escapeHtml(r.nom) + '</div></div>'
).join('');
suggestionsEl.querySelectorAll('.suggestion-item').forEach(el => {
el.addEventListener('mousedown', (e) => {
e.preventDefault();
fillInput(currentResults[+el.dataset.index]);
});
});
suggestionsEl.style.display = 'block';
}
function fillInput(r) {
selectedGroup = r;
input.value = r.nom;
hideSuggestions();
input.focus();
}
function submitSearch() {
let group = null;
if (selectedGroup) {
group = selectedGroup;
} else {
const q = normalizeExact(input.value.trim());
const exact = currentResults.find(r => normalizeExact(r.nom) === q);
if (exact) group = exact;
}
if (!group) return;
placeSearchDots(group.cities);
selectedGroup = null;
input.value = '';
hideSuggestions();
}
function updateActive(items) {
items.forEach((el, i) => el.classList.toggle('active', i === activeIndex));
}
function hideSuggestions() {
suggestionsEl.style.display = 'none';
suggestionsEl.innerHTML = '';
currentResults = [];
activeIndex = -1;
}
input.addEventListener('input', () => {
selectedGroup = null;
const q = input.value.trim();
if (q.length < 2) { hideSuggestions(); return; }
searchCities(q);
});
input.addEventListener('keydown', (e) => {
const items = suggestionsEl.querySelectorAll('.suggestion-item');
if (e.key === 'ArrowDown') {
e.preventDefault();
activeIndex = activeIndex < items.length - 1 ? activeIndex + 1 : 0;
updateActive(items);
} else if (e.key === 'ArrowUp') {
e.preventDefault();
activeIndex = activeIndex > 0 ? activeIndex - 1 : items.length - 1;
updateActive(items);
} else if (e.key === 'Enter') {
e.preventDefault();
if (activeIndex >= 0 && currentResults[activeIndex]) {
fillInput(currentResults[activeIndex]);
} else {
submitSearch();
}
} else if (e.key === 'Escape') {
hideSuggestions();
}
});
document.addEventListener('click', (e) => {
if (!e.target.closest('#search-wrapper')) hideSuggestions();
});
</script>
</body>
</html>