blob: 0ff834867878fd63e013466d12f9f926598985bc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import {MapController, CELL_SIZE} from "./mapcontroller";
import {MapView} from "../views/mapview";
export class ScaleIndicatorController {
private static MIN_WIDTH = 50;
private static MAX_WIDTH = 100;
private mapController: MapController;
private mapView: MapView;
private jqueryObject: JQuery;
private currentDivisor: number;
constructor(mapController: MapController) {
this.mapController = mapController;
this.mapView = mapController.mapView;
}
public init(jqueryObject: JQuery): void {
this.jqueryObject = jqueryObject;
this.currentDivisor = 1;
}
public update(): void {
let currentZoom = this.mapView.mapContainer.scaleX;
let newWidth;
do {
newWidth = (currentZoom * CELL_SIZE) / this.currentDivisor;
if (newWidth < ScaleIndicatorController.MIN_WIDTH) {
this.currentDivisor /= 2;
} else if (newWidth > ScaleIndicatorController.MAX_WIDTH) {
this.currentDivisor *= 2;
} else {
break;
}
} while (true);
this.jqueryObject.text(MapView.CELL_SIZE_METERS / this.currentDivisor + "m");
this.jqueryObject.width(newWidth);
}
}
|