Add fallbacks when retrieving full route features to handle cases where source data access methods vary.

This commit is contained in:
Eugene Burmakin 2026-01-07 00:18:26 +01:00
parent 4874245139
commit 0de2cb26b8

View file

@ -142,8 +142,8 @@ export class EventHandlers {
if (!routesLayer) return if (!routesLayer) return
// Get the full feature from source (not the clipped tile version) // Get the full feature from source (not the clipped tile version)
const fullFeature = this._getFullRouteFeature(clickedFeature.properties) // Fallback to clipped feature if full feature not found
if (!fullFeature) return const fullFeature = this._getFullRouteFeature(clickedFeature.properties) || clickedFeature
// If a route is selected and we're hovering over a different route, show both // If a route is selected and we're hovering over a different route, show both
if (this.selectedRouteFeature) { if (this.selectedRouteFeature) {
@ -200,7 +200,23 @@ export class EventHandlers {
if (!source) return null if (!source) return null
// Get the source data (GeoJSON FeatureCollection) // Get the source data (GeoJSON FeatureCollection)
const sourceData = source._data || routesLayer.data // Try multiple ways to access the data
let sourceData = null
// Method 1: Internal _data property (most common)
if (source._data) {
sourceData = source._data
}
// Method 2: Serialize and deserialize (fallback)
else if (source.serialize) {
const serialized = source.serialize()
sourceData = serialized.data
}
// Method 3: Use cached data from layer
else if (routesLayer.data) {
sourceData = routesLayer.data
}
if (!sourceData || !sourceData.features) return null if (!sourceData || !sourceData.features) return null
// Find the matching feature by properties // Find the matching feature by properties
@ -290,8 +306,8 @@ export class EventHandlers {
const properties = clickedFeature.properties const properties = clickedFeature.properties
// Get the full feature from source (not the clipped tile version) // Get the full feature from source (not the clipped tile version)
const fullFeature = this._getFullRouteFeature(properties) // Fallback to clipped feature if full feature not found
if (!fullFeature) return const fullFeature = this._getFullRouteFeature(properties) || clickedFeature
// Store selected route (use full feature) // Store selected route (use full feature)
this.selectedRouteFeature = fullFeature this.selectedRouteFeature = fullFeature