maplibre-native
maplibre-native copied to clipboard
Fix updating regions
Marking a region as invalid has a number of problems. Tiles/Resources marked as offline that expire are not useable.
This PR does the following:
-
Track the online status in OnlineFileSource.
-
Adds canRequestNow to file sources. While canRequest checks the validity of the resource (to ensure it is the correct type of request for the given file source), it does not check whether or not the request can actually be performed. canRequestNow should check the environment to ensure that the request should be completable. This is currently only implemented for OnlineFileSource to check that a network connection is available, but could be expanded upon to ensure files are writable etc. 2a. In DatabaseFileSource.request when the response is not useable (
!offlineResponse->isUsable()
) - if the network is not available to revalidate / update the expired resource than allow the use of the old data because otherwise the map will show nothing. 2b. In MainResourceLoader.request if the database response is not usable but there is no network available, reply to the callback with the database version so that it can be used while the online request is scheduled to update the data when the network is available again. -
OfflineDownload.ensureResource checks whether the resource exists in the database, but doesn't check whether it is usable. If a region is invalidated, and then re-downloaded it doesn't schedule any network to request the new data because it thinks everything is fine. Now, check isUsable and ensure the etag, prior data etc is included in the request so that it can revalidate without having to download needlessly (server can respond 304 if nothing has changed)
-
SpriteLoader.load previously asserted if the data was the same, with the change in 3 above, it can be -> so now only emit if something actually changed, but don't assert
This fixes https://github.com/maplibre/maplibre-native/issues/410 and removes the need for https://github.com/maplibre/maplibre-native/issues/409