Skip to content

Commit

Permalink
added a condition to wait for the map to load before mapping objects
Browse files Browse the repository at this point in the history
  • Loading branch information
piggydoughnut committed May 30, 2024
1 parent 00745ba commit 7fadf7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/client/components/OfficeFloorMap.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { MouseEventHandler } from 'react'
import React, { MouseEventHandler, useState } from 'react'
import { Avatar, Button, P } from '#client/components/ui'
import {
OfficeArea,
Expand Down Expand Up @@ -104,6 +104,7 @@ export const OfficeFloorMap: React.FC<OfficeFloorMapProps> = ({
clickablePoints,
onToggle,
}) => {
const [isMapLoaded, setIsMapLoaded] = useState(false)
const me = useStore(stores.me)
const initialStartPosition = selectedPointId
? mappablePoints?.find(
Expand Down Expand Up @@ -208,8 +209,9 @@ export const OfficeFloorMap: React.FC<OfficeFloorMapProps> = ({
src={area.map}
alt={`${area.name} floor plan`}
className="opacity-80"
onLoad={() => setIsMapLoaded(true)}
/>
{mapObjects(1)}
{isMapLoaded && mapObjects(1)}
</div>
<div
className={cn(
Expand Down
12 changes: 8 additions & 4 deletions src/client/components/ui/ImageWithPanZoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const ImageWithPanZoom = ({
containerClassName,
}: ImageWithPanZoomProps) => {
const [imgScale, setImgScale] = useState(1)
const [isMapLoaded, setIsMapLoaded] = useState(false)
const containerRef = useRef(null)
const imageRef = useRef(null)
const panZoomRef = useRef(null)
Expand Down Expand Up @@ -65,11 +66,14 @@ export const ImageWithPanZoom = ({
'max-w-auto max-h-[720px] m-auto object-cover',
className
)}
onLoad={() => setIsMapLoaded(true)}
/>
<div className="absolute top-0 left-0 w-full h-full">
{/* passing scale so we can do reverse scaling on the mapped points */}
{imageOverlayMappingFn(imgScale)}
</div>
{isMapLoaded && (
<div className="absolute top-0 left-0 w-full h-full">
{/* passing scale so we can do reverse scaling on the mapped points */}
{imageOverlayMappingFn(imgScale)}
</div>
)}
</div>
</PanZoom>
</div>
Expand Down

0 comments on commit 7fadf7c

Please sign in to comment.