Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve polyline order in legend #133

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions scripts/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,9 @@ $(window).on('load', function() {
* Adds polylines to the map
*/
function processPolylines(p) {

var lines = Array(p.length); // array to keep track of loaded geojson polylines

if (!p || p.length == 0) return;

var pos = (getSetting('_polylinesLegendPos') == 'off')
Expand Down Expand Up @@ -814,20 +817,19 @@ $(window).on('load', function() {
}
}

line = L.polyline(latlng, {
var line = L.polyline(latlng, {
color: (p[index]['Color'] == '') ? 'grey' : p[index]['Color'],
weight: trySetting('_polylinesWeight', 2),
pane: 'shadowPane'
}).addTo(map);
})

lines[index] = line;
line.addTo(map);

if (p[index]['Description'] && p[index]['Description'] != '') {
line.bindPopup(p[index]['Description']);
}

polylinesLegend.addOverlay(line,
'<i class="color-line" style="background-color:' + p[index]['Color']
+ '"></i> ' + p[index]['Display Name']);

if (index == 0) {
if (polylinesLegend._container) {
polylinesLegend._container.id = 'polylines-legend';
Expand All @@ -850,8 +852,15 @@ $(window).on('load', function() {
}
}

if (p.length == index + 1) {
if ( lines.filter(Boolean).length == p.length ) { // only if all polylines loaded
completePolylines = true;

// Add polylines to the legend - we do this after all lines are loaded
for (let j = 0; j < p.length; j++) {
polylinesLegend.addOverlay(lines[j],
'<i class="color-line" style="background-color:' + p[j]['Color']
+ '"></i> ' + p[j]['Display Name']);
}
}
};
}(i));
Expand Down