Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeline close #39

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/pathOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function pathToGraphic(path: ILocation[]): IGraphicOptions {
})
graphic.clear()

graphic.lineStyle(1 / scale, 0x5858ff, 1)
graphic.lineStyle(1 / scale, 0x005cc8, 1)
graphic.moveTo(projectedCords[0].x, projectedCords[0].y)
for (let i = 1; i < projectedCords.length; i++) {
graphic.lineTo(projectedCords[i].x, projectedCords[i].y)
Expand All @@ -97,7 +97,7 @@ function vesselToGraphic(
const sprite: PIXI.Sprite = new PIXI.Sprite(location.heading ? arrowTexture : circleTexture)
sprite.anchor.set(0.5, 0.5)
sprite.rotation = Math.PI / 2 + (location.heading ? (location.heading * Math.PI) / 180 : 0)
sprite.tint = 0x5858ff
sprite.tint = 0x005cc8
sprite.x = projectedCords.x
sprite.y = projectedCords.y
sprite.width = 20 / scale
Expand Down
10 changes: 6 additions & 4 deletions src/components/timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from 'react'
import { useVesselGuiContext } from '../contexts/vesselGuiContext'
import CloseSVG from '../svgs/closeSVG'
interface ITimelineProps {
timestamps: Date[]
onChange(index: number): void
Expand All @@ -8,7 +9,7 @@ interface ITimelineProps {
}

export default function Timeline({ timestamps, onChange, timelineVal, setTimelineVal }: ITimelineProps) {
const { setSelectedVesselPath, selectedVesselmmsi, selectedVesselPath } = useVesselGuiContext()
const { setSelectedVesselPath, selectedVesselmmsi, selectedVesselPath, setPathIsShown } = useVesselGuiContext()
function handleChange(val: string) {
try {
const intVal: number = parseInt(val)
Expand All @@ -21,6 +22,7 @@ export default function Timeline({ timestamps, onChange, timelineVal, setTimelin

function closePath() {
setSelectedVesselPath([])
setPathIsShown(false)
}

useEffect(() => {
Expand All @@ -32,16 +34,16 @@ export default function Timeline({ timestamps, onChange, timelineVal, setTimelin
}, [selectedVesselmmsi, setSelectedVesselPath, setTimelineVal])

return selectedVesselPath.length !== 0 ? (
<div className="bg-gray-700 text-white rounded-xl mx-4 px-4 py-2 shadow max-w-[700px] w-full">
<div className="bg-gray-700 text-white rounded-xl px-4 py-2 shadow max-w-[700px] w-full">
<div className="w-full flex items-center relative">
<p className="absolute left-1/2 transform -translate-x-1/2 font-bold text-center">
Timestamp:{' '}
{timelineVal && timestamps[timelineVal]
? timestamps[timelineVal].toISOString().replace('T', ' ').replace('Z', '').slice(0, 19)
: 'unknown'}
</p>
<button onClick={closePath} className="ml-auto blue-badge">
Close
<button title="Hide path" onClick={closePath} className="ml-auto -mr-2">
<CloseSVG />
</button>
</div>
<input
Expand Down
15 changes: 12 additions & 3 deletions src/components/vesselMarkerOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export default function VesselMarkerOverlay({ simpleVessels, monitoredVessels }:
setSelectedVesselmmsi((selectedVesselmmsi) =>
selectedVesselmmsi === vessel.simpleVessel.mmsi ? undefined : vessel.simpleVessel.mmsi
)

markerOptions.push(
displayVesselToSpriteMarkerOption(
vessel,
Expand All @@ -80,7 +79,8 @@ export default function VesselMarkerOverlay({ simpleVessels, monitoredVessels }:
circleTexture,
selectedCircleTexture,
selectedVesselmmsi === vessel.simpleVessel.mmsi,
onClick
onClick,
() => overlay.redraw()
)
)
}
Expand Down Expand Up @@ -139,7 +139,8 @@ function displayVesselToSpriteMarkerOption(
circleTexture: PIXI.Texture,
selectedCircleTexture: PIXI.Texture,
isSelected: boolean,
onClick: () => void
onClick: () => void,
redraw: () => void
): ISpriteMarkerOptions {
const { simpleVessel, monitoredInfo } = vessel

Expand All @@ -165,6 +166,14 @@ function displayVesselToSpriteMarkerOption(
sprite.eventMode = 'dynamic'
sprite.cursor = 'pointer'
sprite.on('click', onClick)
sprite.on('mouseover', () => {
sprite.alpha = monitoredInfo ? 1 : 0.7
redraw()
})
sprite.on('mouseout', () => {
sprite.alpha = monitoredInfo ? 1 : 0.3
redraw()
})

const size = isSelected ? 20 : 13
const position: L.LatLngTuple = [simpleVessel.location.point.lat, simpleVessel.location.point.lon]
Expand Down
Loading