search: per-leg colored polylines + transit whole-day toggle
This commit is contained in:
@@ -51,6 +51,17 @@
|
||||
destination: data.destination || null,
|
||||
departureDate: data.departure_date || '',
|
||||
departureTime: data.departure_time || '',
|
||||
transitWholeDay: data.transit_whole_day || false,
|
||||
|
||||
toggleTransitWholeDay() {
|
||||
const u = new URL(window.location.href);
|
||||
if (u.searchParams.get('transit_whole_day') === '1') {
|
||||
u.searchParams.delete('transit_whole_day');
|
||||
} else {
|
||||
u.searchParams.set('transit_whole_day', '1');
|
||||
}
|
||||
window.location.href = u.toString();
|
||||
},
|
||||
|
||||
get departureLabel() {
|
||||
return this.departure?.properties?.label || this.departure?.properties?.name || 'Départ';
|
||||
@@ -77,83 +88,11 @@
|
||||
(r.local_solutions?.number || 0);
|
||||
},
|
||||
|
||||
// showJourneyOnMap is intentionally a no-op: the real route
|
||||
// rendering lives in window.showJourneyRoute (search-results.html),
|
||||
// invoked by selectionManager.selectItem.
|
||||
showJourneyOnMap(journey, index) {
|
||||
console.log('showJourneyOnMap called', index, journey);
|
||||
this.selectedJourney = index;
|
||||
|
||||
if (!window.parcoursmobMap) {
|
||||
console.log('Map not found');
|
||||
return;
|
||||
}
|
||||
const map = window.parcoursmobMap;
|
||||
|
||||
// Supprimer l'ancien tracé s'il existe
|
||||
if (map.getSource('journey-route')) {
|
||||
map.removeLayer('journey-route-line');
|
||||
map.removeSource('journey-route');
|
||||
}
|
||||
|
||||
// Collecter toutes les coordonnées des legs
|
||||
const coordinates = [];
|
||||
|
||||
journey.legs.forEach(leg => {
|
||||
if (leg.legGeometry && leg.legGeometry.points) {
|
||||
try {
|
||||
const decoded = polyline.decode(leg.legGeometry.points);
|
||||
decoded.forEach(point => {
|
||||
const lng = point[1];
|
||||
const lat = point[0];
|
||||
if (lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180) {
|
||||
coordinates.push([lng, lat]);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Erreur décodage polyline:', e);
|
||||
}
|
||||
} else if (leg.from && leg.to) {
|
||||
const fromLng = leg.from.lon || leg.from.lng;
|
||||
const fromLat = leg.from.lat;
|
||||
const toLng = leg.to.lon || leg.to.lng;
|
||||
const toLat = leg.to.lat;
|
||||
|
||||
if (fromLat && fromLng) coordinates.push([fromLng, fromLat]);
|
||||
if (toLat && toLng) coordinates.push([toLng, toLat]);
|
||||
}
|
||||
});
|
||||
|
||||
if (coordinates.length < 2) return;
|
||||
|
||||
// Ajouter le tracé sur la carte
|
||||
map.addSource('journey-route', {
|
||||
type: 'geojson',
|
||||
data: {
|
||||
type: 'Feature',
|
||||
properties: {},
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: coordinates
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
map.addLayer({
|
||||
id: 'journey-route-line',
|
||||
type: 'line',
|
||||
source: 'journey-route',
|
||||
layout: {
|
||||
'line-join': 'round',
|
||||
'line-cap': 'round'
|
||||
},
|
||||
paint: {
|
||||
'line-color': '#283959',
|
||||
'line-width': 4
|
||||
}
|
||||
});
|
||||
|
||||
// Ajuster la vue pour montrer tout le tracé
|
||||
const bounds = new maplibregl.LngLatBounds();
|
||||
coordinates.forEach(coord => bounds.extend(coord));
|
||||
map.fitBounds(bounds, { padding: 50 });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user