-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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 |
When fixing the interactive problem I also changed the position to |
src/components/map/map.tsx
Outdated
type Marker = HTMLElement & | ||
React.DetailedReactHTMLElement< | ||
{ | ||
className: string; | ||
}, | ||
HTMLElement | ||
>; |
There was a problem hiding this comment.
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']
?
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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
👍
Feeling like the zoom level should be closer? |
6c8f651
to
6b9484c
Compare
Co-authored-by: Mikael Brevik <mikaelbre@gmail.com>
Co-authored-by: Mikael Brevik <mikaelbre@gmail.com>
Co-authored-by: Mikael Brevik <mikaelbre@gmail.com>
e58b381
to
239182c
Compare
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, @mortennordseth! 👏🚀🗺️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff 🥳
This PR should include the necessary functionality to have an interactive map that can be integrated on the departures page.
TODO
Fix map layer warnings or suppress them(Should be fixed in MapBox studio)Screenshots
Solves https://github.com/AtB-AS/kundevendt/issues/9147