-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1077 from MTES-MCT/fix-map-building-colors
Fix building colors on the map
- Loading branch information
Showing
12 changed files
with
701 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
square-fill-*.png |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useMap } from 'react-map-gl/maplibre'; | ||
import { useEffect } from 'react'; | ||
|
||
interface UseMapImageOptions { | ||
id: string; | ||
path: string; | ||
} | ||
|
||
export function useMapImage(options: UseMapImageOptions) { | ||
const { housingMap: map } = useMap(); | ||
|
||
useEffect(() => { | ||
if (map && !map.hasImage(options.id)) { | ||
map | ||
.loadImage(options.path) | ||
.then((response) => { | ||
map.addImage(options.id, response.data, { | ||
sdf: false | ||
}); | ||
}) | ||
.catch(console.error); | ||
} | ||
}, [map, options.id, options.path]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import async from 'async'; | ||
import * as path from 'node:path'; | ||
import sharp, { Color, OutputInfo } from 'sharp'; | ||
|
||
import { HousingStatus } from '@zerologementvacant/models'; | ||
import statusColors from '../components/Map/status-colors'; | ||
|
||
const SIZE = 15; | ||
const BORDER_SIZE = 1; | ||
|
||
interface CreateImageOptions { | ||
border: Color; | ||
background: Color; | ||
filename: string; | ||
} | ||
|
||
const directory = path.join(__dirname, '..', '..', 'public', 'map'); | ||
|
||
async function createImage(options: CreateImageOptions): Promise<OutputInfo> { | ||
return sharp({ | ||
create: { | ||
channels: 3, | ||
background: options.background, | ||
width: SIZE, | ||
height: SIZE | ||
} | ||
}) | ||
.extend({ | ||
top: BORDER_SIZE, | ||
right: BORDER_SIZE, | ||
bottom: BORDER_SIZE, | ||
left: BORDER_SIZE, | ||
background: options.border | ||
}) | ||
.png() | ||
.toFile(path.join(directory, options.filename)); | ||
} | ||
|
||
createImage({ | ||
border: statusColors.defaultBorderColor, | ||
background: statusColors.defaultBackgroundColor, | ||
filename: `square-fill-${HousingStatus.NEVER_CONTACTED}.png` | ||
}); | ||
|
||
async.forEachOf( | ||
statusColors.borderColors, | ||
async ([status, borderColor], index) => { | ||
const [, backgroundColor] = statusColors.backgroundColors[index as number]; | ||
return createImage({ | ||
border: borderColor, | ||
background: backgroundColor, | ||
filename: `square-fill-${status}.png` | ||
}); | ||
} | ||
); |
Oops, something went wrong.