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

Handle empty 20x raster tile response as empty tile. #1586

Conversation

cns-solutions-admin
Copy link
Contributor

getImage (ajax.ts) now returns a null image, if there is no content (ArrayBuffer with length 0).
Raster source loadTile will store such an image as a tile with the new status 'empty' (to avoid loading it again, if there are cache headers).

See also #1579.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 30, 2022

Bundle size report:

Size Change: +60 B
Total Size Before: 204 kB
Total Size After: 204 kB

Output file Before After Change
maplibre-gl.js 195 kB 195 kB +60 B
maplibre-gl.css 9.03 kB 9.03 kB 0 B
ℹ️ View Details No major changes

@HarelM
Copy link
Collaborator

HarelM commented Aug 30, 2022

Can you also add tests to raster source too?
Also, I can't get a grasp of what exactly this might cause in terms of risk.
Basically, I need you to clam me down and explain why this is not "risky" :-)

@HarelM
Copy link
Collaborator

HarelM commented Aug 30, 2022

Also please add a changelog item as part of this PR

@cns-solutions-admin
Copy link
Contributor Author

And I hoped you could review it and tell me if it was "risky" (and why) ;-)

@HarelM
Copy link
Collaborator

HarelM commented Aug 31, 2022

:-o :-)

@xabbu42
Copy link
Contributor

xabbu42 commented Aug 31, 2022

As already mentioned in #161 (comment) there was some discussion to use 204 just to silence the browser errors, but still fall back to lower zoom-level and not interpret the result as an empty tile. I personally think that compatibility with other map tools (especially current mapbox-gl-js) is the most important aspect here. That is depending on what other tools do, we should merge either #161 or this pull request to handle 204 (at least from my understanding of the two pull requests, I did not dive into the code).

Is my understanding correct that currently maplibre-gl-js falls back on scaling lower zoom levels for 204 tiles, but with this pull request does not? (I may have some time to test this later but perhaps you already know the answer).

@cns-solutions-admin
Copy link
Contributor Author

Without the change in raster_tile_source it just suppresses the error message: the raster_tile_source ignores null results.

With the change in raster_tile_source the only change would be, that these empty tiles would not be requested again each time, if they had a cache header. But this should be checked by somebody who knows the source_cache better.

Generally I think it is not compatibility to client libraries but to tile servers, that we should strive for.
And I think that if a tile server returns 204

  • there is no data and there should not be an error in the log
  • if it sends cache/expire headers with 204, we should not make more requests during that period

Whether maplibre should try to use tiles from another tile or not, is another question. Currently maplibre seems handle 404 differently than other results.

@systemed
Copy link

systemed commented Sep 1, 2022

Whenever I've written a tileserver I've had to patch in some code to send empty tiles, because some clients don't like 204s. So this would be a great improvement.

@HarelM
Copy link
Collaborator

HarelM commented Sep 1, 2022

@systemed can you review this as well then?

@systemed
Copy link

systemed commented Sep 1, 2022

I don't have a Maplibre build setup (yet ;) ) so can't test the code, but from briefly grokking the patch and the test, it looks good to me.

@xabbu42
Copy link
Contributor

xabbu42 commented Sep 5, 2022

I think the following accepted pull request mapbox/mapbox-gl-native#8164 to mapbox-gl-native is relevant to the discussion. According to that pull request it is explicit designed behavior for mapbox-gl-native (and so also for maplibre-gl-native as it is currently) to fall back on lower zoom levels for empty raster tiles. Either maplibre-gl-js should follow that design or we will have to revert the changes in maplibre-gl-native as the two repos should be as close as possible. I will try to add some integration tests for the current behavior so the difference is clearly exposed by the tests.

There is also a similar open issue for mapbox-gl-js with relevant discussion: mapbox/mapbox-gl-js#9304

@HarelM
Copy link
Collaborator

HarelM commented Sep 5, 2022

In terms of feature parity with native we open an issue on their repo and link the relevant PR here for reference.
I'm honesty not sure what should be the right behavior. I tend to say that 204 and 404 are different and the library should be aware of this difference i.e. accept the PR.
@xabbu42 tests are always super welcome! 😁

@xabbu42 xabbu42 mentioned this pull request Sep 7, 2022
2 tasks
@HarelM
Copy link
Collaborator

HarelM commented Sep 12, 2022

@cns-solutions-admin can you rebase the branch with latest changes in main? @xabbu42 added tests so we can see if there's a change in behavior when introducing this PR.

@xabbu42
Copy link
Contributor

xabbu42 commented Sep 12, 2022

I expect this branch to pass the tests as they are by the way, whereas #160 and maplibre–gl-native would fail rasterfallback204 as it is, as they would actually fallback on zoom 0. According mapbox/mapbox-gl-native#8164 the latter is intentional.

I personally follow the reasoning given in that pull request and think we should in the end adapt maplibre-gl-js to maplibre-gl-native (after checking that it actually still has a different behavior). Of course we can also add an issue in maplibre-gl-native, if the current behavior of maplibre-gl-js is considered correct.

@cns-solutions-admin cns-solutions-admin force-pushed the #1579-response-204-handling branch 5 times, most recently from 653f346 to 76aa19e Compare September 21, 2022 10:46
@cns-solutions-admin
Copy link
Contributor Author

The test passes, the behavior is like before with the exception that no error message is logged.
The empty tile is stored in the tile cache with status empty and the expiration time from the cache header.

} else if (imgResult != null) {
callback(null, imgResult as (HTMLImageElement | ImageBitmap), {cacheControl, expires});
} else {
callback(null, imgResult as (HTMLImageElement | ImageBitmap | null), {cacheControl, expires});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of adding this case to the decorated callback I would consider simply calling the callback with null.
The decorated callback is used in the below function to facilitate less code, but this is not the case in this flow.
i.e. adding an else to the callback and then writing an if in the below code is not needed I believe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@cns-solutions-admin can you please take care of this so I can merge this PR and carve out a release?

@HarelM
Copy link
Collaborator

HarelM commented Sep 25, 2022

I've added some code review comments.
When fixed I think this can be merged.

@xabbu42 xabbu42 mentioned this pull request Apr 3, 2023
4 tasks
@HarelM
Copy link
Collaborator

HarelM commented Jun 28, 2023

I'm closing this PR now.
I hope someone would pick it up so MapLibre can better support 204/empty 200.

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.

4 participants