Compare commits

..

No commits in common. "0de2cb26b80fe618b2d1489a954ebf0ce4f2bfff" and "b6eeba437052a5b8b936d98d6c2b10a8c7592de3" have entirely different histories.

View file

@ -135,24 +135,20 @@ export class EventHandlers {
* Handle route hover
*/
handleRouteHover(e) {
const clickedFeature = e.features[0]
if (!clickedFeature) return
const feature = e.features[0]
if (!feature) return
const routesLayer = this.controller.layerManager.getLayer('routes')
if (!routesLayer) return
// Get the full feature from source (not the clipped tile version)
// Fallback to clipped feature if full feature not found
const fullFeature = this._getFullRouteFeature(clickedFeature.properties) || clickedFeature
// If a route is selected and we're hovering over a different route, show both
if (this.selectedRouteFeature) {
// Check if we're hovering over the same route that's selected
const isSameRoute = this._areFeaturesSame(this.selectedRouteFeature, fullFeature)
const isSameRoute = this._areFeaturesSame(this.selectedRouteFeature, feature)
if (!isSameRoute) {
// Show both selected and hovered routes
const features = [this.selectedRouteFeature, fullFeature]
const features = [this.selectedRouteFeature, feature]
routesLayer.setHoverRoute({
type: 'FeatureCollection',
features: features
@ -162,9 +158,9 @@ export class EventHandlers {
}
} else {
// No selection, just show hovered route
routesLayer.setHoverRoute(fullFeature)
routesLayer.setHoverRoute(feature)
// Create markers for hovered route
this._createRouteMarkers(fullFeature)
this._createRouteMarkers(feature)
}
}
@ -187,47 +183,6 @@ export class EventHandlers {
}
}
/**
* Get full route feature from source data (not clipped tile version)
* MapLibre returns clipped geometries from queryRenderedFeatures()
* We need the full geometry from the source for proper highlighting
*/
_getFullRouteFeature(properties) {
const routesLayer = this.controller.layerManager.getLayer('routes')
if (!routesLayer) return null
const source = this.map.getSource(routesLayer.sourceId)
if (!source) return null
// Get the source data (GeoJSON FeatureCollection)
// 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
// Find the matching feature by properties
return sourceData.features.find(feature => {
const props = feature.properties
return props.startTime === properties.startTime &&
props.endTime === properties.endTime &&
props.pointCount === properties.pointCount
})
}
/**
* Compare two features to see if they represent the same route
*/
@ -302,24 +257,20 @@ export class EventHandlers {
* Handle route click
*/
handleRouteClick(e) {
const clickedFeature = e.features[0]
const properties = clickedFeature.properties
const feature = e.features[0]
const properties = feature.properties
// Get the full feature from source (not the clipped tile version)
// Fallback to clipped feature if full feature not found
const fullFeature = this._getFullRouteFeature(properties) || clickedFeature
// Store selected route (use full feature)
this.selectedRouteFeature = fullFeature
// Store selected route
this.selectedRouteFeature = feature
// Update hover layer to show selected route
const routesLayer = this.controller.layerManager.getLayer('routes')
if (routesLayer) {
routesLayer.setHoverRoute(fullFeature)
routesLayer.setHoverRoute(feature)
}
// Create markers for selected route
this._createRouteMarkers(fullFeature)
this._createRouteMarkers(feature)
// Calculate duration
const durationSeconds = properties.endTime - properties.startTime