Spaces:
Running
on
Zero
Running
on
Zero
Joffrey Thomas
commited on
Commit
·
7f53d2e
1
Parent(s):
664783c
better images + full screen
Browse files
app.py
CHANGED
|
@@ -202,9 +202,9 @@ def pick_random_location(difficulty: str) -> Dict[str, float]:
|
|
| 202 |
def street_view_image_url(lat: float, lng: float) -> str:
|
| 203 |
if not GOOGLE_MAPS_API_KEY:
|
| 204 |
# Fallback placeholder to avoid blank image when key is missing
|
| 205 |
-
return "https://picsum.photos/
|
| 206 |
return (
|
| 207 |
-
f"https://maps.googleapis.com/maps/api/streetview?size=
|
| 208 |
)
|
| 209 |
|
| 210 |
|
|
@@ -298,6 +298,9 @@ def build_street_html(image_url: str) -> str:
|
|
| 298 |
base = """
|
| 299 |
<div id="image-container" style="position:relative;max-width:960px;margin:0 auto;">
|
| 300 |
<img id="street-image" src="__IMG_URL__" style="width:100%;height:auto;border-radius:8px;box-shadow:0 4px 6px rgba(0,0,0,0.1)" />
|
|
|
|
|
|
|
|
|
|
| 301 |
<div id="mini-map-wrap" style="transition:all 0.3s ease;position:absolute;right:10px;bottom:10px;border:2px solid #fff;border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,0.2);background:#fff;">
|
| 302 |
<div id="mini-map" style="width:100%;height:100%;cursor:pointer"></div>
|
| 303 |
<div id="map-controls" style="position:absolute;right:8px;top:8px;display:flex;gap:6px;z-index:5;">
|
|
@@ -593,6 +596,38 @@ APP_BOOT_JS = """
|
|
| 593 |
} catch (e) { log('Popup map init error', e); }
|
| 594 |
});
|
| 595 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 596 |
function initMapControlsIfPresent() {
|
| 597 |
const plusBtn = document.getElementById('map-size-plus');
|
| 598 |
const minusBtn = document.getElementById('map-size-minus');
|
|
@@ -629,11 +664,12 @@ APP_BOOT_JS = """
|
|
| 629 |
updateSize();
|
| 630 |
log('Map controls initialized');
|
| 631 |
}
|
| 632 |
-
const obs = new MutationObserver(() => { initMiniMapIfPresent(); initPopupIfPresent(); initMapControlsIfPresent(); });
|
| 633 |
obs.observe(document.documentElement, { childList: true, subtree: true });
|
| 634 |
initMiniMapIfPresent();
|
| 635 |
initPopupIfPresent();
|
| 636 |
initMapControlsIfPresent();
|
|
|
|
| 637 |
}
|
| 638 |
""".replace("__GMAPS_KEY__", GOOGLE_MAPS_API_KEY or '')
|
| 639 |
|
|
|
|
| 202 |
def street_view_image_url(lat: float, lng: float) -> str:
|
| 203 |
if not GOOGLE_MAPS_API_KEY:
|
| 204 |
# Fallback placeholder to avoid blank image when key is missing
|
| 205 |
+
return "https://picsum.photos/1920/1080"
|
| 206 |
return (
|
| 207 |
+
f"https://maps.googleapis.com/maps/api/streetview?size=1920x1080&location={lat},{lng}&fov=90&pitch=0&key={GOOGLE_MAPS_API_KEY}"
|
| 208 |
)
|
| 209 |
|
| 210 |
|
|
|
|
| 298 |
base = """
|
| 299 |
<div id="image-container" style="position:relative;max-width:960px;margin:0 auto;">
|
| 300 |
<img id="street-image" src="__IMG_URL__" style="width:100%;height:auto;border-radius:8px;box-shadow:0 4px 6px rgba(0,0,0,0.1)" />
|
| 301 |
+
<button id="fullscreen-btn" title="Toggle Fullscreen" style="position:absolute;top:10px;right:10px;z-index:10;background:rgba(0,0,0,0.5);border:none;color:white;padding:8px;border-radius:4px;cursor:pointer;line-height:0;">
|
| 302 |
+
<!-- SVG icon will be injected by JS -->
|
| 303 |
+
</button>
|
| 304 |
<div id="mini-map-wrap" style="transition:all 0.3s ease;position:absolute;right:10px;bottom:10px;border:2px solid #fff;border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,0.2);background:#fff;">
|
| 305 |
<div id="mini-map" style="width:100%;height:100%;cursor:pointer"></div>
|
| 306 |
<div id="map-controls" style="position:absolute;right:8px;top:8px;display:flex;gap:6px;z-index:5;">
|
|
|
|
| 596 |
} catch (e) { log('Popup map init error', e); }
|
| 597 |
});
|
| 598 |
}
|
| 599 |
+
function initFullscreenButtonIfPresent() {
|
| 600 |
+
log('initFullscreenButtonIfPresent called');
|
| 601 |
+
const btn = document.getElementById('fullscreen-btn');
|
| 602 |
+
const img = document.getElementById('street-image');
|
| 603 |
+
if (!btn || !img || btn.dataset.initialized === '1') return;
|
| 604 |
+
|
| 605 |
+
const enterIcon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>';
|
| 606 |
+
const exitIcon = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 0-2-2h-3m-6 0H3a2 2 0 0 0-2 2v3"/></svg>';
|
| 607 |
+
|
| 608 |
+
btn.innerHTML = enterIcon;
|
| 609 |
+
|
| 610 |
+
btn.addEventListener('click', () => {
|
| 611 |
+
if (!document.fullscreenElement) {
|
| 612 |
+
img.requestFullscreen().catch(err => {
|
| 613 |
+
log('Fullscreen error:', err);
|
| 614 |
+
});
|
| 615 |
+
} else {
|
| 616 |
+
document.exitFullscreen();
|
| 617 |
+
}
|
| 618 |
+
});
|
| 619 |
+
|
| 620 |
+
document.addEventListener('fullscreenchange', () => {
|
| 621 |
+
if (document.fullscreenElement === img) {
|
| 622 |
+
btn.innerHTML = exitIcon;
|
| 623 |
+
} else {
|
| 624 |
+
btn.innerHTML = enterIcon;
|
| 625 |
+
}
|
| 626 |
+
});
|
| 627 |
+
|
| 628 |
+
btn.dataset.initialized = '1';
|
| 629 |
+
log('Fullscreen button initialized');
|
| 630 |
+
}
|
| 631 |
function initMapControlsIfPresent() {
|
| 632 |
const plusBtn = document.getElementById('map-size-plus');
|
| 633 |
const minusBtn = document.getElementById('map-size-minus');
|
|
|
|
| 664 |
updateSize();
|
| 665 |
log('Map controls initialized');
|
| 666 |
}
|
| 667 |
+
const obs = new MutationObserver(() => { initMiniMapIfPresent(); initPopupIfPresent(); initMapControlsIfPresent(); initFullscreenButtonIfPresent(); });
|
| 668 |
obs.observe(document.documentElement, { childList: true, subtree: true });
|
| 669 |
initMiniMapIfPresent();
|
| 670 |
initPopupIfPresent();
|
| 671 |
initMapControlsIfPresent();
|
| 672 |
+
initFullscreenButtonIfPresent();
|
| 673 |
}
|
| 674 |
""".replace("__GMAPS_KEY__", GOOGLE_MAPS_API_KEY or '')
|
| 675 |
|