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
|
@ -17,6 +17,12 @@ import {VariableUiElement} from "./Base/VariableUIElement";
|
|||
import LeftControls from "./BigComponents/LeftControls";
|
||||
import RightControls from "./BigComponents/RightControls";
|
||||
import CenterMessageBox from "./CenterMessageBox";
|
||||
import ShowDataLayer from "./ShowDataLayer/ShowDataLayer";
|
||||
import AllKnownLayers from "../Customizations/AllKnownLayers";
|
||||
import ScrollableFullScreen from "./Base/ScrollableFullScreen";
|
||||
import Translations from "./i18n/Translations";
|
||||
import SimpleAddUI from "./BigComponents/SimpleAddUI";
|
||||
import StrayClickHandler from "../Logic/Actors/StrayClickHandler";
|
||||
|
||||
export class DefaultGuiState {
|
||||
public readonly welcomeMessageIsOpened;
|
||||
|
@ -85,9 +91,9 @@ export default class DefaultGUI {
|
|||
state.mainMapObject.SetClass("w-full h-full")
|
||||
.AttachTo("leafletDiv")
|
||||
|
||||
state.setupClickDialogOnMap(
|
||||
this.setupClickDialogOnMap(
|
||||
guiState.filterViewIsOpened,
|
||||
state.leafletMap
|
||||
state
|
||||
)
|
||||
|
||||
this.InitWelcomeMessage();
|
||||
|
@ -125,6 +131,14 @@ export default class DefaultGUI {
|
|||
document
|
||||
.getElementById("centermessage")
|
||||
.classList.add("pointer-events-none");
|
||||
|
||||
|
||||
new ShowDataLayer({
|
||||
leafletMap: state.leafletMap,
|
||||
layerToShow: AllKnownLayers.sharedLayers.get("home_location"),
|
||||
features: state.homeLocation,
|
||||
enablePopups: false,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
@ -158,4 +172,48 @@ export default class DefaultGUI {
|
|||
|
||||
}
|
||||
|
||||
public setupClickDialogOnMap(filterViewIsOpened: UIEventSource<boolean>, state: FeaturePipelineState) {
|
||||
|
||||
function setup(){
|
||||
let presetCount = 0;
|
||||
for (const layer of state.layoutToUse.layers) {
|
||||
for (const preset of layer.presets) {
|
||||
presetCount++;
|
||||
}
|
||||
}
|
||||
if (presetCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newPointDialogIsShown = new UIEventSource<boolean>(false);
|
||||
const addNewPoint = new ScrollableFullScreen(
|
||||
() => Translations.t.general.add.title.Clone(),
|
||||
() => new SimpleAddUI(newPointDialogIsShown, filterViewIsOpened, state),
|
||||
"new",
|
||||
newPointDialogIsShown
|
||||
);
|
||||
addNewPoint.isShown.addCallback((isShown) => {
|
||||
if (!isShown) {
|
||||
state.LastClickLocation.setData(undefined);
|
||||
}
|
||||
});
|
||||
|
||||
new StrayClickHandler(
|
||||
state.LastClickLocation,
|
||||
state.selectedElement,
|
||||
state.filteredLayers,
|
||||
state.leafletMap,
|
||||
addNewPoint
|
||||
);
|
||||
}
|
||||
|
||||
state.featureSwitchAddNew.addCallbackAndRunD(addNewAllowed => {
|
||||
if (addNewAllowed) {
|
||||
setup()
|
||||
return true;
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -18,6 +18,7 @@ import {Unit} from "../../Models/Unit";
|
|||
import {FixedInputElement} from "./FixedInputElement";
|
||||
import WikidataSearchBox from "../Wikipedia/WikidataSearchBox";
|
||||
import Wikidata from "../../Logic/Web/Wikidata";
|
||||
import AvailableBaseLayers from "../../Logic/Actors/AvailableBaseLayers";
|
||||
|
||||
interface TextFieldDef {
|
||||
name: string,
|
||||
|
@ -35,8 +36,6 @@ interface TextFieldDef {
|
|||
|
||||
export default class ValidatedTextField {
|
||||
|
||||
public static bestLayerAt: (location: UIEventSource<Loc>, preferences: UIEventSource<string[]>) => any
|
||||
|
||||
public static tpList: TextFieldDef[] = [
|
||||
ValidatedTextField.tp(
|
||||
"string",
|
||||
|
@ -93,7 +92,7 @@ export default class ValidatedTextField {
|
|||
})
|
||||
if (args[1]) {
|
||||
// We have a prefered map!
|
||||
options.mapBackgroundLayer = ValidatedTextField.bestLayerAt(
|
||||
options.mapBackgroundLayer = AvailableBaseLayers.SelectBestLayerAccordingTo(
|
||||
location, new UIEventSource<string[]>(args[1].split(","))
|
||||
)
|
||||
}
|
||||
|
@ -137,7 +136,7 @@ export default class ValidatedTextField {
|
|||
})
|
||||
if (args[1]) {
|
||||
// We have a prefered map!
|
||||
options.mapBackgroundLayer = ValidatedTextField.bestLayerAt(
|
||||
options.mapBackgroundLayer = AvailableBaseLayers.SelectBestLayerAccordingTo(
|
||||
location, new UIEventSource<string[]>(args[1].split(","))
|
||||
)
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
|
|||
import MoveConfig from "../../Models/ThemeConfig/MoveConfig";
|
||||
import {ElementStorage} from "../../Logic/ElementStorage";
|
||||
import ValidatedTextField from "../Input/ValidatedTextField";
|
||||
import AvailableBaseLayers from "../../Logic/Actors/AvailableBaseLayers";
|
||||
|
||||
interface MoveReason {
|
||||
text: Translation | string,
|
||||
|
@ -138,7 +139,7 @@ export default class MoveWizard extends Toggle {
|
|||
const locationInput = new LocationInput({
|
||||
minZoom: reason.minZoom,
|
||||
centerLocation: loc,
|
||||
mapBackground: ValidatedTextField.bestLayerAt(loc, new UIEventSource(background))
|
||||
mapBackground:AvailableBaseLayers.SelectBestLayerAccordingTo(loc, new UIEventSource(background))
|
||||
})
|
||||
|
||||
if (reason.lockBounds) {
|
||||
|
|
|
@ -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