Skip to content

Commit

Permalink
Merge pull request #14 from Seshat-Global-History-Databank/remove-pop…
Browse files Browse the repository at this point in the history
…up-when-polity-not-on-legend

Handle popup appearance on click more intuitively
  • Loading branch information
edwardchalstrey1 authored Jul 4, 2024
2 parents 36e3a6f + 1706005 commit 44eede3
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions seshat/apps/core/templates/core/world_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ <h1 class="text-teal federicka-huge" id="sliderDate"></h1>
var variable = document.getElementById('chooseVariable').value;
var selectedYear = document.getElementById('dateSlide').value;
var opacity = document.getElementById('opacitySlide').value;
var atLeastOnePolityHighlighted = false;

// If variable has changed from the previous selection
if (localStorage.getItem('variable') != variable) {
Expand Down Expand Up @@ -623,6 +624,10 @@ <h1 class="text-teal federicka-huge" id="sliderDate"></h1>
// Ignore shapes that are in a union during this year (because we are plotting the union)
if ((parseInt(shape.start_year) <= selectedYearInt && parseInt(shape.end_year) >= selectedYearInt) && !dontPlotMeBecauseImInAUnion.includes(shape.seshat_id)) {

if (shapeWeight > 0){
atLeastOnePolityHighlighted = true;
}

// Format the area float
const formattedArea = parseFloat(shape.area).toLocaleString('en-US', {
minimumFractionDigits: 0,
Expand Down Expand Up @@ -819,24 +824,25 @@ <h1 class="text-teal federicka-huge" id="sliderDate"></h1>

// Listen for the click event on the layer
layer.on('click', function (e) {

// Add the popup to the popup div
document.getElementById('popup').innerHTML = popupContent;
// Set the border colour of the popup div
document.getElementById('popup').style.borderColor = layer.feature.properties.colour;
// Increase the border width of the popup div
document.getElementById('popup').style.borderWidth = '4px';

if (variable == 'polity'){
if (shape.weight === 0) {
// Increase the weight of the clicked layer
newWeight = polityBorderWeightSelected;
this.setStyle({
weight: newWeight
});
});
// Add the popup to the popup div
document.getElementById('popup').innerHTML = popupContent;
// Set the border colour of the popup div
document.getElementById('popup').style.borderColor = layer.feature.properties.colour;
// Increase the border width of the popup div
document.getElementById('popup').style.borderWidth = '4px';
} else {
// Decrease the weight of the clicked layer
newWeight = polityBorderWeight;
// Remove the popup from the popup div
document.getElementById('popup').innerHTML = '';
};
// Update weights in this layer and others of the same polity
map.eachLayer(function (layer) {
Expand Down Expand Up @@ -876,7 +882,14 @@ <h1 class="text-teal federicka-huge" id="sliderDate"></h1>
i++;
});
updateLegend();
};
} else {
// Add the popup to the popup div
document.getElementById('popup').innerHTML = popupContent;
// Set the border colour of the popup div
document.getElementById('popup').style.borderColor = layer.feature.properties.colour;
// Increase the border width of the popup div
document.getElementById('popup').style.borderWidth = '4px';
}
L.DomEvent.stopPropagation(e);
});
}
Expand Down Expand Up @@ -979,6 +992,10 @@ <h1 class="text-teal federicka-huge" id="sliderDate"></h1>
};

adjustScroll();

if (!atLeastOnePolityHighlighted){
document.getElementById('popup').innerHTML = '';
}
}

// Initial plot on page load
Expand Down

0 comments on commit 44eede3

Please sign in to comment.