Skip to content

Commit

Permalink
Style each moving platform with a different color
Browse files Browse the repository at this point in the history
  • Loading branch information
willemarcel committed Jun 17, 2024
1 parent 8230c5a commit 072bbd1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/timeline/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { mapLayerFilter } from "../../utils/filter-utils"
import { colors } from "../../theme"
import { replaceSlashes } from "../../utils/helpers"
import { usePlatformStatus } from "../../utils/use-platform-status"
import { getLineColors } from "../../utils/platform-colors"

export function DeploymentMap({
geojson,
Expand All @@ -35,6 +36,16 @@ export function DeploymentMap({
const platformsWithData = geojson.features.map(
f => f.properties.platform_name
)
let movingPlatforms = platforms
.filter(platform =>
["Jet", "Prop", "UAV", "Ships/Boats"].includes(platform.type)
)
.map(platform => platform.name)

const lineColorsPaint = getLineColors(
movingPlatforms.filter((i, index) => movingPlatforms.indexOf(i) === index)
)

const [selectedPlatforms, setSelectedPlatforms] = useState(
names
.filter((name, index) => names.indexOf(name) === index)
Expand All @@ -61,7 +72,7 @@ export function DeploymentMap({
type: "line",
source: "deployment",
paint: {
"line-color": "#1B9E77",
"line-color": lineColorsPaint,
"line-width": 2,
"line-opacity": 0.9,
},
Expand Down
17 changes: 17 additions & 0 deletions src/utils/__tests__/platform-colors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getLineColors } from "../platform-colors"

describe("getLineColor", () => {
it("returns correct match for DC-8 and ER-2", () => {
const platforms = ["DC-8", "ER-2"]
const result = [
"match",
["get", "platform_name"],
"DC-8",
"#F1EEF6",
"ER-2",
"#BDC9E1",
"#1a9b8c",
]
expect(getLineColors(platforms)).toEqual(result)
})
})
14 changes: 14 additions & 0 deletions src/utils/platform-colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const flightColors = platforms => {
const colors = ["#F1EEF6", "#BDC9E1", "#74A9CF", "#2B8CBE", "#045A8D"]
return platforms.map((i, index) => [i, colors[index]])
}

export const getLineColors = platforms => {
const colors = flightColors(platforms)
return [
"match",
["get", "platform_name"],
...colors.flatMap(i => i),
"#1a9b8c", // this is a fallback color
]
}

0 comments on commit 072bbd1

Please sign in to comment.