feat: validate user availability
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
#single-map {
|
||||
height: 50vh; /* Smaller height on mobile */
|
||||
}
|
||||
|
||||
body.sidebar-open .map-controls {
|
||||
display: none;
|
||||
}
|
||||
@@ -98,7 +97,6 @@
|
||||
.dashboard-container {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
#single-map {
|
||||
height: 100%;
|
||||
}
|
||||
@@ -134,12 +132,6 @@
|
||||
<button class="control-button" onclick="refreshMap()" title="Refresh Map">
|
||||
<i class="fas fa-sync-alt"></i>
|
||||
</button>
|
||||
<button class="control-button" onclick="fitAllMarkers()" title="Fit All Markers">
|
||||
<i class="fas fa-expand-arrows-alt"></i>
|
||||
</button>
|
||||
<button class="control-button" onclick="clearAllMarkers()" title="Clear All Markers">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div id="single-map"></div>
|
||||
|
||||
@@ -202,26 +194,17 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Global variables - only one set
|
||||
let theMap = null;
|
||||
let markerLayer = null;
|
||||
let popup = null;
|
||||
let initialized = false;
|
||||
|
||||
// Clean initialization
|
||||
function initializeMap() {
|
||||
if (initialized || !window.ol) {
|
||||
console.log("Map already initialized or OpenLayers not ready");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Initializing single map...");
|
||||
if (initialized || !window.ol) return;
|
||||
|
||||
try {
|
||||
// Calgary coordinates
|
||||
const center = ol.proj.fromLonLat([-114.0719, 51.0447]);
|
||||
|
||||
// Create the ONE AND ONLY map
|
||||
theMap = new ol.Map({
|
||||
target: "single-map",
|
||||
layers: [
|
||||
@@ -235,7 +218,6 @@
|
||||
}),
|
||||
});
|
||||
|
||||
// Create popup
|
||||
popup = new ol.Overlay({
|
||||
element: document.getElementById("popup"),
|
||||
positioning: "bottom-center",
|
||||
@@ -244,13 +226,11 @@
|
||||
});
|
||||
theMap.addOverlay(popup);
|
||||
|
||||
// Close popup handler
|
||||
document.getElementById("popup-closer").onclick = function () {
|
||||
popup.setPosition(undefined);
|
||||
return false;
|
||||
};
|
||||
|
||||
// Create marker layer
|
||||
markerLayer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector(),
|
||||
style: new ol.style.Style({
|
||||
@@ -264,26 +244,18 @@
|
||||
});
|
||||
theMap.addLayer(markerLayer);
|
||||
|
||||
// Click handler
|
||||
theMap.on("click", function (event) {
|
||||
const feature = theMap.forEachFeatureAtPixel(
|
||||
event.pixel,
|
||||
function (feature) {
|
||||
return feature;
|
||||
}
|
||||
);
|
||||
|
||||
const feature = theMap.forEachFeatureAtPixel(event.pixel, f => f);
|
||||
if (feature && feature.get("address_data")) {
|
||||
const data = feature.get("address_data");
|
||||
document.getElementById("popup-content").innerHTML = `
|
||||
<div class="text-sm">
|
||||
<h4 class="font-semibold text-gray-900 mb-2">Address Details</h4>
|
||||
<p><strong>Address:</strong> ${data.address}</p>
|
||||
<p><strong>House #:</strong> ${data.house_number}</p>
|
||||
<p><strong>Street:</strong> ${data.street_name} ${data.street_type}</p>
|
||||
<p><strong>ID:</strong> ${data.address_id}</p>
|
||||
</div>
|
||||
`;
|
||||
<h4 class="font-semibold text-gray-900 mb-2">Address Details</h4>
|
||||
<p><strong>Address:</strong> ${data.address}</p>
|
||||
<p><strong>House #:</strong> ${data.house_number}</p>
|
||||
<p><strong>Street:</strong> ${data.street_name} ${data.street_type}</p>
|
||||
<p><strong>ID:</strong> ${data.address_id}</p>
|
||||
</div>`;
|
||||
popup.setPosition(event.coordinate);
|
||||
} else {
|
||||
popup.setPosition(undefined);
|
||||
@@ -291,45 +263,32 @@
|
||||
});
|
||||
|
||||
initialized = true;
|
||||
console.log("Map initialized successfully");
|
||||
|
||||
// Load markers
|
||||
setTimeout(loadMarkers, 500);
|
||||
} catch (error) {
|
||||
console.error("Map initialization error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Load validated addresses
|
||||
async function loadMarkers() {
|
||||
try {
|
||||
const response = await fetch("/api/validated-addresses");
|
||||
const addresses = await response.json();
|
||||
|
||||
console.log(`Loading ${addresses.length} addresses`);
|
||||
document.getElementById("marker-count").textContent = `${addresses.length} on map`;
|
||||
|
||||
// Clear existing markers
|
||||
markerLayer.getSource().clear();
|
||||
|
||||
// Add new markers
|
||||
const features = [];
|
||||
addresses.forEach((addr) => {
|
||||
if (addr.longitude && addr.latitude) {
|
||||
const coords = ol.proj.fromLonLat([addr.longitude, addr.latitude]);
|
||||
const feature = new ol.Feature({
|
||||
geometry: new ol.geom.Point(coords),
|
||||
address_data: addr,
|
||||
});
|
||||
features.push(feature);
|
||||
}
|
||||
});
|
||||
const features = addresses
|
||||
.filter(addr => addr.longitude && addr.latitude)
|
||||
.map(addr => new ol.Feature({
|
||||
geometry: new ol.geom.Point(ol.proj.fromLonLat([addr.longitude, addr.latitude])),
|
||||
address_data: addr,
|
||||
}));
|
||||
|
||||
markerLayer.getSource().addFeatures(features);
|
||||
|
||||
if (features.length > 0) {
|
||||
const extent = markerLayer.getSource().getExtent();
|
||||
theMap.getView().fit(extent, { padding: [20, 20, 20, 20] });
|
||||
theMap.getView(extent, { padding: [20, 20, 20, 20] });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error loading markers:", error);
|
||||
@@ -337,45 +296,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Control functions
|
||||
function refreshMap() {
|
||||
const view = theMap.getView();
|
||||
const calgaryCenter = ol.proj.fromLonLat([-114.0719, 51.0447]); // Downtown Calgary
|
||||
view.setCenter(calgaryCenter);
|
||||
view.setZoom(11); // your default zoom leve
|
||||
loadMarkers();
|
||||
}
|
||||
|
||||
function fitAllMarkers() {
|
||||
if (markerLayer && markerLayer.getSource().getFeatures().length > 0) {
|
||||
const extent = markerLayer.getSource().getExtent();
|
||||
theMap.getView().fit(extent, { padding: [20, 20, 20, 20] });
|
||||
}
|
||||
}
|
||||
|
||||
function clearAllMarkers() {
|
||||
if (markerLayer) {
|
||||
markerLayer.getSource().clear();
|
||||
}
|
||||
if (popup) {
|
||||
popup.setPosition(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize when ready
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
setTimeout(initializeMap, 1000);
|
||||
});
|
||||
|
||||
// Listen for sidebar state changes to manage map controls visibility
|
||||
function handleSidebarToggle() {
|
||||
const sidebar = document.getElementById('sidebar');
|
||||
const body = document.body;
|
||||
|
||||
if (sidebar && sidebar.classList.contains('active')) {
|
||||
body.classList.add('sidebar-open');
|
||||
} else {
|
||||
body.classList.remove('sidebar-open');
|
||||
}
|
||||
document.body.classList.toggle('sidebar-open', sidebar && sidebar.classList.contains('active'));
|
||||
}
|
||||
|
||||
// Override the original toggleSidebar function to handle map controls
|
||||
if (typeof window.toggleSidebar === 'function') {
|
||||
const originalToggleSidebar = window.toggleSidebar;
|
||||
window.toggleSidebar = function() {
|
||||
@@ -384,4 +321,4 @@
|
||||
};
|
||||
}
|
||||
</script>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user