-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keep old behaviour in RoutePath when we just have coordinates (and no… #1250
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02a7e05
keep old behaviour in RoutePath when we just have coordinates (and no…
jcardus 870ef74
split MapRoutePath
jcardus 28d8a5b
simplify
jcardus 27f6cc5
add colors.js
jcardus 244028c
missing reportColor
jcardus abe03b6
missing reportColor
jcardus 1c779e8
don't override reportColor
jcardus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { decomposeColor } from '@mui/material'; | ||
|
||
export const interpolateColor = (color1, color2, factor) => { | ||
if (factor > 1) factor = 1; | ||
if (factor < 0) factor = 0; | ||
|
||
const c1 = decomposeColor(color1).values; | ||
const c2 = decomposeColor(color2).values; | ||
|
||
const r = Math.round(c1[0] + factor * (c2[0] - c1[0])); | ||
const g = Math.round(c1[1] + factor * (c2[1] - c1[1])); | ||
const b = Math.round(c1[2] + factor * (c2[2] - c1[2])); | ||
|
||
return `rgb(${r}, ${g}, ${b})`; | ||
}; | ||
|
||
export const getSpeedColor = (color1, color2, color3, speed, max) => { | ||
const factor = speed / max; | ||
if (factor <= 0.5) { | ||
return interpolateColor(color1, color2, factor * 2); | ||
} | ||
return interpolateColor(color2, color3, (factor - 0.5) * 2); | ||
}; |
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,90 @@ | ||
import { useTheme } from '@mui/styles'; | ||
import { useId, useEffect } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { map } from './core/MapView'; | ||
|
||
const MapRouteCoordinates = ({ name, coordinates, deviceId }) => { | ||
const id = useId(); | ||
|
||
const theme = useTheme(); | ||
|
||
const reportColor = useSelector((state) => { | ||
const attributes = state.devices.items[deviceId]?.attributes; | ||
if (attributes) { | ||
const color = attributes['web.reportColor']; | ||
if (color) { | ||
return color; | ||
} | ||
} | ||
return theme.palette.geometry.main; | ||
}); | ||
|
||
useEffect(() => { | ||
map.addSource(id, { | ||
type: 'geojson', | ||
data: { | ||
type: 'Feature', | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: [], | ||
}, | ||
}, | ||
}); | ||
map.addLayer({ | ||
source: id, | ||
id: `${id}-line`, | ||
type: 'line', | ||
layout: { | ||
'line-join': 'round', | ||
'line-cap': 'round', | ||
}, | ||
paint: { | ||
'line-color': ['get', 'color'], | ||
'line-width': 2, | ||
}, | ||
}); | ||
map.addLayer({ | ||
source: id, | ||
id: `${id}-title`, | ||
type: 'symbol', | ||
layout: { | ||
'text-field': '{name}', | ||
'text-size': 12, | ||
}, | ||
paint: { | ||
'text-halo-color': 'white', | ||
'text-halo-width': 1, | ||
}, | ||
}); | ||
|
||
return () => { | ||
if (map.getLayer(`${id}-title`)) { | ||
map.removeLayer(`${id}-title`); | ||
} | ||
if (map.getLayer(`${id}-line`)) { | ||
map.removeLayer(`${id}-line`); | ||
} | ||
if (map.getSource(id)) { | ||
map.removeSource(id); | ||
} | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
map.getSource(id)?.setData({ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'LineString', | ||
coordinates, | ||
}, | ||
properties: { | ||
name, | ||
color: reportColor, | ||
}, | ||
}); | ||
}, [theme, coordinates, reportColor]); | ||
|
||
return null; | ||
}; | ||
|
||
export default MapRouteCoordinates; |
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 was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check the warnings and errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any warnings