44
55const API_KEY = 'SvPHVJ5fPXkfJPKsu6958pwLCh5Oidhq' ;
66const API_URL = 'https://prim.iledefrance-mobilites.fr/marketplace/stop-monitoring' ;
7- const LINE_REPORTS_API_URL = 'https://prim.iledefrance-mobilites.fr/marketplace/v2/navitia' ;
7+ const LINE_REPORTS_API_URL = 'https://prim.iledefrance-mobilites.fr/marketplace/v2/navitia/line_reports ' ;
88
99// Configuration de l'affichage des horaires
1010const MAX_SCHEDULES_METRO_TRAM = 5 ; // Nombre d'horaires affichés pour Métro/Tram
@@ -165,9 +165,9 @@ function parseSchedulesData(data) {
165165}
166166
167167/**
168- * Récupère les perturbations pour une ligne
168+ * Récupère les perturbations pour une ligne et un arrêt spécifique
169169 */
170- export async function fetchLineDisruptions ( lineRef ) {
170+ export async function fetchLineDisruptions ( lineRef , idRefZdA = null , routeType = null ) {
171171 try {
172172 const cleanedLineRef = cleanLineRef ( lineRef ) ;
173173
@@ -176,11 +176,28 @@ export async function fetchLineDisruptions(lineRef) {
176176 return [ ] ;
177177 }
178178
179- // Construire l'URL avec le LineRef au format Navitia
180- const navitiaLineId = `line:IDFM:${ cleanedLineRef } ` ;
181- const url = `${ LINE_REPORTS_API_URL } /lines/${ encodeURIComponent ( navitiaLineId ) } /line_reports` ;
179+ let url ;
180+
181+ // Pour TER : utiliser uniquement le stop_point (pas de ligne), departures car il y a les disruptions par arret
182+ if ( routeType === 'TER' && idRefZdA ) {
183+ const stopPointId = `stop_point:IDFM:monomodalStopPlace:${ idRefZdA } ` ;
184+ url = `${ LINE_REPORTS_API_URL } /stop_points/${ encodeURIComponent ( stopPointId ) } /departures?count=10` ;
185+ console . log ( '📡 Récupération perturbations TER (stop_point seul):' , stopPointId ) ;
186+ }
187+ // Si idRefZdA est fourni (RER, Transilien), construire l'URL avec ligne + stop_point, departures car il y a les disruptions par arret
188+ else if ( idRefZdA ) {
189+ const navitiaLineId = `line:IDFM:${ cleanedLineRef } ` ;
190+ const stopPointId = `stop_point:IDFM:monomodalStopPlace:${ idRefZdA } ` ;
191+ url = `${ LINE_REPORTS_API_URL } /lines/${ encodeURIComponent ( navitiaLineId ) } /stop_points/${ encodeURIComponent ( stopPointId ) } /departures?count=10` ;
192+ console . log ( '📡 Récupération perturbations ligne + arrêt:' , navitiaLineId , stopPointId ) ;
193+ }
194+ // Sinon, utiliser line_reports (Métro, Tram)
195+ else {
196+ const navitiaLineId = `line:IDFM:${ cleanedLineRef } ` ;
197+ url = `${ LINE_REPORTS_API_URL } /lines/${ encodeURIComponent ( navitiaLineId ) } /line_reports` ;
198+ console . log ( '📡 Récupération perturbations ligne:' , navitiaLineId ) ;
199+ }
182200
183- console . log ( '📡 Récupération perturbations ligne:' , navitiaLineId ) ;
184201 console . log ( '📡 URL:' , url ) ;
185202
186203 const response = await fetch ( url , {
0 commit comments