Improve HOC map design#30451
Conversation
Codecov Report
@@ Coverage Diff @@
## staging #30451 +/- ##
==========================================
Coverage ? 72.07%
==========================================
Files ? 1373
Lines ? 84899
Branches ? 3462
==========================================
Hits ? 61191
Misses ? 20461
Partials ? 3247
Continue to review full report at Codecov.
|
|
|
||
| // Ensure that if the map is zoomed out such that multiple | ||
| // copies of the feature are visible, the popup appears | ||
| // over the copy being pointed to. |
There was a problem hiding this comment.
Not quite sure what this comment means...
There was a problem hiding this comment.
The logic is correcting for the potential of a feature/point being on the map twice (when it's zoomed out enough) and ensuring that the popup appears where the click happened. I took this logic from Mapbox.
It's very easy to simplify to make it just show the popup on the spot where the user clicked but I think it looks a bit nicer for the popup to be placed on the point itself.
| // Ensure that if the map is zoomed out such that multiple | ||
| // copies of the feature are visible, the popup appears | ||
| // over the copy being pointed to. | ||
| while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) { |
There was a problem hiding this comment.
Is it worth de-duping this with the similar logic just below?
There was a problem hiding this comment.
Deduplicated a bit of the logic. There are a couple of subtle differences between the two listeners but let me know if there's anything else you'd like to see pulled out!
| var map = new mapboxgl.Map({ | ||
| container: 'mapbox-map', | ||
| style: 'mapbox://styles/mapbox/streets-v11', | ||
| style: 'mapbox://styles/codeorg/cjz36duae88ds1cp7ll7smx6s', |
There was a problem hiding this comment.
Should we hoist this magic number into a variable with an explanation?
There was a problem hiding this comment.
I pulled this out and added a brief comment but not sure what else to say.
|
|
||
| $(document).ready(function() { | ||
| // We keep some style elements as a Mapbox style for simplicity. | ||
| const style_path = 'mapbox://styles/codeorg/cjz36duae88ds1cp7ll7smx6s'; |
| // copies of the point are visible, the popup appears | ||
| // over the point clicked on. | ||
| function getPopupCoordinates(clickLngLat, featureCoordinates) { | ||
| var normalizedCoordinates = featureCoordinates; |
There was a problem hiding this comment.
oh, are we not going through the preprocessor for this JS file? In that case, disregard.
| .setLngLat(coordinates) | ||
| .setText(organization_name) | ||
| const popupText = | ||
| organization_name + (city.length > 0 ? ' (' + city + ')' : ''); |
|
Loading the data in JS instead of as a Mapbox style is in 5c21932. In this case we would have to screenshot the map a few days before Hour of Code (which TIL is what we've generally done). Thoughts? |
|
It sounds like taking the screenshot manually is the least burdensome approach. |
|
Sounds good! I've updated the description and title to reflect what this PR now does. |
Update HOC map to use design Mark created. It will need to use a style created by us and hosted on Mapbox to have access to the background and icons.
This PR includes a couple of other small changes to get it ready for launch.
##OLD Description
Mapbox allows you to style a map, including the data, on their site and just use that "style". I've been using that feature to prototype designs and think we should use this in the HOC map in production (tbd on the census map).
Reasons for this change:
Downsides to this change:
The biggest driver for this change is reason number 3 for me. Notably, I don't know of any way of displaying a static image instead of the map during Hour of Code without this change, other than duplicating the JS defined style in a Mapbox style and using that.
This PR also contains a change to how popups are shown for special events to be more consistent with the current map. I can separate that out if that's problematic.