improved maps and browse events, removed search
This commit is contained in:
1 parent
55e28fd0af
commit
75d5d0bb0f
11 files changed
+387
-392
No files matched your search
+34
-19
@@ -29,12 +29,20 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
function saveLastLocation(lat, lon) {
|
||||
function saveLastLocation(lat, lon, name) {
|
||||
try {
|
||||
if (window.localStorage) localStorage.setItem(LAST_LOCATION_KEY, JSON.stringify({ lat: lat, lon: lon }));
|
||||
if (window.localStorage) localStorage.setItem(LAST_LOCATION_KEY, JSON.stringify({ lat: lat, lon: lon, name: name || null }));
|
||||
} catch (e) { /* localStorage disabled/unavailable — nothing to persist to */ }
|
||||
}
|
||||
|
||||
// Mirrors whatever setUserLocation/setSource just resolved (a searched
|
||||
// place name, or nothing for GPS/a map click) into the location search
|
||||
// field, so it doesn't just sit there blank after the fact.
|
||||
function setLocationInputValue(name) {
|
||||
var input = document.getElementById('locationSearch');
|
||||
if (input) input.value = name || '';
|
||||
}
|
||||
|
||||
function setLocateStatus(statusEl, text, isError) {
|
||||
if (!statusEl) return;
|
||||
statusEl.textContent = text;
|
||||
@@ -482,9 +490,10 @@
|
||||
});
|
||||
}
|
||||
|
||||
function setUserLocation(lat, lon, statusText) {
|
||||
function setUserLocation(lat, lon, statusText, placeName) {
|
||||
state.userLoc = [lat, lon];
|
||||
saveLastLocation(lat, lon);
|
||||
saveLastLocation(lat, lon, placeName);
|
||||
setLocationInputValue(placeName);
|
||||
|
||||
if (limit) rebuildMarkers(nearest([lat, lon], allEvents.slice(), limit));
|
||||
|
||||
@@ -512,7 +521,7 @@
|
||||
// A manual search/click may have already happened while this
|
||||
// (silent, permission-check-triggered) lookup was still resolving.
|
||||
if (isAutoCheck && manualLocationSet) return;
|
||||
setUserLocation(pos.coords.latitude, pos.coords.longitude, limit ? ('Showing the ' + limit + ' nearest events') : 'Showing events near you');
|
||||
setUserLocation(pos.coords.latitude, pos.coords.longitude, limit ? ('Showing the ' + limit + ' nearest events') : 'Showing events near you', 'Your location');
|
||||
}, function () {
|
||||
setLocateStatus(statusEl, "Couldn't get your location", true);
|
||||
}, { timeout: 8000 });
|
||||
@@ -540,7 +549,7 @@
|
||||
setLocateStatus(statusEl, 'Could not find "' + query + '"', true);
|
||||
return;
|
||||
}
|
||||
setUserLocation(parseFloat(results[0].lat), parseFloat(results[0].lon), limit ? ('Showing the ' + limit + ' nearest events') : 'Showing events near you');
|
||||
setUserLocation(parseFloat(results[0].lat), parseFloat(results[0].lon), limit ? ('Showing the ' + limit + ' nearest events') : 'Showing events near you', results[0].display_name);
|
||||
})
|
||||
.catch(function () {
|
||||
setLocateStatus(statusEl, 'Location search failed', true);
|
||||
@@ -554,7 +563,7 @@
|
||||
var lastLocation = loadLastLocation();
|
||||
if (lastLocation) {
|
||||
manualLocationSet = true;
|
||||
setUserLocation(lastLocation.lat, lastLocation.lon, limit ? ('Showing the ' + limit + ' nearest events') : 'Showing events near you');
|
||||
setUserLocation(lastLocation.lat, lastLocation.lon, limit ? ('Showing the ' + limit + ' nearest events') : 'Showing events near you', lastLocation.name);
|
||||
} else if (navigator.permissions && navigator.permissions.query) {
|
||||
// If the user already granted location access (on this or an earlier
|
||||
// visit), center on it automatically — this only *reads* the current
|
||||
@@ -603,10 +612,6 @@
|
||||
attributionControl: true,
|
||||
center: state.source,
|
||||
zoom: opts.zoom || 11,
|
||||
// This map already owns the whole viewport (no surrounding page to
|
||||
// protect from trapped scroll/pinch), so gesture handling would only
|
||||
// make one-finger dragging feel unresponsive for no benefit.
|
||||
gestureHandling: false,
|
||||
onMarkerClick: function (ev) { highlightRow(ev.id); }
|
||||
});
|
||||
var map = result ? result.map : null;
|
||||
@@ -724,8 +729,9 @@
|
||||
// new point itself is inside it, so the check is deliberately
|
||||
// conservative: reload whenever full coverage isn't guaranteed,
|
||||
// rather than risk silently showing an incomplete result.
|
||||
function setSource(lat, lon) {
|
||||
saveLastLocation(lat, lon);
|
||||
function setSource(lat, lon, placeName) {
|
||||
saveLastLocation(lat, lon, placeName);
|
||||
setLocationInputValue(placeName);
|
||||
var distFromOriginal = distanceKm(originalCenter[0], originalCenter[1], lat, lon);
|
||||
if (distFromOriginal + state.rangeKm > maxRangeKm) {
|
||||
var url = new URL(window.location.href);
|
||||
@@ -743,13 +749,15 @@
|
||||
}
|
||||
|
||||
if (map) {
|
||||
map.on('click', function (e) { manualLocationSet = true; setSource(e.latlng.lat, e.latlng.lng); });
|
||||
// A clicked point has no place name — clears any stale searched name
|
||||
// that would otherwise sit next to coordinates it no longer describes.
|
||||
map.on('click', function (e) { manualLocationSet = true; setSource(e.latlng.lat, e.latlng.lng, null); });
|
||||
}
|
||||
if (sourceMarker) {
|
||||
sourceMarker.on('dragend', function () {
|
||||
manualLocationSet = true;
|
||||
var ll = sourceMarker.getLatLng();
|
||||
setSource(ll.lat, ll.lng);
|
||||
setSource(ll.lat, ll.lng, null);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -792,7 +800,7 @@
|
||||
setLocateStatus(statusEl, 'Could not find "' + query + '"', true);
|
||||
return;
|
||||
}
|
||||
setSource(parseFloat(results[0].lat), parseFloat(results[0].lon));
|
||||
setSource(parseFloat(results[0].lat), parseFloat(results[0].lon), results[0].display_name);
|
||||
})
|
||||
.catch(function () {
|
||||
setLocateStatus(statusEl, 'Location search failed', true);
|
||||
@@ -811,7 +819,7 @@
|
||||
// A manual search/click/drag may have already happened while this
|
||||
// (silent, permission-check-triggered) lookup was still resolving.
|
||||
if (isAutoCheck && manualLocationSet) return;
|
||||
setSource(pos.coords.latitude, pos.coords.longitude);
|
||||
setSource(pos.coords.latitude, pos.coords.longitude, 'Your location');
|
||||
}, function () {
|
||||
setLocateStatus(statusEl, "Couldn't get your location", true);
|
||||
}, { timeout: 8000 });
|
||||
@@ -820,6 +828,13 @@
|
||||
var locateBtn = document.getElementById('locateBtn');
|
||||
if (locateBtn) locateBtn.addEventListener('click', function () { manualLocationSet = true; requestLocation(false); });
|
||||
|
||||
// A page load landing with an explicit ?lat= (e.g. after setSource's
|
||||
// own reload-threshold redirect, or a shared link) can't carry the
|
||||
// place name in the URL — fill the field back in from localStorage
|
||||
// regardless of whether that load also needs the redirect below.
|
||||
var savedForName = loadLastLocation();
|
||||
if (savedForName && savedForName.name) setLocationInputValue(savedForName.name);
|
||||
|
||||
// An explicit ?lat=/&lon= in the URL (e.g. a shared link) always wins.
|
||||
// Otherwise, a remembered search/geolocation takes priority over asking
|
||||
// the browser again — restoring it counts as the user's own manual
|
||||
@@ -827,10 +842,10 @@
|
||||
// clobber it. If it's far enough from this page's own server-resolved
|
||||
// center, setSource's own reload-threshold logic kicks in as usual.
|
||||
var urlHasExplicitLocation = /[?&]lat=/.test(window.location.search);
|
||||
var lastLocation = urlHasExplicitLocation ? null : loadLastLocation();
|
||||
var lastLocation = urlHasExplicitLocation ? null : savedForName;
|
||||
if (lastLocation) {
|
||||
manualLocationSet = true;
|
||||
setSource(lastLocation.lat, lastLocation.lon);
|
||||
setSource(lastLocation.lat, lastLocation.lon, lastLocation.name);
|
||||
} else if (navigator.permissions && navigator.permissions.query) {
|
||||
navigator.permissions.query({ name: 'geolocation' }).then(function (status) {
|
||||
if (status.state === 'granted') requestLocation(true);
|
||||
|
||||
Reference in new issue
Block a user