Files
frontend/src/app/zoom-detection.service.ts
Piet Ostendorp f4eb700ab4 Add zoom and device detection with warning component
Introduces DeviceDetectionService and ZoomDetectionService to detect mobile devices and browser zoom level. Adds ZoomWarningComponent to display warnings for unsupported mobile devices and non-optimal browser zoom, and integrates it into the app layout. Updates routing to allow mobile access for the 'poc-model' route.
2025-11-18 23:00:18 +01:00

34 lines
875 B
TypeScript

import { Injectable } from '@angular/core';
import { BehaviorSubject, fromEvent } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ZoomDetectionService {
private zoomLevel$ = new BehaviorSubject<number>(this.getZoomLevel());
constructor() {
// Zoom-Änderungen überwachen
fromEvent(window, 'resize')
.pipe(debounceTime(200))
.subscribe(() => {
this.zoomLevel$.next(this.getZoomLevel());
});
}
getZoomLevel(): number {
const devicePixelRatio = window.devicePixelRatio || 1;
return devicePixelRatio;
}
getZoomLevel$() {
return this.zoomLevel$.asObservable();
}
isZoomOutOfRange(minZoom: number = 0.95, maxZoom: number = 1.05): boolean {
const currentZoom = this.getZoomLevel();
return currentZoom < minZoom || currentZoom > maxZoom;
}
}