Justice40 EJScreen prototype application.
First, run the development server:
npm run dev
# or
yarn dev
Open http://localhost:3000 with your browser to see the result.
This is a Next.js website, so it's a layer on top of React. This writeup assume that you're familiar with React.
There are three components working here:
pages/index.tsx
: the page skeletoncomponents/map.tsx
: the mapcomponents/chart.tsx
: the chart, which reflects values on the map and can be used to filter the mapThe only vital part of the code other than that is lib/pmap.ts
, which has the logic for how the map
is set up and changed.
Here's how a few different things work:
For example, toggling between PM2.5 and Respiratory Hazard, right now.
This is done with React state in the pages/index.tsx component, here:
The chosen indicator is sent to the Map component here:
And the Map component receives those values and uses a useEffect
call to modify the displayed layer:
The data for that chart is called viewportData
. When the user moves the map, we wait until the map
has loaded all of the necessary data, then run countMapFeatures, which
uses Mapbox GL JS's queryRenderedFeatures
to find the features currently visible. These features are added together and then send back to
the pages/index.tsx
component with the setViewPortData
method in the Map component, and then sent down to the Chart component.
The chart uses d3 using the approach of using React to render the DOM, and d3 to do math. The slider on the chart is powered by react-aria.
When the slider moves, the Chart component calls setFilter, which then is applied to the Map in another useEffect call in the Map component.