Skip to content

Commit

Permalink
Merge pull request #1288 from opentripplanner/itin-overlay-render-cor…
Browse files Browse the repository at this point in the history
…rectly

Overlay Popup Behavior Correction
  • Loading branch information
miles-grant-ibigroup authored Nov 5, 2024
2 parents 0ceaa2e + 6909653 commit ea5c106
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions lib/components/map/itinerary-summary-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Marker } from 'react-map-gl'
import centroid from '@turf/centroid'
import distance from '@turf/distance'
import polyline from '@mapbox/polyline'
import React, { useContext, useState } from 'react'
import React, { useContext } from 'react'
import styled from 'styled-components'

import * as narriativeActions from '../../actions/narrative'
Expand Down Expand Up @@ -147,19 +147,20 @@ const ItinerarySummaryOverlay = ({
// @ts-expect-error React context is populated dynamically
const { LegIcon } = useContext(ComponentContext)

const [sharedTimeout, setSharedTimeout] = useState<null | NodeJS.Timeout>(
null
)

if (!itins || !visible) return <></>
const mergedItins: ItinWithGeometry[] = addTrueIndex(
doMergeItineraries(itins).mergedItineraries.map(addItinLineString)
const indexedItins: ItinWithGeometry[] = addTrueIndex(
itins.map(addItinLineString)
)
const mergedItins: ItinWithGeometry[] =
doMergeItineraries(indexedItins).mergedItineraries

const midPoints = mergedItins.reduce<ItinUniquePoint[]>(
(prev: ItinUniquePoint[], curItin: ItinWithGeometry) => {
prev.push(getUniquePoint(curItin, prev))
return prev
},
[]
)

const midPoints = mergedItins.reduce<ItinUniquePoint[]>((prev, curItin) => {
prev.push(getUniquePoint(curItin, prev))
return prev
}, [])
// The first point is probably not well placed, so let's run the algorithm again
if (midPoints.length > 1) {
midPoints[0] = getUniquePoint(mergedItins[0], midPoints)
Expand All @@ -186,18 +187,8 @@ const ItinerarySummaryOverlay = ({
onClick={() => {
setActive({ index: mp.itin.index })
}}
// TODO: useCallback here (getting weird errors?)
onMouseEnter={() => {
setSharedTimeout(
setTimeout(() => {
setVisible({ index: mp.itin.index })
}, 150)
)
}}
onMouseLeave={() => {
sharedTimeout && clearTimeout(sharedTimeout)
setVisible({ index: null })
}}
// TODO: restore setting visible itinerary on hover without
// causing endless re-render?
>
<MetroItineraryRoutes
expanded={false}
Expand Down

0 comments on commit ea5c106

Please sign in to comment.