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

feat: interactive map #24

Merged
merged 35 commits into from
Oct 5, 2023
Merged

feat: interactive map #24

merged 35 commits into from
Oct 5, 2023

Conversation

mortennordseth
Copy link
Contributor

@mortennordseth mortennordseth commented Oct 2, 2023

This PR should include the necessary functionality to have an interactive map that can be integrated on the departures page.

TODO

  • Use GeocoderFeature type
  • Add map buttons
  • Mobile view
  • Integrate with departures page (nearest-stop-places)
  • Handle screen reader for map
  • Fix map layer warnings or suppress them (Should be fixed in MapBox studio)
  • Tests
Screenshots image image image image image image

Solves https://github.com/AtB-AS/kundevendt/issues/9147

@mortennordseth
Copy link
Contributor Author

I'm marking this as ready for review now. There is still some work to be done regarding screen readers and refactoring of CSS class names etc, but I think it would be good if you could take a look at the overall structure

@mortennordseth mortennordseth marked this pull request as ready for review October 3, 2023 10:52
@mortennordseth mortennordseth requested review from adriansberg and mikaelbr and removed request for adriansberg October 3, 2023 10:52
@adriansberg
Copy link
Contributor

2023-10-03 at 14 41 53

The map needs to be position relative to the screen and not the container it looks like. When I clicked to show the map it appears at the top of the screen.

src/utils/colors.ts Outdated Show resolved Hide resolved
@mortennordseth
Copy link
Contributor Author

The map needs to be position relative to the screen and not the container it looks like. When I clicked to show the map it appears at the top of the screen.

When fixing the interactive problem I also changed the position to fixed which solves this, @adriansberg 👍

@adriansberg
Copy link
Contributor

The icon seems to be uncentered
image
image

src/components/map/map.tsx Outdated Show resolved Hide resolved
src/components/map/map.tsx Outdated Show resolved Hide resolved
src/components/map/map.tsx Outdated Show resolved Hide resolved
Comment on lines 19 to 25
type Marker = HTMLElement &
React.DetailedReactHTMLElement<
{
className: string;
},
HTMLElement
>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. Why is this so advanced? Could it be as simple as JSX.IntrinsicElements['span']?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant to ask about this, but forgot. The constructor for the mapboxgl Marker expects an element of type HTMLElement and I'll get a ts error using JSX.IntrinsicElements['span'] as there are a lot more properties to that type 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this even works? 😅 I have a hard time seeing how this would render properly. CreateElement here returns an JSON structure which react in turns renders as DOM operations at some point. But passing this to setMarker API of mapbox has no idea what to do with that JSON structure. Also the Icon path looks to be wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are absolutely correct, this isn't working 🤦‍♂️ I'll fix it asap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've solved this using React createRoot. I also added a new component, PinSvg, so that I can use the CSS fill property to set the correct color on the SVG.

Copy link
Collaborator

@mikaelbr mikaelbr Oct 4, 2023

Choose a reason for hiding this comment

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

You could also do this the old fashioned way (which is actually not old, but new fashion also, but maybe an API many people don't use directly):

const pin: HTMLElement = document.createElement('img');
pin.src = '/assets/map/Pin.svg';
setMarker(pin);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's neat! The design says that we should use the interactive_0 color for the pin and that's not straightforward to use when using an <img /> though, is it? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm.. No, but I think maybe the color of the pin isn't as important and might not be a hard require. Often in these cases I'd verify and think it over with the designer. Because it's not really interacteble and interactive_0 implies primary function. Also black is more contrast then blue interactive on some blue water for instance. So I think using map/Pin.svg is a better choice here, but like I said, I think verifying/discussing this is a good way to go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. Good point. I'll have a chat with the designer 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've talked with the designer and we'll go for the black SVG. Updated the code to use document.createElement 👍

@mikaelbr
Copy link
Collaborator

mikaelbr commented Oct 3, 2023

This happens as image inside button isn't display: block

Screenshot 2023-10-03 at 21 29 13

@mikaelbr
Copy link
Collaborator

mikaelbr commented Oct 3, 2023

Feeling like the zoom level should be closer?

@mortennordseth
Copy link
Contributor Author

I've looked into and resolved the comments you've made. What's not done now is creating tests for the actual map and handle the Mapbox errors. The tests in not so straightforward and I'll create an issue so that can be handled in another PR. The Mapbox errors should be fixed in Mapbox Studio and since these errors already exists on the main branch I don't think that should block this from being merged.

Copy link
Contributor

@adriansberg adriansberg left a comment

Choose a reason for hiding this comment

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

Great work, @mortennordseth! 👏🚀🗺️

Copy link
Collaborator

@mikaelbr mikaelbr left a comment

Choose a reason for hiding this comment

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

Good stuff 🥳

@mortennordseth mortennordseth merged commit 6dba636 into main Oct 5, 2023
2 checks passed
@mortennordseth mortennordseth deleted the morten/map branch October 5, 2023 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants