You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: These are the maximum tile sizes, not averages, but it's actually a better indicator in some ways because many tiles are largely empty (and this becomes even more true at high zooms), which skews the average tilesize downwards.
MapLibre fetches and parses dozens of tiles per second as you pan and zoom the map. Even on a fast internet connection where fetching is quick, parsing a large tile and preparing it for rendering requires significant work: reading PBF data, triangulating polygon geometries and computing normals for line geometries, and generating collision boxes for symbols.
This work happens on the CPU, and once it starts it can't be interrupted (unlike fetching, which can via an AbortController). This explains why zooming on OpenTrailMap is especially laggy: as you pass through each intermediate zoom level, new tiles are requested, and if any of them finish loading before the final zoom level is reached, that tile will be parsed and prepared for rendering, tying up the thread and preventing other tiles which are needed at the final zoom level from being processed. Ironically this means that the lag is worst on a fast internet connection, since more tile fetch requests will "win the race" against the AbortController and enter the processing queue.
To fix this, tiles in the trails tileset need to be made much smaller: at least 10x smaller if not more. Fortunately, this is pretty achievable. While OpenTrailMap does require more data in the vector tiles than a traditional map (in order to support filtering and color-coding trails by a bunch of different tags), a large fraction of the total tile size can be explained by a few design choices that could be revisited.
Here are a couple ideas:
Increase the tileset minzoom. The table above shows that z7-z9 are the largest layers; we could only generate trails tiles for z10+. This would also help with the zoom lag issue, since if these tiles don't exist, they won't be fetched and clog up the processing queue as a user zooms in. Lower zooms would still display a map, but it wouldn't be interactive or filterable until you zoom in.
Remove unnecessary attributes from features. The only attributes that need to be present on tile features are the ones used for styling or filtering the map. Other metadata that's only displayed when you click on a feature could be loaded on demand from the OSM API. There are a bunch of attributes that could be removed with minimal/no loss in functionality, for example:
OSM_CHANGESET, OSM_USER_NAME, and OSM_VERSION (not used for rendering at all AFAIK)
OSM_TYPE and OSM_ID (can be decoded from the feature ID assigned by Planetiler instead)
OSM_TIMESTAMP (only used for "last modified date" filtering; should be replaced by a lower cardinality value like YYYY-MM)
MIN_LON, MIN_LAT, MAX_LON, and MAX_LAT (only used to zoom the map to a selected feature; these four fields alone are responsible for ~10% of the data in a tile I tested because each feature tends to have unique values).
AREA_Z0_PX2 (used on label points for areas; should instead compute a reasonable minzoom at build time)
Some of these changes require removing existing features in OpenTrailMap (such as certain filter types, or "zoom to feature"), but I think this is worth considering as a way to improve the overall usefulness of the tool and make it possible to continue to extend and improve it in the future.
OpenTrailMap's main map view currently has some significant performance problems:
The initial page load takes several seconds to render the map:
opentrailmap.loading.mp4
When panning the map, tiles often take longer than they should to render:
opentrailmap.panning.mp4
When zooming the map often gets stuck displaying low-zoom tiles for many seconds:
opentrailmap.zooming.mp4
Panning or zooming the map too much often causes the browser tab to freeze up entirely, forcing the user to close the tab and open a new one.
All of the above symptoms are caused by the fact that the tiles in the
trailstileset are very large.Note: These are the maximum tile sizes, not averages, but it's actually a better indicator in some ways because many tiles are largely empty (and this becomes even more true at high zooms), which skews the average tilesize downwards.
MapLibre fetches and parses dozens of tiles per second as you pan and zoom the map. Even on a fast internet connection where fetching is quick, parsing a large tile and preparing it for rendering requires significant work: reading PBF data, triangulating polygon geometries and computing normals for line geometries, and generating collision boxes for symbols.
This work happens on the CPU, and once it starts it can't be interrupted (unlike fetching, which can via an AbortController). This explains why zooming on OpenTrailMap is especially laggy: as you pass through each intermediate zoom level, new tiles are requested, and if any of them finish loading before the final zoom level is reached, that tile will be parsed and prepared for rendering, tying up the thread and preventing other tiles which are needed at the final zoom level from being processed. Ironically this means that the lag is worst on a fast internet connection, since more tile fetch requests will "win the race" against the AbortController and enter the processing queue.
To fix this, tiles in the
trailstileset need to be made much smaller: at least 10x smaller if not more. Fortunately, this is pretty achievable. While OpenTrailMap does require more data in the vector tiles than a traditional map (in order to support filtering and color-coding trails by a bunch of different tags), a large fraction of the total tile size can be explained by a few design choices that could be revisited.Here are a couple ideas:
Increase the tileset minzoom. The table above shows that z7-z9 are the largest layers; we could only generate trails tiles for z10+. This would also help with the zoom lag issue, since if these tiles don't exist, they won't be fetched and clog up the processing queue as a user zooms in. Lower zooms would still display a map, but it wouldn't be interactive or filterable until you zoom in.
Remove unnecessary attributes from features. The only attributes that need to be present on tile features are the ones used for styling or filtering the map. Other metadata that's only displayed when you click on a feature could be loaded on demand from the OSM API. There are a bunch of attributes that could be removed with minimal/no loss in functionality, for example:
OSM_CHANGESET,OSM_USER_NAME, andOSM_VERSION(not used for rendering at all AFAIK)OSM_TYPEandOSM_ID(can be decoded from the feature ID assigned by Planetiler instead)OSM_TIMESTAMP(only used for "last modified date" filtering; should be replaced by a lower cardinality value like YYYY-MM)MIN_LON,MIN_LAT,MAX_LON, andMAX_LAT(only used to zoom the map to a selected feature; these four fields alone are responsible for ~10% of the data in a tile I tested because each feature tends to have unique values).AREA_Z0_PX2(used on label points for areas; should instead compute a reasonable minzoom at build time)Some of these changes require removing existing features in OpenTrailMap (such as certain filter types, or "zoom to feature"), but I think this is worth considering as a way to improve the overall usefulness of the tool and make it possible to continue to extend and improve it in the future.