adjusts display issues of world map on admin dash

This commit is contained in:
2026-06-28 08:29:32 +00:00
parent 77d1c04d86
commit db2ebd23fb
2 changed files with 26 additions and 4 deletions
Binary file not shown.
@@ -1,4 +1,4 @@
import { Component, OnInit, inject, AfterViewInit, OnDestroy, ViewChild, ElementRef, NgZone } from '@angular/core'; import { Component, OnInit, inject, AfterViewChecked, OnDestroy, ViewChild, ElementRef, NgZone } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { Chart, registerables } from 'chart.js'; import { Chart, registerables } from 'chart.js';
@@ -25,7 +25,7 @@ Chart.register(...registerables);
templateUrl: './admin-stats-dashboard.component.html', templateUrl: './admin-stats-dashboard.component.html',
styleUrl: './admin-stats-dashboard.component.scss', styleUrl: './admin-stats-dashboard.component.scss',
}) })
export class AdminStatsDashboardComponent implements OnInit, AfterViewInit, OnDestroy { export class AdminStatsDashboardComponent implements OnInit, AfterViewChecked, OnDestroy {
private readonly statsService: StatsService = inject(StatsService); private readonly statsService: StatsService = inject(StatsService);
private readonly ngZone = inject(NgZone); private readonly ngZone = inject(NgZone);
@@ -70,13 +70,29 @@ export class AdminStatsDashboardComponent implements OnInit, AfterViewInit, OnDe
// ── Leaflet ───────────────────────────────────────────── // ── Leaflet ─────────────────────────────────────────────
private map: L.Map | null = null; private map: L.Map | null = null;
private markersLayer: L.LayerGroup | null = null; private markersLayer: L.LayerGroup | null = null;
private mapInitialized = false;
ngOnInit(): void { ngOnInit(): void {
this.loadAll(); this.loadAll();
} }
ngAfterViewInit(): void { ngAfterViewChecked(): void {
// Initialize Leaflet map // The map container is inside an @else block gated by loading=true.
// ngAfterViewInit fires before loading completes, so the element
// doesn't exist yet. ngAfterViewChecked detects when it appears.
if (this.mapInitialized) return;
if (!this.mapContainerRef) return;
this.mapInitialized = true;
this.ngZone.runOutsideAngular(() => {
// Defer one frame so the browser has laid out the container
requestAnimationFrame(() => {
requestAnimationFrame(() => this._initMap());
});
});
}
private _initMap(): void {
this.map = L.map(this.mapContainerRef.nativeElement, { this.map = L.map(this.mapContainerRef.nativeElement, {
center: [20, 0], center: [20, 0],
zoom: 2, zoom: 2,
@@ -88,6 +104,12 @@ export class AdminStatsDashboardComponent implements OnInit, AfterViewInit, OnDe
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/">CARTO</a>', attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/">CARTO</a>',
maxZoom: 19, maxZoom: 19,
}).addTo(this.map); }).addTo(this.map);
// Ensure Leaflet uses the correct container size
this.map.invalidateSize();
// Data may have loaded in ngOnInit before the view was ready
this._updateMapMarkers();
} }
ngOnDestroy(): void { ngOnDestroy(): void {