Repository navigation
Mapbox/React wrapper - #87
Conversation
# Conflicts: # src/actions/Actions.ts # src/map/Mapbox.ts
# Conflicts: # src/App.tsx # src/map/Map.tsx # src/map/Mapbox.ts
# Conflicts: # src/App.tsx # src/api/Api.ts # src/stores/QueryStore.ts
# Conflicts: # src/App.module.css # src/App.tsx # src/custom.d.ts # src/map/Map.tsx # src/map/Mapbox.ts
# Conflicts: # src/App.tsx # src/actions/Actions.ts # src/index.tsx # src/map/Mapbox.ts
I like this very much. The white bars were terrible. |
|
This is nice 👍 |
|
So, I changed the Dispatch stuff and moved everything into the Viewport store. I also noticed that there is no easing on zoom. Do we need to specify an easing function? The examples on the mapbox component page seem to have a smooth animation when I zoom by mouse wheel. |
|
Unit testing? At least of the store? |
Yes, see the end of this comment #87 (comment) and the todo in the |
Thanks for this. To me it seems a bit strange that the ViewportStore knows about all the routesuccess, pathdetail etc. actions. Changing the viewport rather seems like a basic feature of the map that is used by different more specific features (like routes and path details). So I would have expected the dependency the other way around: The route store (same with path detail) is a client of the viewport store. For example when we add more features that modify the viewport I would rather add more client code that uses the viewport store than modify the viewport store's reduce function every time. |
That's an intersting question. I've thought of a store as something which holds and manages a portion of the app's state. The store reacts to Actions happening in the app and updates its state accordingly. So, when we want the viewport to be different after a certain event occured, the ViewportStore should take care of it. Also, every action is dispatched to every store anyway, so that every store knows about every action already.
I think the set of actions our app has should represent the events that happen in our app. Introducing actions like the SetViewportFromBbox action don't actually represent an event of the app but a desired change to the state caused by something else ( a successfull routing request for example) |
|
Ok, I understand there is a difference between 'reacting to a state change' and sending an event like
No, I don't think so. Every action is passed to every store yes, but the code of the different stores is not coupled to all actions and the stores do not contain any code related to actions they do not handle explicitly. We can add/remove actions without changing all the stores. But now we cannot remove the path detail stuff (for example not needed for isochrone) without adjusting the (IMO unrelated) viewport changing code. |
I added a test in my last commit. It is actually quite nice that we can test the viewport transitions on this level now. |
| module.exports = { | ||
| preset: 'ts-jest', | ||
| testEnvironment: 'node', | ||
| testEnvironment: 'jsdom', |
There was a problem hiding this comment.
Is this ok? I needed this for the viewportstore test as it uses window.matchMedia.
There was a problem hiding this comment.
I have no preference here. I think I just put in, what the "getting-started-with-jest" tutorial says.
There was a problem hiding this comment.
I reverted. jsdom sounds more correct but who knows and as long as it works with the current value no need to change
| // ... select path details | ||
| state = store.reduce(state, new PathDetailsRangeSelected([10.46, 50.88, 10.47, 50.9])) | ||
| expect(state.longitude).toBeCloseTo(10.46, 2) | ||
| expect(state.latitude).toBeCloseTo(50.89, 2) | ||
| expect(state.zoom).toBeCloseTo(13.7, 1) |
There was a problem hiding this comment.
I really like we can do this now.
There was a problem hiding this comment.
Yes, this looks very nice.
| Object.defineProperty(window, 'matchMedia', { | ||
| writable: true, | ||
| value: jest.fn().mockImplementation(query => ({ |
There was a problem hiding this comment.
I needed this because viewport store uses window.matchMedia.
| // have this right here for now. Not sure if this needs to be abstracted somewhere else | ||
| const mediaQuery = window.matchMedia('(max-width: 640px)') |
There was a problem hiding this comment.
This makes testing the store a bit complicated, see my other comments. Can we just inject this into the constructor? And is it the same as isSmallScreen in App.tsx? Here we use 640px and in App.tsx we have something similar with 44rem.
There was a problem hiding this comment.
Yes, it would be better to have this media query at 44rem as well. And yes, it is supposed to be the same as isSmallScreen.
I guess you could even inject something like isSmallScreen: () => boolean and pass new ViewportStore(() => window.matchMedia(...)) in index.tsx. Then in the test you could supply your own predicate.
There was a problem hiding this comment.
I did this. The only thing is that we have this media query twice now. One time in index.tsx where we use window.matchMedia and one time in App.tsx where we use the useMediaQuery hook. We cannot use the hook in index.tsx because it would be outside of any react component and I thought there is probably a reason you use the useMediaQuery hook in App.tsx
There was a problem hiding this comment.
Yes, the hook is used, so that the layout changes when the window is resized.
There are several other places in css where this media query is used as well. I think as long as we only have one breakpoint we may be fine.
| ? { | ||
| top: 250, | ||
| bottom: 150, | ||
| top: 200, | ||
| bottom: 32, | ||
| right: 16, | ||
| left: 16, | ||
| } | ||
| : { | ||
| top: 100, | ||
| bottom: 100, | ||
| bottom: 300, | ||
| right: 100, | ||
| left: 500, | ||
| } |
There was a problem hiding this comment.
Nice! This fixed the problem that sometimes the markers were hidden by the path detail diagram, see #53
|
This seems to solve several issue like @easbar said also the issue where the elevation widget hides the routes 👍 There is a minor problem with the path details widget (not too important :) ) but it is hard to describe. Sometimes the elevation/pathdetails data does not show up when the mouse goes over the area (try hovering left and right). There seem to be areas that just do not work. Hm ... the path detail widget with current mapbox seems to have this problem too but only for small areas of the widget. |
Yes, even though this was unrelated to the wrapper: #87 (comment) |
|
I just played chaos monkey a bit more and now an error occurred when using the same coordinates (like #36). But now an error happens like "e is undefined". To avoid this in the future would we already need something like playwright or cypress or is this possible in a unit test? |
|
This error occurs because we do this on the server-side: so when the points are identical the bbox field is missing and we do not handle this yet. Things like this can be tested without UI/browser tests. |
|
Should we change this on the server-side? It seems a bit ugly that the bbox is missing in this case. Why not just return [lat, lon, lat, lon] in case we request a route from (lat, lon) to (lat, lon)? |
|
I wasn't able to find the reason but will change this on the server side as this made problems before. The oldest location seems to be here. |
) Co-authored-by: Janekdererste <[email protected]> Co-authored-by: Peter <[email protected]>
I was curious and tried Uber's Mapbox/React wrapper: https://visgl.github.io/react-map-gl/
This is just experimental and not meant to be merged in the current state. This branch is also based on top of #77 and #75, but that should not be so important. I just did not want to do the migration without the fix in #77 and before the path detail code was moved out of the map component in #75.The philosophy of the wrapper is interesting: https://visgl.github.io/react-map-gl/docs#design-philosophy
The wrapper is meant to address the problem that Mapbox is stateful and therefore does not integrate so well with React. We already faced some of the related issues like switching the background layer without re-creating the Map component or changing the bounding box in #72 etc. So I was hoping using this wrapper the viewport updates and the style switching feels more natural.
The migration actually went relatively smooth and I did not run into bigger issues yet. The state handling definitely feels better to me and it seems like less workarounds are required.
Other advantages could be that according to the documentation the wrapper works with mapbox-gl 1&2 and maplibre as well (I only tried mapbox-gl 1 so far) (#81) and it will be easier to move the different map layers out of the central map component (#78), just like I already moved out the viewport state handling. Another advantage could be easier integration with deck.gl (but I am just speculating and not sure if we even need this). Anyway, so far I do not see many reasons not to use the wrapper. At least we should keep this in mind and maybe comeback here when we see more issues related to the Mapbox state management for example.
I will update this branch when #75 and #77 are finished so it will be easier to track the changes. Otherwise, there are the following todos on this branch to make it equal to master/#75/#77, currently (feel free to edit this in case you notice something):
use actual marker symbols for query points and the path detail hovering. this should not be a real problem, but I just could not find any default marker svgs to use. For the path detail marker we might need to adjust the code because I could not find a way how to use the HTML node we get from heightgraph currently as marker.improve look of the point markers and the path detail marker. so far I use a rather ugly point marker and just open a popup for the path detail marker. -> postponed to Numbered markers #106Map.tsxdoes not have to deal with all the different things? I think so and did this in Move layers to separate files #108On the other hand this branch already fixes #82 (and maybe #80 as well) and it also implements the missing 'center map' context menu entry.
Btw there is also another such wrapper here: https://github.com/urbica/react-map-gl