tangrams / tangram

WebGL map rendering engine for creative cartography
https://tangram.city
MIT License
2.22k stars 290 forks source link

Add background color parameter for screenshots #570

Closed bcamper closed 7 years ago

bcamper commented 7 years ago

Adds an optional background color that will be blended with any translucent pixels in the scene when capturing a screenshot. In normal browser presentation, these pixels are blended with whatever HTML content is behind them. With this optional parameter, users have more control to achieve similar when capturing a screenshot.

The existing scene.screenshot() method signature is expanded to support a background parameter:

scene.screenshot ({ background = 'white' }

The background parameter defaults to white. This is because while the Tangram scene's default background is transparent, it is always viewed against an opaque browser background (which itself defaults to white, absent any user styling). As such, a default screenshot background color of white is most likely to match the user's expectations. However, the background can still be set to transparent, or to any other color format accepted by Tangram (red, [0.5, 0.5, 0], etc.).

Example of capturing a screenshot with an explicit transparent background, then opening it in a new window:

scene.screenshot({ background: 'transparent' }).then(s => window.open(s.url))

bcamper commented 7 years ago

Released in v0.13.0