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

Add contextual layers for SIMD and population density. #141

Merged
merged 1 commit into from
Feb 14, 2025
Merged

Conversation

dabreegster
Copy link
Collaborator

#106
image
image

You'll need to grab https://assets.od2net.org/cnt_layers/population.pmtiles. I mistakenly uploaded an early draft of it during the first layers PR, but it's changed now.


let densityColorScale = simdColorScale.toReversed();
// Use the same (slightly rounded) buckets as https://www.ons.gov.uk/census/maps/choropleth/population/population-density/population-density/persons-per-square-kilometre. TODO Adapt for Scotland.
let densityLimits = [0, 4700, 13000, 33000, 94000, 1980000];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lifted these from England, but since Scotland has lower density, we could maybe adjust

@@ -65,6 +65,21 @@ function bus_routes {
tippecanoe tmp/bus_routes_v2.geojson -zg -l bus_routes -o $OUT/bus_routes.pmtiles
}

function population {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</HelpButton>
{/if}

<VectorTileSource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not novel to this PR, but I just realized I didn't have a good mental model for how our maplibre-svelte integration works.

The current component context for this is within the Control component defined in ContextualLayers.svelte, which is where the buttons and text like "Darker colours are denser" are rendered.

However, the layer declarations below are just "floating" here, and somehow communicate to the outer map component.

This is all fine and reasonable, I'm just restating my new understanding of how this works since I guess I hadn't paid enough attention before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes getting used to for sure.

<ContextualLayers />

Because ContextualLayers is a child component of the MapLibre component, it all works out. svelte-maplibe sets context (the Svelte scoped state that's available to children, no matter how deep, without prop drilling) that lets sources/layers find the MapLibre map object.

It is kind of weird to mix DOM nodes and maplibre drawing directives. It's a nice way to write the code, because you can have one component control both the map and panel/legend, without plumbing state back and forth or doing something intense with event handlers. In this case, it works out easily, because there's a svelte-maplibre Control component for the floating map panels with bits of regular DOM.

In other cases, to get one svelte component to do something both on the sidebar and map, we use the SplitComponent trick. I can describe how it works if the code isn't clear. This is maybe also called "remote DOM" in other frameworks.

Copy link
Contributor

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dabreegster dabreegster merged commit bb7a388 into main Feb 14, 2025
1 check passed
@dabreegster dabreegster deleted the lol_simd branch February 14, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants