-
Notifications
You must be signed in to change notification settings - Fork 1
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: add support for custom offline maps #318
Conversation
Some initial ideas for debugging (you may have already tried): turn on logging for fastify so you can see what requests are being handled, so you can trace back what is happening up to the crash. |
2546868
to
d17e176
Compare
For reasons unknown, I'm no longer getting the crash. Didn't do anything special... |
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.
The use of useMapStyle() feels unnecessary with the tanstack query.
I think it would be better to use a suspense query (The map is the main feature, so i think it makes sense to block the entire app while it is loading)
And then we could create a custom hook for invalidating the query when the user goes offline/online
// custom hook
function useInvalidateMapUrlQuery(){
const {isInternetReachable} = useNetInfo();
const queryClient = useQueryClient()
useEffect(()=>{
queryClient.invalidateQuery({queryKey:[MAP_STYLE_URL_KEY]})
},[queryClient, isInternetReachable])
}
// inside map screen:
const MapScreen = () => {
const {data:mapStyleUrl} = useMapStyleUrl() //this is a suspense query, so no loading needs to be taken into account
useInvalidateMapUrlQuery()
// rest of component
}
The code feels a little cleaner if we are just utilizing tanstack query.
The other thing that we should maybe do is only change to the offline map if there isnt an online map already loaded. Aka, if the user is online and has a map loaded and then goes offline, don't reload the map with offline one, just keep the online one (even though we wont have any zoom) The online map at the farthest zoom feels better than using an offline map.
Basically the only time we should serve an offline map is when they open the app initally without any access to the internet.
// Register maps plugins | ||
fastify.register(MapeoStaticMapsFastifyPlugin, { | ||
prefix: 'static', | ||
staticRootDir: staticStylesDir, | ||
}) | ||
fastify.register(MapeoOfflineFallbackMapFastifyPlugin, { | ||
prefix: 'fallback', | ||
styleJsonPath: join(fallbackMapPath, 'style.json'), | ||
sourcesDir: join(fallbackMapPath, 'dist'), | ||
}) | ||
fastify.register(MapeoMapsFastifyPlugin, { | ||
prefix: 'maps', | ||
defaultOnlineStyleUrl: DEFAULT_ONLINE_MAP_STYLE_URL, | ||
}) | ||
|
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.
Can you explain what this is for?
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.
it's to add maps functionality to the fastify instance that we use for serving things over http. the functionality is separate into 3 plugins:
- static: provides ability to statically serve custom offline maps, similar to how Mapeo Mobile works
- fallback: provides ability to statically serve a directory that acts as the fallback map (which are set up differently that custom offline maps). this is mostly to accommodate for the fallback map structure that's used by Mapeo Mobile.
- maps: currently acts as the main resolver for the user-facing API e.g. resolving the appropriate style.json based on existence of static/fallback maps. in the future, this will probably hold other functionality related to features that are more similar to the Map Manager in Mapeo Mobile.
not entirely sure which map you're referring to when saying "offline", but for custom background maps, the legacy behavior is that if there's a custom background map loaded (e.g. a map that exists in Regarding the proposed approach for adjusting the setup for the query, your suggestion as is will not work because the URL returned by the api is stable during the lifetime of the backend server and will not change based on internet connectivity. Basically it will always point to Agree that the query can probably be switched to a suspense query, but the |
Agree that there's probably improvements to the UX around this stuff. but this PR is mostly focused on porting over the existing behavior from Mapeo Mobile, which is described by the decision tree above |
I misspoke on the first part here. Without any custom basemap, I thought the behavior when going from online to offline was that the fallback offline map would immediately be displayed in the app. Based on testing Mapeo Mobile, this is incorrect, and what you suggested is what actually happens in this case (again, wasn't sure what you mean by "offline"). Seems like the fallback offline map is never dynamically displayed i.e. when network state changes while app is active. It seems that it's only ever displayed when the map initially renders. I think what I was trying to improve with this change was the opposite situation: what if you're offline but then you become online? (again, no custom basemaps) Seems like it would be a nice feature to be able to dynamically switch to the online map in that case, but that's not what happens in Mapeo Mobile currently, so maybe that would be a follow-up This is an easy fix in this PR, as it basically means I can get rid of the network-related parts of the changes, which will simplify the PR as a side effect! |
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, everything is working
This is out of scope of this PR, but we should check when the user goes back online and serve that online map without forcing them to close the app.
For the posterity I didn't actually test this with a custom map...For the MVP release that doesn't feel like a priority so I will make note it for the QA testers |
also for posterity, i tested this on my Pixel 2 Android 11 using some custom maps from the Mapeo testing kit (which we have in Google Drive) |
Closes #243
Notes:
decision tree for which map's style.json to serve (EDIT: when map initially loads/renders):
Remaining items:
on my Pixel 2 Android 11, zooming out eventually causes the app to crash. have only tried this with one example map so not sure if it's specific to this map or a general issue. i get the following some cryptic logs from adb but not sure how to debug:
NODEJS-MOBILE: exiting due to SIG_DFL handler for signal 11
One thing to try next: upload same map to Mapeo Mobile and see if same crash happens.
EDIT: I'm no longer getting the crash for mysterious reasons...
attempting to test this on my Pixel 6 Android 14 is very difficult due to storage permission changes introduced in Android 13+14. Basically almost impossible without using adb and even then, it requires some complicated workarounds that I have yet to figure out (think other members of our team have done it before).EDIT: will not test on pixel 6 for now