Skip to content

Commit

Permalink
Add colors to sidebar dependent on person type
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Ory committed Feb 7, 2025
1 parent 35e0054 commit 97f2af2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
8 changes: 8 additions & 0 deletions scripts-listeners.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@
const clusterMarkers = event.layer.getAllChildMarkers();
updateSidebarWithClusterMarkers(clusterMarkers);
});

// Ensure the sidebar updates when clusters spiderfy (expand)
markerCluster.on('spiderfied', function (event) {
const clusterMarkers = event.markers; // Get expanded markers

// Update the sidebar with the new visible markers
updateSidebarWithClusterMarkers(clusterMarkers);
});

map.on('moveend zoomend', () => {
const input = document.querySelector("#input");
Expand Down
4 changes: 2 additions & 2 deletions scripts-local.html
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@
});

if (!skipSidebarUpdate) {
updateMarkerSidebar({ text, personprocessed, locationprocessed, daterange, description }, true, eventid);
updateMarkerSidebar({ text, personID, personprocessed, locationprocessed, daterange, description }, true, eventid);
}
} else {
markersToRemove.add(marker);
Expand Down Expand Up @@ -811,7 +811,7 @@
if (!visibleMarkers.has(marker)) {
markerCluster.addLayer(marker);
}
updateMarkerSidebar({ text, personprocessed, locationprocessed, daterange, description }, true, eventid);
updateMarkerSidebar({ text, personID, personprocessed, locationprocessed, daterange, description }, true, eventid);
} else if (visibleMarkers.has(marker)) {
removedMarkers.add(marker);
}
Expand Down
24 changes: 21 additions & 3 deletions scripts/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
tableBody.innerHTML = '';

// Add visible markers to the sidebar
visibleMarkers.forEach(({ text, personprocessed, locationprocessed, daterange, description, eventid }) => {
updateMarkerSidebar({ text, personprocessed, locationprocessed, daterange, description }, true, eventid);
visibleMarkers.forEach(({ text, personID, personprocessed, locationprocessed, daterange, description, eventid }) => {
updateMarkerSidebar({ text, personID, personprocessed, locationprocessed, daterange, description }, true, eventid);
});
}

function updateMarkerSidebar({ text, personprocessed, locationprocessed, daterange, description }, show, eventid) {
function updateMarkerSidebar({ text, personID, personprocessed, locationprocessed, daterange, description }, show, eventid) {
// Sanitize eventid for use as a DOM id
const sanitizedEventId = sanitizeEventId(eventid);

Expand All @@ -27,6 +27,23 @@
const row = document.createElement('tr');
row.id = `marker-${sanitizedEventId}`; // Use sanitized id for the row

// Assign background color based on person type
const type = personID ? personID.substring(0, 3) : '';


let backgroundColor = 'rgba(68, 1, 84, 0.1)'; // Composer (BCO)

if (type === 'BMU') {
backgroundColor = 'rgba(35, 237, 92, 0.1)'; // Musician (BMU)
} else if (type === 'BNO') {
backgroundColor = 'rgba(253, 231, 37, 0.1)'; // Default: Non-musician (BNO)
}

// Set row styling
row.style.backgroundColor = backgroundColor;
row.style.padding = '8px';
row.style.borderBottom = '1px solid #ddd';

// Create a single cell for the row
const cell = document.createElement('td');
const truncatedDescription = description
Expand Down Expand Up @@ -110,6 +127,7 @@
if (markerData) {
updateMarkerSidebar({
text: markerData.text,
personID: markerData.personID,
personprocessed: markerData.personprocessed,
locationprocessed: markerData.locationprocessed,
daterange: markerData.daterange,
Expand Down

0 comments on commit 97f2af2

Please sign in to comment.