forked from MapComplete/MapComplete
Add overlay layer possibility, fix #515
This commit is contained in:
parent
7e053b3ada
commit
891c449058
12 changed files with 263 additions and 56 deletions
45
UI/ShowDataLayer/ShowOverlayLayer.ts
Normal file
45
UI/ShowDataLayer/ShowOverlayLayer.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import TilesourceConfig from "../../Models/ThemeConfig/TilesourceConfig";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import * as L from "leaflet";
|
||||
|
||||
export default class ShowOverlayLayer {
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
} )
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue