forked from MapComplete/MapComplete
Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,28 +1,24 @@
|
|||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import {Translation} from "../i18n/Translation";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
import Svg from "../../Svg";
|
||||
import {TextField} from "../Input/TextField";
|
||||
import {Geocoding} from "../../Logic/Osm/Geocoding";
|
||||
import Translations from "../i18n/Translations";
|
||||
import Hash from "../../Logic/Web/Hash";
|
||||
import Combine from "../Base/Combine";
|
||||
import Locale from "../i18n/Locale";
|
||||
import { UIEventSource } from "../../Logic/UIEventSource"
|
||||
import { Translation } from "../i18n/Translation"
|
||||
import { VariableUiElement } from "../Base/VariableUIElement"
|
||||
import Svg from "../../Svg"
|
||||
import { TextField } from "../Input/TextField"
|
||||
import { Geocoding } from "../../Logic/Osm/Geocoding"
|
||||
import Translations from "../i18n/Translations"
|
||||
import Hash from "../../Logic/Web/Hash"
|
||||
import Combine from "../Base/Combine"
|
||||
import Locale from "../i18n/Locale"
|
||||
|
||||
export default class SearchAndGo extends Combine {
|
||||
constructor(state: {
|
||||
leafletMap: UIEventSource<any>,
|
||||
selectedElement: UIEventSource<any>
|
||||
}) {
|
||||
const goButton = Svg.search_ui().SetClass(
|
||||
"w-8 h-8 full-rounded border-black float-right"
|
||||
);
|
||||
constructor(state: { leafletMap: UIEventSource<any>; selectedElement: UIEventSource<any> }) {
|
||||
const goButton = Svg.search_ui().SetClass("w-8 h-8 full-rounded border-black float-right")
|
||||
|
||||
const placeholder = new UIEventSource<Translation>(
|
||||
Translations.t.general.search.search
|
||||
);
|
||||
const placeholder = new UIEventSource<Translation>(Translations.t.general.search.search)
|
||||
const searchField = new TextField({
|
||||
placeholder: placeholder.map(tr => tr.textFor(Locale.language.data), [Locale.language]),
|
||||
placeholder: placeholder.map(
|
||||
(tr) => tr.textFor(Locale.language.data),
|
||||
[Locale.language]
|
||||
),
|
||||
value: new UIEventSource<string>(""),
|
||||
inputStyle:
|
||||
" background: transparent;\n" +
|
||||
|
@ -32,53 +28,52 @@ export default class SearchAndGo extends Combine {
|
|||
" height: 100%;\n" +
|
||||
" box-sizing: border-box;\n" +
|
||||
" color: var(--foreground-color);",
|
||||
});
|
||||
})
|
||||
|
||||
searchField.SetClass("relative float-left mt-0 ml-2");
|
||||
searchField.SetStyle("width: calc(100% - 3em);height: 100%");
|
||||
searchField.SetClass("relative float-left mt-0 ml-2")
|
||||
searchField.SetStyle("width: calc(100% - 3em);height: 100%")
|
||||
|
||||
super([searchField, goButton]);
|
||||
super([searchField, goButton])
|
||||
|
||||
this.SetClass("block h-8");
|
||||
this.SetClass("block h-8")
|
||||
this.SetStyle(
|
||||
"background: var(--background-color); color: var(--foreground-color); pointer-evetns:all;"
|
||||
);
|
||||
)
|
||||
|
||||
// Triggered by 'enter' or onclick
|
||||
async function runSearch() {
|
||||
const searchString = searchField.GetValue().data;
|
||||
const searchString = searchField.GetValue().data
|
||||
if (searchString === undefined || searchString === "") {
|
||||
return;
|
||||
return
|
||||
}
|
||||
searchField.GetValue().setData("");
|
||||
placeholder.setData(Translations.t.general.search.searching);
|
||||
searchField.GetValue().setData("")
|
||||
placeholder.setData(Translations.t.general.search.searching)
|
||||
try {
|
||||
const result = await Geocoding.Search(searchString)
|
||||
|
||||
const result = await Geocoding.Search(searchString);
|
||||
|
||||
console.log("Search result", result);
|
||||
console.log("Search result", result)
|
||||
if (result.length == 0) {
|
||||
placeholder.setData(Translations.t.general.search.nothing);
|
||||
return;
|
||||
placeholder.setData(Translations.t.general.search.nothing)
|
||||
return
|
||||
}
|
||||
|
||||
const poi = result[0];
|
||||
const bb = poi.boundingbox;
|
||||
const poi = result[0]
|
||||
const bb = poi.boundingbox
|
||||
const bounds: [[number, number], [number, number]] = [
|
||||
[bb[0], bb[2]],
|
||||
[bb[1], bb[3]],
|
||||
];
|
||||
state.selectedElement.setData(undefined);
|
||||
Hash.hash.setData(poi.osm_type + "/" + poi.osm_id);
|
||||
state.leafletMap.data.fitBounds(bounds);
|
||||
]
|
||||
state.selectedElement.setData(undefined)
|
||||
Hash.hash.setData(poi.osm_type + "/" + poi.osm_id)
|
||||
state.leafletMap.data.fitBounds(bounds)
|
||||
placeholder.setData(Translations.t.general.search.search)
|
||||
}catch(e){
|
||||
searchField.GetValue().setData("");
|
||||
placeholder.setData(Translations.t.general.search.error);
|
||||
} catch (e) {
|
||||
searchField.GetValue().setData("")
|
||||
placeholder.setData(Translations.t.general.search.error)
|
||||
}
|
||||
}
|
||||
|
||||
searchField.enterPressed.addCallback(runSearch);
|
||||
goButton.onClick(runSearch);
|
||||
searchField.enterPressed.addCallback(runSearch)
|
||||
goButton.onClick(runSearch)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue