mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 14:59:36 +02:00
Add better support in adventure modal for the region search
This commit is contained in:
parent
43c134bf2b
commit
afe83bb03e
1 changed files with 32 additions and 15 deletions
|
@ -13,7 +13,7 @@
|
||||||
export let is_collection: boolean = false;
|
export let is_collection: boolean = false;
|
||||||
|
|
||||||
import { DefaultMarker, MapEvents, MapLibre } from 'svelte-maplibre';
|
import { DefaultMarker, MapEvents, MapLibre } from 'svelte-maplibre';
|
||||||
let markers: Point[] = [];
|
|
||||||
let query: string = '';
|
let query: string = '';
|
||||||
let places: OpenStreetMapPlace[] = [];
|
let places: OpenStreetMapPlace[] = [];
|
||||||
let images: { id: string; image: string }[] = [];
|
let images: { id: string; image: string }[] = [];
|
||||||
|
@ -72,6 +72,8 @@
|
||||||
collection: adventureToEdit?.collection || collection_id || null
|
collection: adventureToEdit?.collection || collection_id || null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let markers: Point[] = [];
|
||||||
|
|
||||||
let url: string = '';
|
let url: string = '';
|
||||||
let imageError: string = '';
|
let imageError: string = '';
|
||||||
let wikiImageError: string = '';
|
let wikiImageError: string = '';
|
||||||
|
@ -79,6 +81,7 @@
|
||||||
images = adventure.images || [];
|
images = adventure.images || [];
|
||||||
|
|
||||||
if (adventure.longitude && adventure.latitude) {
|
if (adventure.longitude && adventure.latitude) {
|
||||||
|
markers = [];
|
||||||
markers = [
|
markers = [
|
||||||
{
|
{
|
||||||
lngLat: { lng: adventure.longitude, lat: adventure.latitude },
|
lngLat: { lng: adventure.longitude, lat: adventure.latitude },
|
||||||
|
@ -87,6 +90,7 @@
|
||||||
activity_type: ''
|
activity_type: ''
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
checkPointInRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (longitude && latitude) {
|
if (longitude && latitude) {
|
||||||
|
@ -142,6 +146,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (adventure.type != 'visited') {
|
||||||
|
region_id = null;
|
||||||
|
region_name = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchImage() {
|
async function fetchImage() {
|
||||||
let res = await fetch(url);
|
let res = await fetch(url);
|
||||||
let data = await res.blob();
|
let data = await res.blob();
|
||||||
|
@ -247,6 +258,7 @@
|
||||||
activity_type: data[0]?.type || ''
|
activity_type: data[0]?.type || ''
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
checkPointInRegion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
@ -284,21 +296,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addMarker(e: CustomEvent<any>) {
|
async function checkPointInRegion() {
|
||||||
markers = [];
|
|
||||||
markers = [
|
|
||||||
...markers,
|
|
||||||
{
|
|
||||||
lngLat: e.detail.lngLat,
|
|
||||||
name: '',
|
|
||||||
location: '',
|
|
||||||
activity_type: ''
|
|
||||||
}
|
|
||||||
];
|
|
||||||
if (adventure.type == 'visited') {
|
if (adventure.type == 'visited') {
|
||||||
let res = await fetch(
|
let lat = markers[0].lngLat.lat;
|
||||||
`/api/countries/check_point_in_region/?lat=${e.detail.lngLat.lat}&lon=${e.detail.lngLat.lng}`
|
let lon = markers[0].lngLat.lng;
|
||||||
);
|
let res = await fetch(`/api/countries/check_point_in_region/?lat=${lat}&lon=${lon}`);
|
||||||
let data = await res.json();
|
let data = await res.json();
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
addToast('error', data.error);
|
addToast('error', data.error);
|
||||||
|
@ -315,6 +317,20 @@
|
||||||
region_id = null;
|
region_id = null;
|
||||||
region_name = null;
|
region_name = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addMarker(e: CustomEvent<any>) {
|
||||||
|
markers = [];
|
||||||
|
markers = [
|
||||||
|
...markers,
|
||||||
|
{
|
||||||
|
lngLat: e.detail.lngLat,
|
||||||
|
name: '',
|
||||||
|
location: '',
|
||||||
|
activity_type: ''
|
||||||
|
}
|
||||||
|
];
|
||||||
|
checkPointInRegion();
|
||||||
|
|
||||||
console.log(markers);
|
console.log(markers);
|
||||||
}
|
}
|
||||||
|
@ -675,6 +691,7 @@
|
||||||
activity_type: place.type
|
activity_type: place.type
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
checkPointInRegion();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{place.display_name}
|
{place.display_name}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue