Skip to content
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

Hierarchies of boundaries #199

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const PoliticalChoropleths: React.FC<PoliticalChoroplethsProps> = ({
>({})

const [, setMapZoom] = useMapZoom()
const activeTileset = useActiveTileset(boundaryType)
const activeTileset = useActiveTileset(boundaryType, view)
const { data } = useDataByBoundary({
view,
tileset: activeTileset,
Expand Down Expand Up @@ -110,126 +110,135 @@ const PoliticalChoropleths: React.FC<PoliticalChoroplethsProps> = ({
}
}, [map.loaded, activeTileset, data, view.mapOptions])

const [zoom, _] = useMapZoom()

if (!map.loaded) return null
if (!tilesets) return null

return (
<>
{tilesets.map((tileset) => (
<Fragment key={tileset.mapboxSourceId}>
<Source
id={tileset.mapboxSourceId}
type="vector"
url={`mapbox://${tileset.mapboxSourceId}`}
promoteId={tileset.promoteId}
minzoom={tileset.minZoom}
maxzoom={tileset.maxZoom}
>
{/* Fill of the boundary */}
<Layer
beforeId="road-simple"
id={`${tileset.mapboxSourceId}-fill`}
source={tileset.mapboxSourceId}
source-layer={tileset.sourceLayerId}
type="fill"
paint={fillsByLayer[tileset.mapboxSourceId] || {}}
minzoom={tileset.minZoom}
maxzoom={tileset.maxZoom}
/>
{/* Border of the boundary */}
<Layer
beforeId={PLACEHOLDER_LAYER_ID_CHOROPLETH}
id={`${tileset.mapboxSourceId}-line`}
source={tileset.mapboxSourceId}
source-layer={tileset.sourceLayerId}
type="line"
paint={getChoroplethEdge(borderVisibility === 'visible')}
layout={{
'line-join': 'round',
'line-round-limit': 0.1,
}}
/>
{/* Border of the selected boundary */}
<Layer
beforeId={PLACEHOLDER_LAYER_ID_CHOROPLETH}
id={`${tileset.mapboxSourceId}-selected`}
source={tileset.mapboxSourceId}
source-layer={tileset.sourceLayerId}
type="line"
paint={getSelectedChoroplethEdge()}
filter={[
'==',
['get', tileset.promoteId],
explorer.state.entity === 'area'
? explorer.state.id
: 'sOmE iMpOsSiBle iD tHaT wIlL uPdAtE mApBoX',
]}
layout={{
visibility: areasVisible,
'line-join': 'round',
'line-round-limit': 0.1,
}}
/>
</Source>
<Source
id={`${tileset.mapboxSourceId}-area-count`}
type="geojson"
data={getAreaGeoJSON(dataByBoundary)}
minzoom={tileset.minZoom}
maxzoom={tileset.maxZoom}
>
<Layer
{tilesets.map((tileset) => {
const isActiveTileset =
activeTileset.analyticalAreaType === tileset.analyticalAreaType
return (
<Fragment key={tileset.mapboxSourceId}>
<Source
id={tileset.mapboxSourceId}
type="vector"
url={`mapbox://${tileset.mapboxSourceId}`}
promoteId={tileset.promoteId}
// minzoom={tileset.minZoom}
// maxzoom={tileset.maxZoom}
>
{/* Fill of the boundary */}
<Layer
beforeId="road-simple"
id={`${tileset.mapboxSourceId}-fill`}
source={tileset.mapboxSourceId}
source-layer={tileset.sourceLayerId}
type="fill"
paint={fillsByLayer[tileset.mapboxSourceId] || {}}
// minzoom={tileset.minZoom}
// maxzoom={tileset.maxZoom}
/>
{/* Border of the boundary */}
<Layer
beforeId={PLACEHOLDER_LAYER_ID_CHOROPLETH}
id={`${tileset.mapboxSourceId}-line`}
source={tileset.mapboxSourceId}
source-layer={tileset.sourceLayerId}
type="line"
paint={getChoroplethEdge(
borderVisibility === 'visible',
isActiveTileset
)}
layout={{
'line-join': 'round',
'line-round-limit': 0.1,
}}
/>
{/* Border of the selected boundary */}
<Layer
beforeId={PLACEHOLDER_LAYER_ID_CHOROPLETH}
id={`${tileset.mapboxSourceId}-selected`}
source={tileset.mapboxSourceId}
source-layer={tileset.sourceLayerId}
type="line"
paint={getSelectedChoroplethEdge()}
filter={[
'==',
['get', tileset.promoteId],
explorer.state.entity === 'area'
? explorer.state.id
: 'sOmE iMpOsSiBle iD tHaT wIlL uPdAtE mApBoX',
]}
layout={{
visibility: areasVisible,
'line-join': 'round',
'line-round-limit': 0.1,
}}
/>
</Source>
<Source
id={`${tileset.mapboxSourceId}-area-count`}
type="symbol"
layout={{
...getAreaCountLayout(dataByBoundary),
visibility: boundaryNameVisibility,
}}
paint={{
'text-opacity': [
'interpolate',
['exponential', 1],
['zoom'],
7.5,
0,
7.8,
1,
],
'text-color': 'white',
'text-halo-color': '#24262b',
'text-halo-width': 1.5,
}}
minzoom={tileset.minZoom}
maxzoom={tileset.maxZoom}
/>
type="geojson"
data={getAreaGeoJSON(dataByBoundary)}
// minzoom={tileset.minZoom}
// maxzoom={tileset.maxZoom}
>
<Layer
id={`${tileset.mapboxSourceId}-area-count`}
type="symbol"
layout={{
...getAreaCountLayout(dataByBoundary),
visibility: boundaryNameVisibility,
}}
paint={{
'text-opacity': [
'interpolate',
['exponential', 1],
['zoom'],
7.5,
0,
7.8,
1,
],
'text-color': 'white',
'text-halo-color': '#24262b',
'text-halo-width': 1.5,
}}
// minzoom={tileset.minZoom}
// maxzoom={tileset.maxZoom}
/>

<Layer
id={`${tileset.mapboxSourceId}-area-label`}
type="symbol"
layout={{
...getAreaLabelLayout(dataByBoundary),
visibility: boundaryNameVisibility,
}}
paint={{
'text-color': 'white',
'text-opacity': [
'interpolate',
['exponential', 1],
['zoom'],
7.5,
0,
7.8,
1,
],
'text-halo-color': '#24262b',
'text-halo-width': 1.5,
}}
minzoom={tileset.minZoom}
maxzoom={tileset.maxZoom}
/>
</Source>
</Fragment>
))}
<Layer
id={`${tileset.mapboxSourceId}-area-label`}
type="symbol"
layout={{
...getAreaLabelLayout(dataByBoundary),
visibility: boundaryNameVisibility,
}}
paint={{
'text-color': 'white',
'text-opacity': [
'interpolate',
['exponential', 1],
['zoom'],
7.5,
0,
7.8,
1,
],
'text-halo-color': '#24262b',
'text-halo-width': 1.5,
}}
// minzoom={tileset.minZoom}
// maxzoom={tileset.maxZoom}
/>
</Source>
</Fragment>
)
})}
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default function ReportMapChoroplethLegend() {
)

const activeTileset = useActiveTileset(
viewManager.currentViewOfType?.mapOptions.choropleth.boundaryType
viewManager.currentViewOfType?.mapOptions.choropleth.boundaryType,
viewManager.currentViewOfType
)

const { loading, data } = useDataByBoundary({
Expand Down Expand Up @@ -316,6 +317,8 @@ export default function ReportMapChoroplethLegend() {
onChange={(d) => {
viewManager.updateView((draft) => {
draft.mapOptions.choropleth.boundaryType = d as BoundaryType
// unset the analytical area type
// delete draft.mapOptions.choropleth.lockedOnAnalyticalAreaType
})
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion nextjs/src/app/reports/[id]/(components)/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function MapView({
(boundary) => boundary.boundaryType === boundaryType
)?.tilesets

const activeTileset = useActiveTileset(boundaryType)
const activeTileset = useActiveTileset(boundaryType, mapView)

const { loading, fetchMore } = useDataByBoundary({
view: mapView,
Expand Down
11 changes: 6 additions & 5 deletions nextjs/src/app/reports/[id]/mapboxStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export function getChoroplethFill(
}

export function getChoroplethEdge(
visible?: boolean
visible?: boolean,
isFocused?: boolean
): LineLayerSpecification['paint'] {
return {
'line-color': 'white',
Expand All @@ -76,10 +77,10 @@ export function getChoroplethEdge(
['zoom'],
//
8,
0.3,
isFocused ? 0.3 : 0.1,
//
12,
1,
isFocused ? 1 : 0.5,
]
: 0,
'line-width': [
Expand All @@ -88,10 +89,10 @@ export function getChoroplethEdge(
['zoom'],
//
8,
0.3,
isFocused ? 0.5 : 0.1,
//
12,
2,
isFocused ? 2.5 : 1,
],
}
}
Expand Down
Loading
Loading