mapcomplete/UI/ShowDataLayer/ShowOverlayLayerImplementation.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.2 KiB
TypeScript
Raw Normal View History

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