tangram-es icon indicating copy to clipboard operation
tangram-es copied to clipboard

Enable data sources to define zoom levels from which tiles are loaded

Open matteblair opened this issue 5 years ago • 0 comments

From: https://github.com/tangrams/tangram/pull/702

Currently, tiled data sources request data at every map zoom level. There are some parameters that affect the mapping between the "view" zoom and the "tile" zoom (tile_size, zoom_offset), but these still trigger a new load at each zoom level.

There are some cases where it may be unnecessary or undesirable to load new tile data this frequently. This PR extends the syntax for data sources, with a new zooms parameter that can specify a list of zoom levels at which new data should be loaded.

For example, to only load new tile data at every other zoom level:

sources:
  tilezen:
    type: MVT
    url: ...
    zooms: [0, 2, 4, 6, 8, 10, 12, 14, 16] # only load tiles every 2 zooms

Or, an application with two logical levels -- such as a zoomed out and zoomed in view -- could define these explicitly, for example: zooms: [4, 12].

For view zooms in between these defined tile zooms, the tile for the next lowest available zoom will be overzoomed; in this sense, this feature extends and allows for more control of our existing overzooming behavior. For example, if zooms: [4, 8, 12, 16], when viewing the map at zoom 14, the zoom 12 tile will be overzoomed (note, this assumes 256px tiles).

Default / Max / Min Zooms

When zooms is undefined, the current behavior is used (tiles load at all zooms). If both zooms and max_zoom is present, the last zoom listed in zooms takes precedence, and overrides the max_zoom parameter. The min_display_zoom also automatically defaults to the first entry in the zooms list (e.g. if zooms: [4, 8, 12, 16], then min_display_zoom defaults to 4).

Other Zoom Adjustment Parameters

The tile_size and zoom_offset parameters can be mixed with zooms, and continue to behave as they do currently, by lowering the potential tile zoom requested for a given view zoom. For example, with this combination:

zooms: [4, 8, 12, 16]
tile_size: 512
zoom_offset: 2

A given view zoom will look for a tile zoom that is 3 levels lower (1 level for 512px tiles, plus 2 more for the zoom_offset). Thus at a view zoom of 12, the data source will look for the z9 tile, and then request/overzoom the z8 tile instead (the next available level defined in zooms). But at zoom 14, the data source will look for a z11 tile -- and will also use the z8 tile, since the requested level falls below the z12 thresholds in zooms, even though the map view zoom is above it; in this example, the z12 tile will not be requested until the view zoom is z15 (note, this is a somewhat extreme/contrived example for illustration).

matteblair avatar Feb 20 '19 18:02 matteblair