Anna Duan - Philadelphia ethnic food clusters#19
Anna Duan - Philadelphia ethnic food clusters#19annaduan09 wants to merge 13 commits intoWeitzman-MUSA-JavaScript:mainfrom
Conversation
I did this by pressing enter
|
|
||
| <article class="slide" id="european"> | ||
| <h2>European</h2> | ||
| <p>The main European cuisines are British and Irish. Most of these restaurants cluster in Center City.</p> |
There was a problem hiding this comment.
I was surprised that British and Irish dominate the European category, but I guess it's because there are so many pubs, and in my head I lump them into the category of "bar" as distinct from "restaurant". 🤷
There was a problem hiding this comment.
I found the timing of map data transitions to be a little disconnected from the slide positions, but when I changed this line in the calcCurrentSlideIndex function from:
const scrollPos = window.scrollY;to:
const scrollPos = window.scrollY - this.container.offsetTop;It was a little better. The latter line takes the top position of the slide container element into account. I added that into the template, but it may have been after you forked the code.
| const Mapboxstyle = 'mapbox/light-v11'; | ||
|
|
||
| const baseTileLayer = L.tileLayer(`https://api.mapbox.com/styles/v1/${Mapboxstyle}/tiles/512/{z}/{x}/{y}{r}?access_token=${Mapboxkey}`, { | ||
| maxZoom: 16, |
There was a problem hiding this comment.
suggestion: When using Mapbox's 512px tiles, you should usually set up your tile layer like this. This will reduce the number of tile requests your map has to make to Mapbox, and will prevent your map labels from showing up super tiny.
| maxZoom: 16, | |
| maxZoom: 16, | |
| tileSize: 512, | |
| zoomOffset: -1, |
What's happening right now on your map is Mapbox's 512 pixel tiles are being squeezed into Leaflet's default 256x256 pixel tile size, so each tile is getting scaled down to half it's size in each direction. This code is telling leaflet to use 512 pixel tiles instead, but use the tiles from one zoom level offset from what leaflet might expect (i.e. request the zoom level 7 tiles from Mapbox when you're at zoom level 8 on the map).
| const restaurant = layer.feature.properties.name; | ||
| const cuisine = layer.feature.properties.cuisine; | ||
| const cuisine_group = data.name; | ||
| return `${restaurant} - ${cuisine} - ${cuisine_group}` |
There was a problem hiding this comment.
suggestion: Since you're using the same bindTooltip function for each layer (which is fine) you can do something like this to show different messages for each:
| return `${restaurant} - ${cuisine} - ${cuisine_group}` | |
| const percent = layer.feature.properties.pct; | |
| const count = layer.feature.properties.count; | |
| return ( | |
| // If it's an individual restaurant... | |
| restaurant ? `${restaurant} - ${cuisine} - ${cuisine_group}` : | |
| // If it has a percentage... | |
| percent ? `${cuisine} - ${percent.toFixed(1)}% of ${count} restaurants` : | |
| // Anything else... | |
| cuisine | |
| ); |
That way you won't get undefined showing up in your tooltips.
| min-width: 0; | ||
| } | ||
|
|
||
| .legend { |
There was a problem hiding this comment.
suggestion: I might recommend some background on your legend to make the text a little more readable on top of the map tiles.
| .legend { | |
| .legend { | |
| padding: 0.5rem; | |
| border: 1px solid #ccc; | |
| border-radius: 0.5rem; | |
| background-color: rgba(255 255 255 / 50%); |
| // Initialize the legend content | ||
| this.legend.div.innerHTML = ""; | ||
|
|
||
| // Iterate over each unique cuisine to add to the legend |
There was a problem hiding this comment.
suggestion: If you always wanted the colors in the same order (i.e. highest to lowest rank) you could use something like this:
| // Iterate over each unique cuisine to add to the legend | |
| // Iterate over each unique cuisine to add to the legend | |
| uniqueCuisines.sort((a, b) => cuisineToRank[a] - cuisineToRank[b]); |
| @@ -0,0 +1,38 @@ | |||
| import { SlideDeck } from './slidedeck.js'; | |||
| import L from 'leaflet'; | |||
There was a problem hiding this comment.
suggestion: In order to use Leaflet from an import like this, you have to be using a development server that knows how to deal with it, and you have to build your project to run on any server. This is similar to the vite tool that I showed in class on Wednesday. I'll be re-recording the second half of that class to show how to build a project that uses these imports to deploy to the web, but as long as you include your <script tag in the HTML (i.e., as you do here) then you don't need this import.
| import L from 'leaflet'; |
Storymap project submission