Skip to content

Commit

Permalink
change marker scaling logic to reduce jank
Browse files Browse the repository at this point in the history
  • Loading branch information
vmork committed Nov 17, 2024
1 parent 4aa3ccf commit a5d0430
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/app/student/map/_components/BoothMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function BoothMarker({ booth, scale }: { booth: Booth; scale: number }) {
key={booth.id}
longitude={booth.center[0]}
latitude={booth.center[1]}>
<div className="cursor-default" style={{ transform: `scale(${scale})` }}>
<div
className="cursor-default transition"
style={{ transform: `scale(${scale})` }}>
{logoSrc ? (
<div className="flex size-[60px]">
<Image
Expand Down
7 changes: 4 additions & 3 deletions src/app/student/map/_components/MapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export function MapComponent({
const { pathname } = window.location
window.history.replaceState(null, "", pathname)
}, 300)
setMarkerScale(0.6)
return () => clearTimeout(timeout)
}, [location])

Expand Down Expand Up @@ -162,8 +161,10 @@ export function MapComponent({
function onZoomChange() {
const zoom = mapRef.current?.getZoom()
if (zoom === undefined) return
const scale = Math.max(0.2, Math.min(1, 1 + (zoom - 20) * 0.5))
setMarkerScale(scale)

if (zoom < 18.5) setMarkerScale(0.2)
else if (zoom < 20.5) setMarkerScale(0.5)
else setMarkerScale(1.0)
}

return (
Expand Down
1 change: 0 additions & 1 deletion src/app/student/map/editor/EditorMapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export default function EditorMapComponent({
[18.079, 59.35]
]}
mapStyle="https://api.maptiler.com/maps/376fa556-c405-4a91-8e9e-15be82eb3a58/style.json?key=mgMcr2yF2fWUHzf27ygv">

{/** Order sensitive! */}
<Source
id="buildings"
Expand Down
2 changes: 1 addition & 1 deletion src/app/student/map/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const style = {
routeHintColor: "#F3ECC3",
routeHintWidth: 1,

roomBackgroundColor: "#1f2b24",
roomBackgroundColor: "#1f2b24"
} as const

export enum LineType {
Expand Down

0 comments on commit a5d0430

Please sign in to comment.