derive logic for "include roads without data" from selected attribute
This commit is contained in:
parent
1ad5fe562e
commit
76b1b41b4b
|
@ -44,12 +44,19 @@ export const reds = [
|
|||
]
|
||||
|
||||
export function colorByCount(attribute = 'event_count', maxCount, colormap = viridis) {
|
||||
return colormapToScale(colormap, ['case', ['to-boolean', ['get', attribute]], ['get', attribute], 0], 0, maxCount)
|
||||
return colormapToScale(colormap, ['case', isValidAttribute(attribute), ['get', attribute], 0], 0, maxCount)
|
||||
}
|
||||
|
||||
var steps = {'rural': [1.6,1.8,2.0,2.2],
|
||||
'urban': [1.1,1.3,1.5,1.7]}
|
||||
|
||||
export function isValidAttribute(attribute) {
|
||||
if (attribute.endsWith('zone')) {
|
||||
return ['in', ['get', attribute], ['literal', ['rural', 'urban']]]
|
||||
}
|
||||
return ['to-boolean', ['get', attribute]]
|
||||
}
|
||||
|
||||
export function borderByZone() {
|
||||
return ["match", ['get', 'zone'],
|
||||
"rural", "cyan",
|
||||
|
@ -62,7 +69,7 @@ export function colorByDistance(attribute = 'distance_overtaker_mean', fallback
|
|||
|
||||
return [
|
||||
'case',
|
||||
['!', ['to-boolean', ['get', attribute]]],
|
||||
['!', isValidAttribute(attribute)],
|
||||
fallback,
|
||||
["match", ['get', 'zone'], "rural",
|
||||
[
|
||||
|
|
|
@ -6,7 +6,7 @@ import produce from 'immer'
|
|||
|
||||
import {Page, Map} from 'components'
|
||||
import {useConfig} from 'config'
|
||||
import {colorByDistance, colorByCount, borderByZone, reds} from 'mapstyles'
|
||||
import {colorByDistance, colorByCount, borderByZone, reds, isValidAttribute} from 'mapstyles'
|
||||
import {useMapConfig} from 'reducers/mapConfig'
|
||||
|
||||
import RoadInfo from './RoadInfo'
|
||||
|
@ -40,15 +40,16 @@ const untaggedRoadsLayer = {
|
|||
minzoom: 12,
|
||||
}
|
||||
|
||||
const getUntaggedRoadsLayer = (colorAttribute, maxCount) =>
|
||||
produce(untaggedRoadsLayer, (draft) => {
|
||||
draft.filter = ['!', isValidAttribute(colorAttribute)]
|
||||
})
|
||||
|
||||
|
||||
const getRoadsLayer = (colorAttribute, maxCount) =>
|
||||
produce(untaggedRoadsLayer, (draft) => {
|
||||
draft.id = 'obs_roads_normal'
|
||||
if (colorAttribute.endsWith('_count')) {
|
||||
// delete draft.filter
|
||||
draft.filter = ['to-boolean', ['get', colorAttribute]]
|
||||
} else {
|
||||
draft.filter = draft.filter[1] // remove '!'
|
||||
}
|
||||
draft.filter = isValidAttribute(colorAttribute)
|
||||
draft.paint['line-width'][6] = 6 // scale bigger on zoom
|
||||
draft.paint['line-color'] = colorAttribute.startsWith('distance_')
|
||||
? colorByDistance(colorAttribute)
|
||||
|
@ -130,8 +131,9 @@ export default function MapPage() {
|
|||
|
||||
const layers = []
|
||||
|
||||
const untaggedRoadsLayerCustom = useMemo(() => getUntaggedRoadsLayer(attribute), [attribute])
|
||||
if (mapConfig.obsRoads.show && mapConfig.obsRoads.showUntagged) {
|
||||
layers.push(untaggedRoadsLayer)
|
||||
layers.push(untaggedRoadsLayerCustom)
|
||||
}
|
||||
|
||||
const roadsLayer = useMemo(() => getRoadsLayer(attribute, maxCount), [attribute, maxCount])
|
||||
|
|
Loading…
Reference in a new issue