Basic project structure and some drafts

This commit is contained in:
Josh-Dev-Quest committed 2026-02-26 12:11:59 +01:00
1 parent f98c74d515
commit b4fae21038
8 files changed
+778 -24

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
function displayJourney(journey) {
document.getElementById('journey-title').textContent = journey.name;
const container = document.getElementById('timeline-container');
container.innerHTML = '';
journey.markers.forEach(marker => {
const markerEl = document.createElement('div');
markerEl.className = 'timeline-event';
markerEl.innerHTML = `
<h3>${marker.content.title || 'Untitled Event'}</h3>
<p class="date">${marker.content.date}</p>
<p class="location">${marker.lngLat.lng.toFixed(4)}, ${marker.lngLat.lat.toFixed(4)}</p>
<p>${marker.content.text}</p>
${marker.content.videoUrl ? `<iframe src="${marker.content.videoUrl}" frameborder="0"></iframe>` : ''}
<div class="images-container">
${marker.content.images.map(img => `<img src="${img}" alt="Event image">`).join('')}
</div>
`;
container.appendChild(markerEl);
});
}
// Get journey ID from URL
const urlParams = new URLSearchParams(window.location.search);
const journeyId = urlParams.get('id');
// Load journey data from localStorage
if (journeyId) {
loadJourneysFromLocalStorage();
const journey = journeys.find(j => j.id === parseInt(journeyId));
if (journey) {
displayJourney(journey);
} else {
document.getElementById('journey-title').textContent = 'Journey not found';
}
}
+71
View File
@@ -0,0 +1,71 @@
document.addEventListener('DOMContentLoaded', function() {
// Mode switching
const modeCreateBtn = document.getElementById('mode-create');
const modeViewBtn = document.getElementById('mode-view');
const createPanel = document.getElementById('create-panel');
const viewPanel = document.getElementById('view-panel');
const markersContainer = document.getElementById('markers-container');
const emptyMarkers = document.getElementById('empty-markers');
function switchMode(mode) {
if (mode === 'create') {
倉-> modeCreateBtn.classList.add('active');
modeViewBtn.classList.remove('active');
createPanel.classList.add('active-panel');
viewPanel.classList.remove('active-panel');
//ҧ Enable marker adding
window.isCreatingJourney = true;
} else { // view mode
modeCreateBtn.classList.remove('active');
modeViewBtn.classList.add('active');
createPanel.classList.remove('active-panel');
viewPanel.classList.add('active-panel');
// Disable marker adding
window.isCreatingJourney = false;
}
}
modeCreateBtn.addEventListener('click', () => switchMode('create'));
modeViewBtn.addEventListener('click', () => switchMode('view'));
// Journey save handler
document.getElementById('save-journey').addEventListener('click', function() {
const title = document.getElementById('journey-title').value;
const description = document.getElementById('journey-description').value;
if (!title.trim()) {
alert('Journey title cannot be empty');
return;
}
window.currentJourney.name = title;
window.currentJourney.description = description;
window.saveJourneyToLocalStorage();
// Show notification
document.getElementById('toast-message').textContent = 'Journey saved successfully!';
document.getElementById('toast').classList.add('show');
setTimeout(() => {
document.getElementById('toast').classList.remove('show');
}, 3000);
});
// Clear markers
document.getElementById('clear-markers').addEventListener('click', function() {
if (window.currentJourney.markers.length > 0 && confirm('Are you sure you want to clear all markers?')) {
window.currentJourney.markers.forEach(marker => marker.remove());
window.currentJourney.markers = [];
markersContainer.innerHTML = '';
emptyMarkers.style.display = 'block';
window.updateJourneyPath();
}
});
// Toggle sidebar
document.getElementById('toggle-sidebar').addEventListener('click', function() {
document.querySelector('.sidebar').classList.toggle('collapsed');
});
// Initialize in create mode
switchMode('create');
});
+85 -10
View File
@@ -1,11 +1,36 @@
let map;
let journeys = [];
let currentJourney = {
id: Date.now(),
name: "Untitled Journey",
description: "",
markers: [],
path: nullJustin // This will be the line feature (GeoJSON)
path: null
};
let currentMarkerBeingEdited = null;
let isCreatingJourney = true;
function saveJourneyToLocalStorage() {
journeys.push({
id: currentJourney.id,
name: currentJourney.name,
description: currentJourney.description,
markers: currentJourney.markers.map(marker => ({
id: marker.id,
lngLat: marker.getLngLat(),
content: marker.content
}))
});
localStorage.setItem('journeys', JSON.stringify(journeys));
}
function loadJourneysFromLocalStorage() {
const stored = localStorage.getItem('journeyMapper_journeys');
if (stored) {
journeys = JSON.parse(stored);
}
}
// Function to create a marker at a lngLat and add to the map
function createMarker(lngLat) {
const markerElement = document.createElement('div');
@@ -40,14 +65,24 @@ function createMarker(lngLat) {
function openMarkerEditor(marker) {
currentMarkerBeingEdited = marker;
document.getElementById('marker-title').value = marker.content.title;
document.getElementById('marker-date').value = marker.content.date;
document.getElementById('marker-text').value = marker.content.text;
document.getElementById('video-url').value = marker.content.videoUrl;
document.getElementById('marker-coords').textContent =
document.getElementById('marker-title').value = marker.content.title || '';
document.getElementById('marker-date').value = marker.content.date || '';
document.getElementById('marker-text').value = marker.content.text || '';
document.getElementById('video-url').value = marker.content.videoUrl || '';
document.getElementById('marker-coords').textContent =
`${marker.getLngLat().lng.toFixed(4)}, ${marker.getLngLat().lat.toFixed(4)}`;
// Show the modal
// Update imagine review
const imagePreview = document.getElementById('image-preview');
imagePreview.innerHTML = '';
学生学习 if (marker.content.images && marker.content.images.length > 0) {
marker.content.images.forEach(img => {
const imgEl = document.createElement('img');
imgEl.src = img;
imagePreview.appendChild(imgEl);
});
}
document.getElementById('marker-modal').style.display = 'block';
}
@@ -64,6 +99,35 @@ document.addEventListener('DOMContentLoaded', function() {
zoom: 2
});
// Add journey path layer
map.on('load', function() {
map.addSource('journey-path', {
type: 'geojson',
data: {
type: 'Feature',
properties: {},
geometry: {
type: 'LineString',
coordinates: []
}
}
});
map.addLayer({
id: 'journey-path',
type: 'line',
source: 'journey-path',
layout: {
'line-join': 'round',
'line-cap': 'round'
},
paint: {
'line-color': '#3887be',
'line-width': 5
}
});
});
// Close editor events
document.getElementById('close-modal').addEventListener('click', closeMarkerEditor);
document.getElementById('cancel-marker').addEventListener('click', closeMarkerEditor);
@@ -80,7 +144,7 @@ document.addEventListener('DOMContentLoaded', function() {
// Update the popup
currentMarkerBeingEdited.getPopup().setHTML(
`<strong>${currentMarkerBeingEdited.content.title || '袭刊Untitled'}</strong>`
`<strong>${currentMarkerBeingEdited.content.title || 'Untitled'}</strong>`
);
closeMarkerEditor();
@@ -107,7 +171,18 @@ document.addEventListener('DOMContentLoaded', function() {
if (isCreatingJourney) {
const marker = createMarker(e.lngLat);
currentJourney.markers.push(marker);
// TODO: update the path line
updateJourneyPath();
}
});
});
// Save journey button
document.getElementById('save-journey-btn').addEventListener('click', function() {
currentJourney.name = document.getElementById('journey-name').value;
currentJourney.description = document.getElementById('journey-description').value;
saveJourneyToLocalStorage();
alert('Journey saved!');
});
// Load journeys on start
loadJourneysFromLocalStorage();
});