diff --git a/frontend/src/components/ColorMapLegend.tsx b/frontend/src/components/ColorMapLegend.tsx index af97691..8430be8 100644 --- a/frontend/src/components/ColorMapLegend.tsx +++ b/frontend/src/components/ColorMapLegend.tsx @@ -4,12 +4,13 @@ type ColorMap = [number, string][] import styles from './ColorMapLegend.module.less' -export default function ColorMapLegend({map}: {map: ColorMap}) { +export default function ColorMapLegend({map, twoTicks = false}: {map: ColorMap, twoTicks?: boolean}) { const min = map[0][0] const max = map[map.length - 1][0] const normalizeValue = (v) => (v - min) / (max - min) const gradientId = useMemo(() => `gradient${Math.floor(Math.random() * 1000000)}`, []); const gradientUrl = `url(#${gradientId})`; + const tickValues = twoTicks ? [map[0], map[map.length-1]] : map return (
@@ -23,7 +24,7 @@ export default function ColorMapLegend({map}: {map: ColorMap}) { - {map.map(([value]) => ( + {tickValues.map(([value]) => ( {value.toFixed(2)} diff --git a/frontend/src/mapstyles/index.js b/frontend/src/mapstyles/index.js index 6af0631..e16c1ca 100644 --- a/frontend/src/mapstyles/index.js +++ b/frontend/src/mapstyles/index.js @@ -22,6 +22,10 @@ function rgbArrayToColor(arr) { return ['rgb', ...arr.map((v) => Math.round(v * 255))] } +function rgbArrayToHtml(arr) { + return "#" + arr.map((v) => Math.round(v * 255).toString(16)).map(v => (v.length == 1 ? '0' : '') + v).join('') +} + export function colormapToScale(colormap, value, min, max) { return [ 'interpolate-hcl', @@ -32,6 +36,7 @@ export function colormapToScale(colormap, value, min, max) { } export const viridis = simplifyColormap(viridisBase.map(rgbArrayToColor), 20) +export const viridisSimpleHtml = simplifyColormap(viridisBase.map(rgbArrayToHtml), 10) export const grayscale = ['#FFFFFF', '#000000'] export const reds = [ 'rgba( 255, 0, 0, 0)', diff --git a/frontend/src/pages/MapPage/LayerSidebar.tsx b/frontend/src/pages/MapPage/LayerSidebar.tsx index 4f4626a..cc0b781 100644 --- a/frontend/src/pages/MapPage/LayerSidebar.tsx +++ b/frontend/src/pages/MapPage/LayerSidebar.tsx @@ -8,7 +8,7 @@ import { setMapConfigFlag as setMapConfigFlagAction, initialState as defaultMapConfig, } from 'reducers/mapConfig' -import {colorByDistance, colorByCount, reds} from 'mapstyles' +import {colorByDistance, colorByCount, viridisSimpleHtml} from 'mapstyles' import {ColorMapLegend} from 'components' const BASEMAP_STYLE_OPTIONS = [ @@ -93,7 +93,7 @@ function LayerSidebar({ /> - + ) : ( diff --git a/frontend/src/pages/MapPage/index.tsx b/frontend/src/pages/MapPage/index.tsx index 8ca454c..9d30847 100644 --- a/frontend/src/pages/MapPage/index.tsx +++ b/frontend/src/pages/MapPage/index.tsx @@ -44,7 +44,8 @@ const getRoadsLayer = (colorAttribute, maxCount) => produce(untaggedRoadsLayer, (draft) => { draft.id = 'obs_roads_normal' if (colorAttribute.endsWith('_count')) { - delete draft.filter + // delete draft.filter + draft.filter = ['to-boolean', ['get', colorAttribute]] } else { draft.filter = draft.filter[1] // remove '!' } @@ -52,7 +53,7 @@ const getRoadsLayer = (colorAttribute, maxCount) => draft.paint['line-color'] = colorAttribute.startsWith('distance_') ? colorByDistance(colorAttribute) : colorAttribute.endsWith('_count') - ? colorByCount(colorAttribute, maxCount, reds) + ? colorByCount(colorAttribute, maxCount) : '#DDD' draft.paint['line-opacity'][3] = 12 draft.paint['line-opacity'][5] = 13