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.
This commit is contained in:
33
src/app/zoom-detection.service.ts
Normal file
33
src/app/zoom-detection.service.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user