major performance improvements map
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
createPopupFromTrail,
|
||||
FontawesomeMarker,
|
||||
} from "$lib/util/maplibre_util";
|
||||
import { polylineToGeoJSON } from "$lib/util/polyline_util";
|
||||
import type { ElevationProfileControl } from "$lib/vendor/maplibre-elevation-profile/elevationprofile-control";
|
||||
import { FullscreenControl } from "$lib/vendor/maplibre-fullscreen/fullscreen-control";
|
||||
import MaplibreGraticule from "$lib/vendor/maplibre-graticule/maplibre-graticule";
|
||||
@@ -182,8 +183,11 @@
|
||||
}
|
||||
|
||||
const r: GeoJSON[] = [];
|
||||
console.time("start decode")
|
||||
trails.forEach((t) => {
|
||||
if (t.expand?.gpx_data) {
|
||||
if (t.polyline) {
|
||||
r.push(polylineToGeoJSON(t.polyline, 5));
|
||||
} else if (t.expand?.gpx_data) {
|
||||
r.push(toGeoJson(t.expand.gpx_data) as GeoJSON);
|
||||
} else if (t.lat !== null && t.lon !== null) {
|
||||
r.push({
|
||||
@@ -197,6 +201,8 @@
|
||||
} as GeoJSON);
|
||||
}
|
||||
});
|
||||
console.timeEnd("start decode")
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ class Trail {
|
||||
tags: string[];
|
||||
waypoints: string[];
|
||||
summit_logs: string[];
|
||||
polyline?: string;
|
||||
expand?: {
|
||||
tags?: Tag[]
|
||||
category?: Category;
|
||||
@@ -165,6 +166,7 @@ interface TrailSearchResult {
|
||||
created: number;
|
||||
public: boolean;
|
||||
thumbnail: string;
|
||||
polyline?: string;
|
||||
shares?: string[];
|
||||
tags?: string[]
|
||||
gpx: string;
|
||||
@@ -174,6 +176,29 @@ interface TrailSearchResult {
|
||||
};
|
||||
}
|
||||
|
||||
export const defaultTrailSearchAttributes = [
|
||||
"id",
|
||||
"author",
|
||||
"author_name",
|
||||
"author_avatar",
|
||||
"name",
|
||||
"description",
|
||||
"location",
|
||||
"distance",
|
||||
"elevation_gain",
|
||||
"elevation_loss",
|
||||
"duration",
|
||||
"difficulty",
|
||||
"category",
|
||||
"completed",
|
||||
"date",
|
||||
"created",
|
||||
"public",
|
||||
"thumbnail",
|
||||
"gpx",
|
||||
"tags",
|
||||
"_geo",]
|
||||
|
||||
|
||||
export { Trail };
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { env } from "$env/dynamic/public";
|
||||
import { defaultTrailSearchAttributes } from "$lib/models/trail";
|
||||
import { APIError } from "$lib/util/api_util";
|
||||
import type { Hits, MultiSearchParams, MultiSearchResponse, MultiSearchResult, SearchParams, SearchResponse } from "meilisearch";
|
||||
|
||||
@@ -97,6 +98,7 @@ export async function searchTrails(q: string, options: SearchParams): Promise<Hi
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
q,
|
||||
attributesToRetrieve: defaultTrailSearchAttributes,
|
||||
options
|
||||
}),
|
||||
});
|
||||
@@ -161,7 +163,7 @@ function getLocationDescription(address: Address) {
|
||||
description = `${address.city}, ` + description
|
||||
} else if (address.town) {
|
||||
description = `${address.town}, ` + description
|
||||
}else if (address.hamlet) {
|
||||
} else if (address.hamlet) {
|
||||
description = `${address.hamlet}, ` + description
|
||||
} else if (address.village) {
|
||||
description = `${address.village}, ` + description
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { SummitLog } from "$lib/models/summit_log";
|
||||
import { Trail, type TrailFilter, type TrailFilterValues, type TrailSearchResult } from "$lib/models/trail";
|
||||
import { defaultTrailSearchAttributes, Trail, type TrailFilter, type TrailFilterValues, type TrailSearchResult } from "$lib/models/trail";
|
||||
import type { Waypoint } from "$lib/models/waypoint";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { deepEqual } from "$lib/util/deep_util";
|
||||
@@ -65,6 +65,7 @@ export async function trails_search_filter(filter: TrailFilter, page: number = 1
|
||||
q: filter.q,
|
||||
options: {
|
||||
filter: filterText,
|
||||
attributesToRetrieve: defaultTrailSearchAttributes,
|
||||
sort: [`${filter.sort}:${filter.sortOrder == "+" ? "asc" : "desc"}`],
|
||||
hitsPerPage: 12,
|
||||
page: page
|
||||
@@ -89,7 +90,7 @@ export async function trails_search_filter(filter: TrailFilter, page: number = 1
|
||||
|
||||
}
|
||||
|
||||
export async function trails_search_bounding_box(northEast: M.LngLat, southWest: M.LngLat, filter?: TrailFilter, page: number = 1, loadGPX: boolean = true) {
|
||||
export async function trails_search_bounding_box(northEast: M.LngLat, southWest: M.LngLat, filter?: TrailFilter, page: number = 1, includePolyline: boolean = true) {
|
||||
|
||||
let filterText: string = "";
|
||||
|
||||
@@ -106,6 +107,7 @@ export async function trails_search_bounding_box(northEast: M.LngLat, southWest:
|
||||
`_geoBoundingBox([${northEast.lat}, ${northEast.lng}], [${southWest.lat}, ${southWest.lng}])`,
|
||||
filterText
|
||||
],
|
||||
attributesToRetrieve: [...defaultTrailSearchAttributes, ...(includePolyline ? ["polyline"] : [])],
|
||||
hitsPerPage: 500,
|
||||
page: page
|
||||
}
|
||||
@@ -118,7 +120,7 @@ export async function trails_search_bounding_box(northEast: M.LngLat, southWest:
|
||||
return { trails: [], ...result }
|
||||
}
|
||||
|
||||
const resultTrails: Trail[] = await searchResultToTrailList(result.hits, loadGPX)
|
||||
const resultTrails: Trail[] = await searchResultToTrailList(result.hits)
|
||||
|
||||
trails = page > 1 ? trails.concat(resultTrails) : resultTrails
|
||||
|
||||
@@ -444,7 +446,7 @@ export async function fetchGPX(trail: { gpx?: string } & Record<string, any>, f:
|
||||
return gpxData
|
||||
}
|
||||
|
||||
async function searchResultToTrailList(hits: Hits<TrailSearchResult>, loadGPX: boolean = false): Promise<Trail[]> {
|
||||
async function searchResultToTrailList(hits: Hits<TrailSearchResult>): Promise<Trail[]> {
|
||||
const trails: Trail[] = []
|
||||
for (const h of hits) {
|
||||
const t: Trail & RecordModel = {
|
||||
@@ -472,6 +474,7 @@ async function searchResultToTrailList(hits: Hits<TrailSearchResult>, loadGPX: b
|
||||
lon: h._geo.lng,
|
||||
location: h.location,
|
||||
gpx: h.gpx,
|
||||
polyline: h.polyline,
|
||||
thumbnail: 0,
|
||||
expand: {
|
||||
author: {
|
||||
@@ -489,10 +492,6 @@ async function searchResultToTrailList(hits: Hits<TrailSearchResult>, loadGPX: b
|
||||
}
|
||||
}
|
||||
|
||||
if (loadGPX) {
|
||||
const gpxData: string = await fetchGPX(t);
|
||||
t.expand!.gpx_data = gpxData;
|
||||
}
|
||||
|
||||
trails.push(t)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import type { GeoJSON } from "geojson";
|
||||
import { bbox } from "./geojson_util";
|
||||
|
||||
|
||||
function py2_round(value: number) {
|
||||
return Math.floor(Math.abs(value) + 0.5) * (value >= 0 ? 1 : -1);
|
||||
}
|
||||
@@ -77,4 +81,34 @@ export function encodePolyline(coordinates: number[][], precision: number = 6) {
|
||||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
function flipped(coords: number[][]) {
|
||||
var flipped = [];
|
||||
for (var i = 0; i < coords.length; i++) {
|
||||
var coord = coords[i].slice();
|
||||
flipped.push([coord[1], coord[0]]);
|
||||
}
|
||||
return flipped;
|
||||
}
|
||||
|
||||
export function polylineToGeoJSON(str: string, precision: number = 6) {
|
||||
var coords = decodePolyline(str, precision);
|
||||
const geojson = {
|
||||
type: "FeatureCollection",
|
||||
features: [
|
||||
{
|
||||
properties: {},
|
||||
type: "Feature",
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
coordinates: flipped(coords),
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
} as GeoJSON;
|
||||
geojson.bbox = bbox(geojson)
|
||||
|
||||
return geojson
|
||||
};
|
||||
@@ -8,6 +8,7 @@
|
||||
import CategoryCard from "$lib/components/category_card.svelte";
|
||||
import Scene from "$lib/components/scene.svelte";
|
||||
import TrailCard from "$lib/components/trail/trail_card.svelte";
|
||||
import { defaultTrailSearchAttributes } from "$lib/models/trail.js";
|
||||
import { categories } from "$lib/stores/category_store";
|
||||
import {
|
||||
searchMulti,
|
||||
@@ -30,6 +31,7 @@
|
||||
queries: [
|
||||
{
|
||||
indexUid: "trails",
|
||||
attributesToRetrieve: defaultTrailSearchAttributes,
|
||||
q: q,
|
||||
limit: 3,
|
||||
},
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
import TrailCard from "$lib/components/trail/trail_card.svelte";
|
||||
import TrailFilterPanel from "$lib/components/trail/trail_filter_panel.svelte";
|
||||
import type { Settings } from "$lib/models/settings";
|
||||
import type {
|
||||
Trail,
|
||||
TrailBoundingBox,
|
||||
TrailFilter,
|
||||
import {
|
||||
defaultTrailSearchAttributes,
|
||||
type Trail,
|
||||
type TrailBoundingBox,
|
||||
type TrailFilter,
|
||||
} from "$lib/models/trail";
|
||||
import { categories } from "$lib/stores/category_store";
|
||||
import {
|
||||
@@ -67,6 +68,7 @@
|
||||
queries: [
|
||||
{
|
||||
indexUid: "trails",
|
||||
attributesToRetrieve: defaultTrailSearchAttributes,
|
||||
q: q,
|
||||
limit: 3,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user