mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-27 16:59:37 +02:00
commit
efa13d85cc
6 changed files with 43894 additions and 33 deletions
26581
backend/server/static/data/au.json
Normal file
26581
backend/server/static/data/au.json
Normal file
File diff suppressed because it is too large
Load diff
2692
backend/server/static/data/de.json
Normal file
2692
backend/server/static/data/de.json
Normal file
File diff suppressed because it is too large
Load diff
14588
backend/server/static/data/fr.json
Normal file
14588
backend/server/static/data/fr.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -119,21 +119,21 @@ class Command(BaseCommand):
|
||||||
('CA-NU', 'Nunavut', 'ca'),
|
('CA-NU', 'Nunavut', 'ca'),
|
||||||
('CA-YT', 'Yukon', 'ca'),
|
('CA-YT', 'Yukon', 'ca'),
|
||||||
('DE-BW', 'Baden-Württemberg', 'de'),
|
('DE-BW', 'Baden-Württemberg', 'de'),
|
||||||
('DE-BY', 'Bavaria', 'de'),
|
('DE-BY', 'Bayern', 'de'),
|
||||||
('DE-BE', 'Berlin', 'de'),
|
('DE-BE', 'Berlin', 'de'),
|
||||||
('DE-BB', 'Brandenburg', 'de'),
|
('DE-BB', 'Brandenburg', 'de'),
|
||||||
('DE-HB', 'Bremen', 'de'),
|
('DE-HB', 'Bremen', 'de'),
|
||||||
('DE-HH', 'Hamburg', 'de'),
|
('DE-HH', 'Hamburg', 'de'),
|
||||||
('DE-HE', 'Hesse', 'de'),
|
('DE-HE', 'Hessen', 'de'),
|
||||||
('DE-NI', 'Lower Saxony', 'de'),
|
|
||||||
('DE-MV', 'Mecklenburg-Vorpommern', 'de'),
|
('DE-MV', 'Mecklenburg-Vorpommern', 'de'),
|
||||||
('DE-NW', 'North Rhine-Westphalia', 'de'),
|
('DE-NI', 'Niedersachsen', 'de'),
|
||||||
('DE-RP', 'Rhineland-Palatinate', 'de'),
|
('DE-NW', 'Nordrhein-Westfalen', 'de'),
|
||||||
|
('DE-RP', 'Rheinland-Pfalz', 'de'),
|
||||||
('DE-SL', 'Saarland', 'de'),
|
('DE-SL', 'Saarland', 'de'),
|
||||||
('DE-SN', 'Saxony', 'de'),
|
('DE-SN', 'Sachsen', 'de'),
|
||||||
('DE-ST', 'Saxony-Anhalt', 'de'),
|
('DE-ST', 'Sachsen-Anhalt', 'de'),
|
||||||
('DE-SH', 'Schleswig-Holstein', 'de'),
|
('DE-SH', 'Schleswig-Holstein', 'de'),
|
||||||
('DE-TH', 'Thuringia', 'de'),
|
('DE-TH', 'Thüringen', 'de'),
|
||||||
('FR-ARA', 'Auvergne-Rhône-Alpes', 'fr'),
|
('FR-ARA', 'Auvergne-Rhône-Alpes', 'fr'),
|
||||||
('FR-BFC', 'Bourgogne-Franche-Comté', 'fr'),
|
('FR-BFC', 'Bourgogne-Franche-Comté', 'fr'),
|
||||||
('FR-BRE', 'Brittany', 'fr'),
|
('FR-BRE', 'Brittany', 'fr'),
|
||||||
|
|
|
@ -5,6 +5,12 @@ import type { Adventure, VisitedRegion } from '$lib/types';
|
||||||
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||||
|
|
||||||
export const load = (async (event) => {
|
export const load = (async (event) => {
|
||||||
|
let countryCodesToFetch = ['FR', 'US', 'CA', 'DE', 'AU'];
|
||||||
|
let geoJSON = {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: []
|
||||||
|
};
|
||||||
|
|
||||||
if (!event.locals.user) {
|
if (!event.locals.user) {
|
||||||
return redirect(302, '/login');
|
return redirect(302, '/login');
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,24 +27,24 @@ export const load = (async (event) => {
|
||||||
});
|
});
|
||||||
let visitedRegions = (await visitedRegionsFetch.json()) as VisitedRegion[];
|
let visitedRegions = (await visitedRegionsFetch.json()) as VisitedRegion[];
|
||||||
|
|
||||||
let USfetch = await fetch(`${endpoint}/static/data/us.json`);
|
await Promise.all(
|
||||||
let USjson = await USfetch.json();
|
countryCodesToFetch.map(async (code) => {
|
||||||
if (!USjson) {
|
let res = await fetch(`${endpoint}/static/data/${code.toLowerCase()}.json`);
|
||||||
console.error('Failed to fetch US GeoJSON');
|
console.log('fetching ' + code);
|
||||||
}
|
let json = await res.json();
|
||||||
|
if (!json) {
|
||||||
let CAfetch = await fetch(`${endpoint}/static/data/ca.json`);
|
console.error(`Failed to fetch ${code} GeoJSON`);
|
||||||
let CAjson = await CAfetch.json();
|
} else {
|
||||||
if (!CAjson) {
|
geoJSON.features = geoJSON.features.concat(json.features);
|
||||||
console.error('Failed to fetch CA GeoJSON');
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
if (!visitedFetch.ok) {
|
if (!visitedFetch.ok) {
|
||||||
console.error('Failed to fetch visited adventures');
|
console.error('Failed to fetch visited adventures');
|
||||||
return redirect(302, '/login');
|
return redirect(302, '/login');
|
||||||
} else {
|
} else {
|
||||||
let visited = (await visitedFetch.json()) as Adventure[];
|
let visited = (await visitedFetch.json()) as Adventure[];
|
||||||
console.log('VISITEDL ' + visited);
|
|
||||||
// make a long lat array like this { lngLat: [-20, 0], name: 'Adventure 1' },
|
// make a long lat array like this { lngLat: [-20, 0], name: 'Adventure 1' },
|
||||||
let markers = visited
|
let markers = visited
|
||||||
.filter((adventure) => adventure.latitude !== null && adventure.longitude !== null)
|
.filter((adventure) => adventure.latitude !== null && adventure.longitude !== null)
|
||||||
|
@ -50,11 +56,12 @@ export const load = (async (event) => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('sent');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
markers,
|
markers,
|
||||||
USjson,
|
geoJSON,
|
||||||
CAjson,
|
|
||||||
visitedRegions
|
visitedRegions
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,19 +17,11 @@
|
||||||
let clickedName = '';
|
let clickedName = '';
|
||||||
|
|
||||||
let markers = data.props.markers;
|
let markers = data.props.markers;
|
||||||
let us = data.props.USjson;
|
|
||||||
let ca = data.props.CAjson;
|
|
||||||
|
|
||||||
// combine the two geojsons
|
|
||||||
let geoJSON = {
|
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: [...us.features, ...ca.features]
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log(markers);
|
|
||||||
|
|
||||||
let visitedRegions = data.props.visitedRegions;
|
let visitedRegions = data.props.visitedRegions;
|
||||||
|
|
||||||
|
let geoJSON = data.props.geoJSON;
|
||||||
|
|
||||||
let visitArray = [];
|
let visitArray = [];
|
||||||
|
|
||||||
// turns in into an array of the visits
|
// turns in into an array of the visits
|
||||||
|
@ -37,6 +29,7 @@
|
||||||
visitArray.push(el.region);
|
visitArray.push(el.region);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// mapped to the checkbox
|
||||||
let showGEO = true;
|
let showGEO = true;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -94,7 +87,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
{#if showGEO}
|
{#if showGEO}
|
||||||
<GeoJSON id="states" data={geoJSON} promoteId="ISOCODE">
|
<GeoJSON id="states" data={data.props.geoJSON} promoteId="ISOCODE">
|
||||||
<LineLayer
|
<LineLayer
|
||||||
layout={{ 'line-cap': 'round', 'line-join': 'round' }}
|
layout={{ 'line-cap': 'round', 'line-join': 'round' }}
|
||||||
paint={{ 'line-color': 'grey', 'line-width': 3 }}
|
paint={{ 'line-color': 'grey', 'line-width': 3 }}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue