Skip to content

Commit

Permalink
Improve naming of maps
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Oct 28, 2024
1 parent d324f95 commit 81b5756
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export const MissionMapView = ({ mission }: MissionProps) => {
[mission.tasks]
)

let displayedMapName = mission.map?.mapName.split('.')[0].replace(/[^0-9a-z-A-Z ]/g, ' ')
displayedMapName = displayedMapName ? displayedMapName.charAt(0).toUpperCase() + displayedMapName.slice(1) : ' '

useEffect(() => {
BackendAPICaller.getMap(mission.installationCode!, mission.map?.mapName!)
.then((imageBlob) => {
Expand Down Expand Up @@ -130,7 +133,7 @@ export const MissionMapView = ({ mission }: MissionProps) => {

return (
<MapCard style={{ boxShadow: tokens.elevation.raised }}>
<Typography variant="h3">{mission.map?.mapName}</Typography>
<Typography variant="h3">{displayedMapName}</Typography>
<SyledContainer>
<StyledElements>
<StyledMap id="mapCanvas" />
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,6 @@
"No alerts": "No alerts",
"minutes ago": "minutes ago",
"Failed to retrieve previous mission runs": "Failed to retrieve previous mission runs",
"Documentation": "Documentation"
"Documentation": "Documentation",
"Map of": "Map of"
}
3 changes: 2 additions & 1 deletion frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,6 @@
"No alerts": "Ingen varsler",
"minutes ago": "minutter siden",
"Failed to retrieve previous mission runs": "Kunne ikke hente tildigere oppdragskjøringer",
"Documentation": "Dokumentasjon"
"Documentation": "Dokumentasjon",
"Map of": "Kart over"
}
31 changes: 22 additions & 9 deletions frontend/src/utils/DeckMapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MapMetadata } from 'models/MapMetadata'
import { Pose } from 'models/Pose'
import { MapCompass } from 'utils/MapCompass'
import { Deck } from 'models/Deck'
import { useLanguageContext } from 'components/Contexts/LanguageContext'

interface DeckProps {
deck: Deck
Expand All @@ -23,7 +24,6 @@ const StyledMap = styled.canvas`
const StyledMapLimits = styled.div`
display: flex;
flex-direction: column;
padding-left: 30px;
justify-content: center;
align-items: center;
`
Expand All @@ -35,16 +35,24 @@ const StyledLoading = styled.div`

const StyledMapCompass = styled.div`
display: flex;
flex-direction: columns;
flex-direction: row;
align-items: end;
`

const StyledCaption = styled.div`
display: flex;
flex-direction: column;
justify-content: left;
gap: 10px;
`

export const DeckMapView = ({ deck, markedRobotPosition }: DeckProps) => {
const [mapCanvas, setMapCanvas] = useState<HTMLCanvasElement>(document.createElement('canvas'))
const [mapImage, setMapImage] = useState<HTMLImageElement>(document.createElement('img'))
const [mapContext, setMapContext] = useState<CanvasRenderingContext2D>()
const [mapMetadata, setMapMetadata] = useState<MapMetadata>()
const [isLoading, setIsLoading] = useState<boolean>()
const { TranslateText } = useLanguageContext()

const updateMap = useCallback(() => {
let context = mapCanvas.getContext('2d')
Expand All @@ -65,6 +73,9 @@ export const DeckMapView = ({ deck, markedRobotPosition }: DeckProps) => {
return image
}

let mapName = mapMetadata?.mapName.split('.')[0].replace(/[^0-9a-z-A-Z ]/g, ' ')
mapName = mapName ? mapName.charAt(0).toUpperCase() + mapName.slice(1) : ' '

useEffect(() => {
const processImageURL = (imageBlob: Blob | string) => {
const imageObjectURL = typeof imageBlob === 'string' ? imageBlob : URL.createObjectURL(imageBlob as Blob)
Expand Down Expand Up @@ -125,13 +136,15 @@ export const DeckMapView = ({ deck, markedRobotPosition }: DeckProps) => {
)}
{!isLoading && (
<StyledMapLimits>
<Typography variant="h2">
{mapMetadata?.mapName ? mapMetadata.mapName : 'No map available'}
</Typography>
<StyledMapCompass>
<StyledMap id="deckMapCanvas" />
{mapMetadata && <MapCompass />}
</StyledMapCompass>
<StyledCaption>
<StyledMapCompass>
<StyledMap id="deckMapCanvas" />
{mapMetadata && <MapCompass />}
</StyledMapCompass>
<Typography italic variant="body_short">
{TranslateText('Map of') + ' ' + mapName}
</Typography>
</StyledCaption>
</StyledMapLimits>
)}
</>
Expand Down

0 comments on commit 81b5756

Please sign in to comment.