1
0
Fork 0
mirror of https://github.com/Findus23/RainbowRoad.git synced 2024-09-19 16:03:52 +02:00
RainbowRoad/src/toggle.ts

108 lines
3 KiB
TypeScript
Raw Normal View History

2023-02-28 22:27:31 +01:00
import {Control} from "ol/control";
import {Options} from "ol/control/Control";
import {createElement} from "./domutils";
import {router} from "./router";
2024-05-12 23:34:08 +02:00
import type {AcceptAll} from "./accept-all/accept-all";
2023-02-28 22:27:31 +01:00
2023-05-21 23:25:52 +02:00
interface CustomOptions extends Options {
buttonLetter: string
buttonClass: string
}
2023-02-28 22:27:31 +01:00
2023-05-21 23:25:52 +02:00
abstract class MapButton extends Control {
2023-02-28 22:27:31 +01:00
2023-05-21 23:25:52 +02:00
constructor(opt_options: CustomOptions) {
const options = opt_options || {buttonLetter: "o", buttonClass: "placeholder"};
2023-02-28 22:27:31 +01:00
const button = createElement('button');
2023-05-21 23:25:52 +02:00
button.innerHTML = options.buttonLetter;
2023-02-28 22:27:31 +01:00
const element = createElement('div');
2023-05-21 23:25:52 +02:00
element.className = 'ol-unselectable ol-control';
element.classList.add(options.buttonClass)
2023-02-28 22:27:31 +01:00
element.appendChild(button);
router.updatePageLinks()
super({
element: element,
target: options.target,
});
button.addEventListener('click', this.handleToggle.bind(this), false);
}
2023-05-21 23:25:52 +02:00
abstract handleToggle(): void
protected mapLayers() {
const osmLayer = this.getMap()!.getLayers().getArray()[0]
const basemapLayer = this.getMap()!.getLayers().getArray()[1]
const orthoLayer = this.getMap()!.getLayers().getArray()[2]
const zebraLayer = this.getMap()!.getLayers().getArray()[3]
return {osmLayer, basemapLayer, orthoLayer, zebraLayer};
}
}
export class OrthophotoControl extends MapButton {
showingOrtho = false
2024-05-12 23:24:10 +02:00
2023-05-21 23:25:52 +02:00
constructor() {
super({
buttonLetter: "o",
buttonClass: "ortho-button"
});
}
2023-02-28 22:27:31 +01:00
handleToggle() {
2023-05-21 23:25:52 +02:00
const {osmLayer, basemapLayer, orthoLayer, zebraLayer} = this.mapLayers();
2023-02-28 22:27:31 +01:00
this.showingOrtho = !this.showingOrtho
2023-05-21 23:25:52 +02:00
osmLayer.setVisible(!this.showingOrtho)
basemapLayer.setVisible(false)
orthoLayer.setVisible(this.showingOrtho)
zebraLayer.setOpacity(this.showingOrtho ? 0.2 : 1)
}
}
export class BasemapControl extends MapButton {
showingBasemap = false
constructor() {
super({
buttonLetter: "b",
buttonClass: "basemap-button"
});
}
2024-05-12 23:24:10 +02:00
2023-05-21 23:25:52 +02:00
handleToggle() {
const {osmLayer, basemapLayer, orthoLayer, zebraLayer} = this.mapLayers();
this.showingBasemap = !this.showingBasemap
osmLayer.setVisible(!this.showingBasemap)
orthoLayer.setVisible(false)
basemapLayer.setVisible(this.showingBasemap)
2024-05-12 23:24:10 +02:00
zebraLayer.setOpacity(1)
}
}
export class AcceptAllControl extends MapButton {
2024-05-12 23:34:08 +02:00
private acceptall: AcceptAll | undefined;
2024-05-12 23:24:10 +02:00
constructor() {
super({
buttonLetter: "a",
buttonClass: "accept-all-button"
});
2023-02-28 22:27:31 +01:00
}
2023-05-21 23:25:52 +02:00
2024-05-12 23:24:10 +02:00
handleToggle() {
import("./accept-all/accept-all").then(module => {
2024-05-12 23:34:08 +02:00
if (typeof this.acceptall !== "undefined") {
this.acceptall.dispose()
2024-05-12 23:24:10 +02:00
}
2024-05-12 23:34:08 +02:00
this.acceptall = new module.AcceptAll()
2024-05-12 23:24:10 +02:00
this.acceptall.show();
})
}
2023-02-28 22:27:31 +01:00
}