Basic project structure and some drafts
This commit is contained in:
8 files changed
+778
-24
No files matched your search
@@ -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();
|
||||
});
|
||||
Reference in new issue
Block a user