Add url parameters to /map to support zoomed view

This commit is contained in:
Joel Krauska
2025-09-30 17:56:35 -07:00
parent 40c5d4e291
commit c7f5467acb
2 changed files with 82 additions and 1 deletions

View File

@@ -27,6 +27,22 @@
.filter-checkbox {
margin: 0 10px;
}
#share-button {
margin-left: 20px;
padding: 5px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
#share-button:hover {
background-color: #45a049;
}
#share-button:active {
background-color: #3d8b40;
}
.blinking-tooltip {
background: white;
color: black;
@@ -42,6 +58,9 @@
<div id="filter-container">
<input type="checkbox" class="filter-checkbox" id="filter-routers-only"> Show Routers Only
</div>
<div style="text-align: center; margin-top: 5px;">
<button id="share-button" onclick="shareCurrentView()">🔗 Share This View</button>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
@@ -58,6 +77,17 @@
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
// Custom view from URL parameters
{% if custom_view %}
var customView = {
lat: {{ custom_view.lat }},
lng: {{ custom_view.lng }},
zoom: {{ custom_view.zoom }}
};
{% else %}
var customView = null;
{% endif %}
// ---- Node Data ----
var markers = {};
var markerById = {};
@@ -155,7 +185,13 @@
[{{ site_config["site"]["map_top_left_lat"] }}, {{ site_config["site"]["map_top_left_lon"] }}],
[{{ site_config["site"]["map_bottom_right_lat"] }}, {{ site_config["site"]["map_bottom_right_lon"] }}]
];
map.fitBounds(bayAreaBounds);
// Apply custom view or default bounds
if (customView) {
map.setView([customView.lat, customView.lng], customView.zoom);
} else {
map.fitBounds(bayAreaBounds);
}
// ---- Filters ----
let filterContainer = document.getElementById("filter-container");
@@ -341,6 +377,32 @@
else startPacketFetcher();
});
// ---- Share Current View ----
function shareCurrentView() {
const center = map.getCenter();
const zoom = map.getZoom();
const lat = center.lat.toFixed(6);
const lng = center.lng.toFixed(6);
const shareUrl = `${window.location.origin}/map?lat=${lat}&lng=${lng}&zoom=${zoom}`;
// Copy to clipboard
navigator.clipboard.writeText(shareUrl).then(() => {
const button = document.getElementById('share-button');
const originalText = button.textContent;
button.textContent = '✓ Link Copied!';
button.style.backgroundColor = '#2196F3';
setTimeout(() => {
button.textContent = originalText;
button.style.backgroundColor = '#4CAF50';
}, 2000);
}).catch(err => {
// Fallback for older browsers
alert('Share this link:\n' + shareUrl);
});
}
// ---- Initialize ----
if (mapInterval > 0) startPacketFetcher();
</script>

View File

@@ -1135,11 +1135,30 @@ async def map(request):
for node in nodes:
if hasattr(node, "last_update") and isinstance(node.last_update, datetime.datetime):
node.last_update = node.last_update.isoformat()
# Parse optional URL parameters for custom view
map_center_lat = request.query.get("lat")
map_center_lng = request.query.get("lng")
map_zoom = request.query.get("zoom")
# Validate and convert parameters if provided
custom_view = None
if map_center_lat and map_center_lng:
try:
lat = float(map_center_lat)
lng = float(map_center_lng)
zoom = int(map_zoom) if map_zoom else 13
custom_view = {"lat": lat, "lng": lng, "zoom": zoom}
except (ValueError, TypeError):
# Invalid parameters, ignore and use defaults
pass
template = env.get_template("map.html")
return web.Response(
text=template.render(
nodes=nodes,
custom_view=custom_view,
site_config=CONFIG,
SOFTWARE_RELEASE=SOFTWARE_RELEASE),
content_type="text/html",