2

Using Mapbox GL JS with self hosted vector tiles in protobuf format where it looks for tiles using {z}/{x}/{y}.pb paths.

I have a scenario where I only have data for zoom levels 9, 11 and 13.

Is there any way to prevent Mapbox GL JS to try loading other zoom levels?

At the moment I get a bunch of 404's on zoom level 12 for example.

3

Looking at the documentation, there are minZoom and maxZoom options available mapboxgl.Map object. Set these to 9 and 13 respectively and users won't be able to zoom beyond these points.

As for skipping zoom 10 and 12, you could listen to the zoom event, test whether the new zoom is 10 or 12, and force the map to skip to the next zoom. (I'm not sure what the zoom event looks like internally, but it must contain all the necessary data: previous zoom and new zoom. Throw it up on a jsfiddle and I'll take a look)

That being said, forcing users to skip a zoom level seems like bad UI. I wouldn't recommend it unless there's really no way to generate tiles at zoom 10 and 12.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.