dev #160
@ -1,17 +1,18 @@
|
|||||||
export const throttle = (func: () => void, wait: number) => {
|
export const throttle = (func: () => void, wait: number) => {
|
||||||
let lastTime = 0;
|
var lastTime = 0;
|
||||||
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
var timeoutId: ReturnType<typeof setTimeout> | undefined;
|
||||||
let lastArgs: any[];
|
var lastArgs: any[];
|
||||||
|
|
||||||
return function (...args: any[]) {
|
return function (...args: any[]) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
lastArgs = args;
|
lastArgs = args;
|
||||||
|
|
||||||
|
if (timeoutId) clearTimeout(timeoutId);
|
||||||
|
timeoutId = undefined;
|
||||||
if (now - lastTime >= wait) {
|
if (now - lastTime >= wait) {
|
||||||
lastTime = now;
|
lastTime = now;
|
||||||
func.apply(this, lastArgs);
|
func.apply(this, lastArgs);
|
||||||
} else {
|
} else {
|
||||||
if (timeoutId) clearTimeout(timeoutId);
|
|
||||||
timeoutId = setTimeout(
|
timeoutId = setTimeout(
|
||||||
() => {
|
() => {
|
||||||
lastTime = Date.now();
|
lastTime = Date.now();
|
||||||
@ -55,6 +56,7 @@ export const query_nominatim = (
|
|||||||
bb: any,
|
bb: any,
|
||||||
f: (v: string) => Boolean = () => true
|
f: (v: string) => Boolean = () => true
|
||||||
) => {
|
) => {
|
||||||
|
if (q.length == 0) return Promise.resolve([])
|
||||||
let url = new URL("/api/place/" + q, window.location.origin);
|
let url = new URL("/api/place/" + q, window.location.origin);
|
||||||
url.searchParams.append("id", q);
|
url.searchParams.append("id", q);
|
||||||
url.searchParams.append("bb", JSON.stringify(bb));
|
url.searchParams.append("bb", JSON.stringify(bb));
|
||||||
@ -95,7 +97,13 @@ export const is_attraction_type = (e: NominatimResult): boolean =>
|
|||||||
"protected_area",
|
"protected_area",
|
||||||
].indexOf(e.type) != -1;
|
].indexOf(e.type) != -1;
|
||||||
|
|
||||||
export const icon_type = (item: NominatimResult): string => {
|
export const is_hotel_type = (e: NominatimResult): boolean =>
|
||||||
|
["hotel", "hostel", "guest_house"].indexOf(e.type) != -1
|
||||||
|
|
||||||
|
export const icon_type = (item: string | NominatimResult): string => {
|
||||||
|
if (typeof (item) == "string") {
|
||||||
|
return item
|
||||||
|
}
|
||||||
let t = item.type;
|
let t = item.type;
|
||||||
let c = item.category;
|
let c = item.category;
|
||||||
let types = {
|
let types = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user