Skip to content

Improve HOC map design#30451

Merged
bethanyaconnor merged 5 commits into
stagingfrom
improve-hoc-map
Sep 5, 2019
Merged

Improve HOC map design#30451
bethanyaconnor merged 5 commits into
stagingfrom
improve-hoc-map

Conversation

@bethanyaconnor

@bethanyaconnor bethanyaconnor commented Aug 26, 2019

Copy link
Copy Markdown
Contributor

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.

Screenshot 2019-09-04 at 3 23 23 PM

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:

  1. Because we're going to start using custom icons, we'd need to import a style anyway (easiest way to expose these custom icons)
  2. We don't need to wait for a deploy for style changes
  3. It allows us to download an image of the map to be served statically during hour of code

Downsides to this change:

  1. The legend is still defined using HTML/CSS and therefore will be impossible to keep in sync if we change color schemes.
  2. Anyone with access to the style can change the look of the map in production without review.

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.

@codecov-io

codecov-io commented Aug 28, 2019

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (staging@b3bd9a3). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             staging   #30451   +/-   ##
==========================================
  Coverage           ?   72.07%           
==========================================
  Files              ?     1373           
  Lines              ?    84899           
  Branches           ?     3462           
==========================================
  Hits               ?    61191           
  Misses             ?    20461           
  Partials           ?     3247
Flag Coverage Δ
#integration 55.75% <ø> (?)
#storybook 56.56% <ø> (?)
#unit 58.04% <ø> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b3bd9a3...5c21932. Read the comment docs.


// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not quite sure what this comment means...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, sounds good.

// 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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth de-duping this with the similar logic just below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we hoist this magic number into a variable with an explanation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: stylePath

// copies of the point are visible, the popup appears
// over the point clicked on.
function getPopupCoordinates(clickLngLat, featureCoordinates) {
var normalizedCoordinates = featureCoordinates;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: 'let

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 + ')' : '');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: organizationName

@bethanyaconnor

Copy link
Copy Markdown
Contributor Author

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?

@breville

breville commented Sep 4, 2019

Copy link
Copy Markdown
Member

It sounds like taking the screenshot manually is the least burdensome approach.

@bethanyaconnor bethanyaconnor changed the title Change the HOC map to use a Mapbox hosted style instead of a JS defined one Improve HOC map design Sep 4, 2019
@bethanyaconnor

Copy link
Copy Markdown
Contributor Author

Sounds good! I've updated the description and title to reflect what this PR now does.

@bethanyaconnor bethanyaconnor merged commit 6b60942 into staging Sep 5, 2019
@bethanyaconnor bethanyaconnor deleted the improve-hoc-map branch September 5, 2019 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants