vega / vl-convert

Utilities for converting Vega-Lite specs from the command line and Python
BSD 3-Clause "New" or "Revised" License
84 stars 9 forks source link

altair_tiles: Tiles are missing in PNG export but works with SVG #162

Closed binste closed 2 months ago

binste commented 2 months ago

In https://github.com/vega/altair_tiles/issues/38 it came up that for certain tile providers, the tiles are missing in an exported PNG but they show up in a Jupyter notebook and in an SVG chart.

Minimal example

import altair as alt
import altair_tiles as til
import geopandas as gpd

gdf_ne = gpd.read_file("https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip")  # zipped shapefile
extent_roi = gdf_ne.loc[gdf_ne["CONTINENT"] == "Africa", ["CONTINENT", "geometry"]]

chart = (
    alt.Chart(extent_roi)
    .mark_geoshape(fillOpacity=0.1, stroke="green", strokeWidth=2)
    .project(type="mercator")
)
chart = til.add_tiles(chart, provider=til.providers.Esri.WorldGrayCanvas).properties(
    width=600, height=400
)
chart

Chart displays as expected with tiles:

image

When saving to SVG and PNG, only the SVG image shows the tiles so seems like they get lost when downloading and embedding them.

chart.save("chart.svg")
chart.save("chart.png")

If you switch the provider in the above example to til.providers.OpenStreetMap.Mapnik, the tiles also show up in PNG. Sorry I don't know how to debug this any further but maybe it's something related to #63 where certain providers require specific request headers or so? In #64 you mentioned that we could set RUST_LOG to vl_convert but at least in a notebook, nothing shows up and I don't have cargo set up to install the CLI.

jonmmease commented 2 months ago

Thanks for the report, I'll take a look!

jonmmease commented 2 months ago

Fix released in version 1.4.0