forked from MapComplete/MapComplete
More refactoring to fix the tests
This commit is contained in:
parent
71285d34cd
commit
b8abbc9505
16 changed files with 507 additions and 418 deletions
|
@ -3,43 +3,17 @@ import {UIEventSource} from "../../Logic/UIEventSource";
|
|||
import * as L from "leaflet";
|
||||
|
||||
export default class ShowOverlayLayer {
|
||||
|
||||
public static implementation: (config: TilesourceConfig,
|
||||
leafletMap: UIEventSource<any>,
|
||||
isShown?: UIEventSource<boolean>) => void;
|
||||
|
||||
constructor(config: TilesourceConfig,
|
||||
leafletMap: UIEventSource<any>,
|
||||
isShown: UIEventSource<boolean> = undefined) {
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
} )
|
||||
|
||||
|
||||
|
||||
if(ShowOverlayLayer.implementation === undefined){
|
||||
throw "Call ShowOverlayLayerImplemenation.initialize() first before using this"
|
||||
}
|
||||
ShowOverlayLayer.implementation(config, leafletMap, isShown)
|
||||
}
|
||||
|
||||
|
||||
}
|
45
UI/ShowDataLayer/ShowOverlayLayerImplementation.ts
Normal file
45
UI/ShowDataLayer/ShowOverlayLayerImplementation.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import * as L from "leaflet";
|
||||
import TilesourceConfig from "../../Models/ThemeConfig/TilesourceConfig";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import ShowOverlayLayer from "./ShowOverlayLayer";
|
||||
|
||||
export default class ShowOverlayLayerImplementation {
|
||||
|
||||
public static Implement(){
|
||||
ShowOverlayLayer.implementation = ShowOverlayLayerImplementation.AddToMap
|
||||
}
|
||||
|
||||
public static AddToMap(config: TilesourceConfig,
|
||||
leafletMap: UIEventSource<any>,
|
||||
isShown: UIEventSource<boolean> = undefined){
|
||||
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)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue