mapcomplete/UI/ShowDataLayer/ShowOverlayLayerImplementation.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-09-08 21:40:48 +02:00
import * as L from "leaflet"
import TilesourceConfig from "../../Models/ThemeConfig/TilesourceConfig"
import { UIEventSource } from "../../Logic/UIEventSource"
import ShowOverlayLayer from "./ShowOverlayLayer"
2021-10-15 14:52:11 +02:00
export default class ShowOverlayLayerImplementation {
2021-11-07 16:34:51 +01:00
public static Implement() {
2021-10-15 14:52:11 +02:00
ShowOverlayLayer.implementation = ShowOverlayLayerImplementation.AddToMap
}
2021-11-07 16:34:51 +01:00
2022-09-08 21:40:48 +02:00
public static AddToMap(
config: TilesourceConfig,
leafletMap: UIEventSource<any>,
isShown: UIEventSource<boolean> = undefined
) {
leafletMap.map((leaflet) => {
2021-10-15 14:52:11 +02:00
if (leaflet === undefined) {
2022-09-08 21:40:48 +02:00
return
2021-10-15 14:52:11 +02:00
}
2022-09-08 21:40:48 +02:00
const tileLayer = L.tileLayer(config.source, {
attribution: "",
maxZoom: config.maxzoom,
minZoom: config.minzoom,
// @ts-ignore
wmts: false,
})
2021-10-15 14:52:11 +02:00
if (isShown === undefined) {
tileLayer.addTo(leaflet)
}
2022-09-08 21:40:48 +02:00
isShown?.addCallbackAndRunD((isShown) => {
2021-10-15 14:52:11 +02:00
if (isShown) {
tileLayer.addTo(leaflet)
} else {
leaflet.removeLayer(tileLayer)
}
})
})
}
2022-09-08 21:40:48 +02:00
}