tangrams / tangram

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

Support external scripts at scene-level #634

Closed bcamper closed 6 years ago

bcamper commented 6 years ago

This is an update to how we handle the (currently JS-only) feature of supporting custom JS scripts. Until now, these have been specifiable at the data source level, using the scripts keyword, which accepts an array of URLs for external scripts. The original intention was to make these scripts available in the execution scope for the source transform feature.

However, it makes sense to broaden this scope for two reasons:

To address the above, scripts are now also specifiable at the scene level. Additionally, the syntax has been revised (with backwards compatibility for existing sources) to provide better merge/import behavior, and reduce ambiguity/conflicts.

Instead of an array of script URLs, scripts are now specified as a mapping, with the key being a user-defined library name, and the value being the URL. For example:

scene:
  scripts:
    d3: https://d3js.org/d3.v5.min.js

This defines a d3 library at the specified URL. If the scene is imported into another scene that specifies the same d3 script name, the overriding URL will be used to load the library. (The previous syntax would have tried to load both scripts, which could lead to run-time errors depending on the script's behavior.)

For backwards compatibility, any array values for scripts in a data source are converted to a mapping, with each script URL used as both the key and value. Note that array values are not accepted for the scene-level scripts, since these are an entirely new feature/syntax.

bcamper commented 6 years ago

@meetar this addresses some issue we ran into with your dataviz experiments, especially for creating reusable scenes for importing.