forked from MapComplete/MapComplete
UX: place 'add new button' in bottom-left instead of having a dynamic pin
This commit is contained in:
parent
dab8d6cd5d
commit
285fe9ab83
7 changed files with 730 additions and 703 deletions
|
@ -1,10 +1,11 @@
|
|||
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
|
||||
import { WritableFeatureSource } from "../FeatureSource"
|
||||
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
|
||||
import { Feature, Point } from "geojson"
|
||||
import { TagUtils } from "../../Tags/TagUtils"
|
||||
import BaseUIElement from "../../../UI/BaseUIElement"
|
||||
import { Utils } from "../../../Utils"
|
||||
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig";
|
||||
import { WritableFeatureSource } from "../FeatureSource";
|
||||
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource";
|
||||
import { Feature, Point } from "geojson";
|
||||
import { TagUtils } from "../../Tags/TagUtils";
|
||||
import BaseUIElement from "../../../UI/BaseUIElement";
|
||||
import { Utils } from "../../../Utils";
|
||||
import { OsmTags } from "../../../Models/OsmFeature";
|
||||
|
||||
/**
|
||||
* Highly specialized feature source.
|
||||
|
@ -12,8 +13,14 @@ import { Utils } from "../../../Utils"
|
|||
*/
|
||||
export class LastClickFeatureSource implements WritableFeatureSource {
|
||||
public readonly features: UIEventSource<Feature[]> = new UIEventSource<Feature[]>([])
|
||||
private i: number = 0
|
||||
private readonly hasNoteLayer: string
|
||||
private readonly renderings: string[];
|
||||
private readonly hasPresets: string;
|
||||
|
||||
constructor(location: Store<{ lon: number; lat: number }>, layout: LayoutConfig) {
|
||||
this.hasNoteLayer = layout.layers.some((l) => l.id === "note") ? "yes" : "no"
|
||||
this.hasPresets= layout.layers.some((l) => l.presets?.length > 0) ? "yes" : "no"
|
||||
const allPresets: BaseUIElement[] = []
|
||||
for (const layer of layout.layers)
|
||||
for (let i = 0; i < (layer.presets ?? []).length; i++) {
|
||||
|
@ -26,35 +33,36 @@ export class LastClickFeatureSource implements WritableFeatureSource {
|
|||
allPresets.push(html)
|
||||
}
|
||||
|
||||
const renderings = Utils.Dedup(
|
||||
this.renderings = Utils.Dedup(
|
||||
allPresets.map((uiElem) =>
|
||||
Utils.runningFromConsole ? "" : uiElem.ConstructElement().innerHTML
|
||||
)
|
||||
)
|
||||
|
||||
let i = 0
|
||||
|
||||
location.addCallbackAndRunD(({ lon, lat }) => {
|
||||
const properties = {
|
||||
lastclick: "yes",
|
||||
id: "last_click_" + i,
|
||||
has_note_layer: layout.layers.some((l) => l.id === "note") ? "yes" : "no",
|
||||
has_presets: layout.layers.some((l) => l.presets?.length > 0) ? "yes" : "no",
|
||||
renderings: renderings.join(""),
|
||||
number_of_presets: "" + renderings.length,
|
||||
first_preset: renderings[0],
|
||||
}
|
||||
i++
|
||||
|
||||
const point = <Feature<Point>>{
|
||||
type: "Feature",
|
||||
properties,
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [lon, lat],
|
||||
},
|
||||
}
|
||||
this.features.setData([point])
|
||||
this.features.setData([this.createFeature(lon, lat)])
|
||||
})
|
||||
}
|
||||
|
||||
public createFeature(lon: number, lat: number): Feature<Point, OsmTags> {
|
||||
const properties: OsmTags = {
|
||||
lastclick: "yes",
|
||||
id: "last_click_" + this.i,
|
||||
has_note_layer: this.hasNoteLayer ,
|
||||
has_presets:this.hasPresets ,
|
||||
renderings: this.renderings.join(""),
|
||||
number_of_presets: "" +this. renderings.length,
|
||||
first_preset: this.renderings[0],
|
||||
}
|
||||
this. i++
|
||||
|
||||
return <Feature<Point, OsmTags>>{
|
||||
type: "Feature",
|
||||
properties,
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [lon, lat],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ export default class ThemeViewStateHashActor {
|
|||
}
|
||||
|
||||
private back() {
|
||||
console.log("Got a back event")
|
||||
console.trace("Got a back event")
|
||||
const state = this._state
|
||||
// history.pushState(null, null, window.location.pathname);
|
||||
if (state.selectedElement.data) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue