Skip to content
Merged
Changes from 1 commit
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
65 changes: 39 additions & 26 deletions src/components/DeckGLMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export class DeckGLMap {
private state: DeckMapState;
private popup: MapPopup;
private isResizing = false;
private legendContainer: HTMLElement | null = null;
private savedTopLat: number | null = null;
private correctingCenter = false;

Expand Down Expand Up @@ -4242,6 +4243,7 @@ export class DeckGLMap {
this.state.layers[layer] = (input as HTMLInputElement).checked;
if (layer === 'flights') this.manageAircraftTimer((input as HTMLInputElement).checked);
this.render();
this.updateLegend();
this.onLayerChange?.(layer, (input as HTMLInputElement).checked, 'user');
if (layer === 'ciiChoropleth') {
const ciiLeg = this.container.querySelector('#ciiChoroplethLegend') as HTMLElement | null;
Expand Down Expand Up @@ -4456,44 +4458,44 @@ export class DeckGLMap {
const isLight = getCurrentTheme() === 'light';
const legendItems = SITE_VARIANT === 'tech'
? [
{ shape: shapes.circle(isLight ? 'rgb(22, 163, 74)' : 'rgb(0, 255, 150)'), label: t('components.deckgl.legend.startupHub') },
{ shape: shapes.circle('rgb(100, 200, 255)'), label: t('components.deckgl.legend.techHQ') },
{ shape: shapes.circle(isLight ? 'rgb(180, 120, 0)' : 'rgb(255, 200, 0)'), label: t('components.deckgl.legend.accelerator') },
{ shape: shapes.circle('rgb(150, 100, 255)'), label: t('components.deckgl.legend.cloudRegion') },
{ shape: shapes.square('rgb(136, 68, 255)'), label: t('components.deckgl.legend.datacenter') },
{ shape: shapes.circle(isLight ? 'rgb(22, 163, 74)' : 'rgb(0, 255, 150)'), label: t('components.deckgl.legend.startupHub'), layerKey: 'startupHubs' },
{ shape: shapes.circle('rgb(100, 200, 255)'), label: t('components.deckgl.legend.techHQ'), layerKey: 'techHQs' },
{ shape: shapes.circle(isLight ? 'rgb(180, 120, 0)' : 'rgb(255, 200, 0)'), label: t('components.deckgl.legend.accelerator'), layerKey: 'accelerators' },
{ shape: shapes.circle('rgb(150, 100, 255)'), label: t('components.deckgl.legend.cloudRegion'), layerKey: 'cloudRegions' },
{ shape: shapes.square('rgb(136, 68, 255)'), label: t('components.deckgl.legend.datacenter'), layerKey: 'datacenters' },
]
: SITE_VARIANT === 'finance'
? [
{ shape: shapes.circle('rgb(255, 215, 80)'), label: t('components.deckgl.legend.stockExchange') },
{ shape: shapes.circle('rgb(0, 220, 150)'), label: t('components.deckgl.legend.financialCenter') },
{ shape: shapes.hexagon('rgb(255, 210, 80)'), label: t('components.deckgl.legend.centralBank') },
{ shape: shapes.square('rgb(255, 150, 80)'), label: t('components.deckgl.legend.commodityHub') },
{ shape: shapes.triangle('rgb(80, 170, 255)'), label: t('components.deckgl.legend.waterway') },
{ shape: shapes.circle('rgb(255, 215, 80)'), label: t('components.deckgl.legend.stockExchange'), layerKey: 'stockExchanges' },
{ shape: shapes.circle('rgb(0, 220, 150)'), label: t('components.deckgl.legend.financialCenter'), layerKey: 'financialCenters' },
{ shape: shapes.hexagon('rgb(255, 210, 80)'), label: t('components.deckgl.legend.centralBank'), layerKey: 'centralBanks' },
{ shape: shapes.square('rgb(255, 150, 80)'), label: t('components.deckgl.legend.commodityHub'), layerKey: 'commodityHubs' },
{ shape: shapes.triangle('rgb(80, 170, 255)'), label: t('components.deckgl.legend.waterway'), layerKey: 'waterways' },
]
: SITE_VARIANT === 'happy'
? [
{ shape: shapes.circle('rgb(34, 197, 94)'), label: 'Positive Event' },
{ shape: shapes.circle('rgb(234, 179, 8)'), label: 'Breakthrough' },
{ shape: shapes.circle('rgb(74, 222, 128)'), label: 'Act of Kindness' },
{ shape: shapes.circle('rgb(255, 100, 50)'), label: 'Natural Event' },
{ shape: shapes.square('rgb(34, 180, 100)'), label: 'Happy Country' },
{ shape: shapes.circle('rgb(74, 222, 128)'), label: 'Species Recovery Zone' },
{ shape: shapes.circle('rgb(255, 200, 50)'), label: 'Renewable Installation' },
{ shape: shapes.circle('rgb(160, 100, 255)'), label: t('components.deckgl.legend.aircraft') },
{ shape: shapes.circle('rgb(34, 197, 94)'), label: 'Positive Event', layerKey: 'positiveEvents' },
{ shape: shapes.circle('rgb(234, 179, 8)'), label: 'Breakthrough', layerKey: '' },
{ shape: shapes.circle('rgb(74, 222, 128)'), label: 'Act of Kindness', layerKey: 'kindness' },
{ shape: shapes.circle('rgb(255, 100, 50)'), label: 'Natural Event', layerKey: 'natural' },
{ shape: shapes.square('rgb(34, 180, 100)'), label: 'Happy Country', layerKey: 'happiness' },
{ shape: shapes.circle('rgb(74, 222, 128)'), label: 'Species Recovery Zone', layerKey: 'speciesRecovery' },
{ shape: shapes.circle('rgb(255, 200, 50)'), label: 'Renewable Installation', layerKey: 'renewableInstallations' },
{ shape: shapes.circle('rgb(160, 100, 255)'), label: t('components.deckgl.legend.aircraft'), layerKey: '' },
Comment thread
koala73 marked this conversation as resolved.
Outdated
]
: [
{ shape: shapes.circle('rgb(255, 68, 68)'), label: t('components.deckgl.legend.highAlert') },
{ shape: shapes.circle('rgb(255, 165, 0)'), label: t('components.deckgl.legend.elevated') },
{ shape: shapes.circle(isLight ? 'rgb(180, 120, 0)' : 'rgb(255, 255, 0)'), label: t('components.deckgl.legend.monitoring') },
{ shape: shapes.triangle('rgb(68, 136, 255)'), label: t('components.deckgl.legend.base') },
{ shape: shapes.hexagon(isLight ? 'rgb(180, 120, 0)' : 'rgb(255, 220, 0)'), label: t('components.deckgl.legend.nuclear') },
{ shape: shapes.square('rgb(136, 68, 255)'), label: t('components.deckgl.legend.datacenter') },
{ shape: shapes.circle('rgb(160, 100, 255)'), label: t('components.deckgl.legend.aircraft') },
{ shape: shapes.circle('rgb(255, 68, 68)'), label: t('components.deckgl.legend.highAlert'), layerKey: 'hotspots' },
{ shape: shapes.circle('rgb(255, 165, 0)'), label: t('components.deckgl.legend.elevated'), layerKey: 'hotspots' },
{ shape: shapes.circle(isLight ? 'rgb(180, 120, 0)' : 'rgb(255, 255, 0)'), label: t('components.deckgl.legend.monitoring'), layerKey: 'hotspots' },
{ shape: shapes.triangle('rgb(68, 136, 255)'), label: t('components.deckgl.legend.base'), layerKey: 'bases' },
{ shape: shapes.hexagon(isLight ? 'rgb(180, 120, 0)' : 'rgb(255, 220, 0)'), label: t('components.deckgl.legend.nuclear'), layerKey: 'nuclear' },
{ shape: shapes.square('rgb(136, 68, 255)'), label: t('components.deckgl.legend.datacenter'), layerKey: 'datacenters' },
{ shape: shapes.circle('rgb(160, 100, 255)'), label: t('components.deckgl.legend.aircraft'), layerKey: 'flights' },
];

legend.innerHTML = `
<span class="legend-label-title">${t('components.deckgl.legend.title')}</span>
${legendItems.map(({ shape, label }) => `<span class="legend-item">${shape}<span class="legend-label">${label}</span></span>`).join('')}
${legendItems.map(({ shape, label, layerKey }) => `<span class="legend-item"${layerKey ? ` data-layer="${layerKey}"` : ''}>${shape}<span class="legend-label">${label}</span></span>`).join('')}
`;

// CII choropleth gradient legend (shown when layer is active)
Expand All @@ -4513,6 +4515,17 @@ export class DeckGLMap {
legend.appendChild(ciiLegend);

this.container.appendChild(legend);
this.legendContainer = legend;
this.updateLegend();
}

private updateLegend(): void {
if (!this.legendContainer) return;
this.legendContainer.querySelectorAll<HTMLElement>('.legend-item[data-layer]').forEach(item => {
const layerKey = item.dataset.layer as keyof MapLayers;
const isVisible = this.state.layers[layerKey] ?? false;
item.style.display = isVisible ? '' : 'none';
});
}

// Public API methods (matching MapComponent interface)
Expand Down
Loading