mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.2k stars 2.22k forks source link

posGIS generated MVT with multiple layers filtered in mapbox component - good optimization strategy? #13109

Closed dee-cf closed 8 months ago

dee-cf commented 8 months ago

We have a postGIS ST_asMVT function creating our vector tiles. We can create multi-layer tile server using that function. Lets say we create tiles with 3 layers: layer1, layer2, layer3.

On the mapbox component side, we could addSource pointing to our api that returns those vector tiles. Then we could add 3 layers where each would use same source and each would have have source-layer property pointing to different layer in vector tile.

If I read documentation correctly, setting source-layer to layer2 would show only layer2 from vector tile within that mapbox layer.

Question is: on map events like zoom or pan, would source load 3 times (3 requests to the source url) because 3 layers use it or would there be a single request?

And, if its a single, is this a good performance optimization strategy where we want to minimize number of requests sent to our vector tile source?

stepankuzmin commented 8 months ago

Hi @codefactorydevelopment,

Thank you for using mapbox-gl-js.

on map events like zoom or pan, would source load 3 times (3 requests to the source url) because 3 layers use it or would there be a single request?

It would be a single request since all layers use the same source.

And, if its a single, is this a good performance optimization strategy where we want to minimize number of requests sent to our vector tile source?

Since it would be a single request, that would work for you if you want to minimize the number of requests.

For future "how do I" questions like this, please refer to our help documentation, and if you can't find the answer there, contact support. This issue tracker is for reporting bugs and feature requests.

You might also consider posting your question to https://stackoverflow.com/questions/tagged/mapbox-gl-js to ask the community for help.