2013-08-20 18:05:33 +08:00
# Torque API
2013-08-21 02:20:53 +08:00
Torque provides two kinds of visualizations.
2013-08-20 18:05:33 +08:00
2013-08-20 21:07:26 +08:00
- static: provides a way to create heatmap like visualizations (note for Andrew: fon). see ``TorqueLayer``
2013-08-21 02:20:53 +08:00
- dynamic: animate points over a map (note for Andrew: Navy) see ``TiledTorqueLayer``
2013-08-20 18:05:33 +08:00
depending on the map provider you are using you need to use different layer type. Currently we provide layers for Google Maps and Leaflet.
## L.TorqueLayer(options)
2013-08-21 05:33:15 +08:00
One of two core classes for the Torque library - it is used to create an animated torque layer with custom settings.
2013-08-21 02:16:12 +08:00
2013-08-21 05:16:37 +08:00
### Usage example
2013-08-21 02:16:12 +08:00
```js
// initialize a torque layer that uses the CartoDB account details and SQL API to pull in data
var torqueLayer = new L.TorqueLayer({
user : 'viz2',
table : 'ow',
column : 'date',
countby : 'count(cartodb_id)',
resolution : 1,
steps : 750,
pixel_size : 3,
blendmode : 'lighter'
});
```
2013-08-21 05:16:37 +08:00
### Options
2013-08-21 02:16:12 +08:00
##### Provider options
2013-08-21 02:47:56 +08:00
| Option | type | Default | Description |
|-----------|:-----------|:----------|:---------------------------------------|
| provider | string | ```sql_api``` | Where is the data coming from? Alternative is 'url_template'|
2013-08-21 02:16:12 +08:00
2013-08-21 02:20:53 +08:00
##### CartoDB data options
2013-08-21 02:47:56 +08:00
| Option | type | Default | Description |
|-----------|:-----------|:----------|:---------------------------------------|
| user | string | ```null``` | CartoDB account name. Found as, accountname.cartodb.com|
| table | string | ```null``` | CartoDB table name where data is found |
| column | string | ```null``` | CartoDB table's column name where date information is found (for dynamic type torque layer only)|
| countby | string | ```null``` | The aggregation method to use for each pixel displayed where multiple data are found. Any valid PostgreSQL aggregate function |
##### Display options
2013-08-21 02:54:12 +08:00
| Option | type | Default | Description |
|-----------|:-----------|:----------|:---------------------------------------|
2013-08-21 05:16:37 +08:00
| resolution| numeric | ```2``` | The x and y dimensions of each pixel as returned by the data|
2013-08-29 18:53:08 +08:00
| blendmode | boolean | ```source-over``` | The HTML5 Canvas composite operation for when multiple pixels overlap on the canvas |
2013-08-20 18:05:33 +08:00
2013-08-28 18:45:07 +08:00
##### Time options
| Option | type | Default | Description |
|-----------|:-----------|:----------|:---------------------------------------|
2013-11-11 23:55:34 +08:00
| steps | integer | ```100``` | The maximun number of steps to divide the data into for animated renderings |
2013-08-28 18:45:07 +08:00
| animationDuration | integer | ```null``` | time in seconds the animation last |
### Time methods
2013-08-21 05:16:37 +08:00
| Method | options | returns | Description |
|-----------|:-----------|:----------|:---------------------------------------|
2013-08-30 18:14:53 +08:00
| ```setStep(step)``` | ```time numeric``` | ```this``` | sets the animation to the step indicated by ```step```, must be between 0 and ```steps```|
2013-08-28 18:45:07 +08:00
| ```play```| | ```this```| starts the animation
| ```stop```| | ```this```| stops the animation and set time to step 0
| ```pause```| | ```this```| stops the animation but keep the current time (play enables the animation again)
2013-08-21 05:33:15 +08:00
2013-08-21 05:16:37 +08:00
2013-08-28 18:45:07 +08:00
### Style methods
2013-08-21 05:16:37 +08:00
2013-08-21 05:33:15 +08:00
| Method | options | returns | Description |
|-----------|:-----------|:----------|:---------------------------------------|
| ```setCartoCSS(cartocss)``` | ```cartocss string``` | ```this``` | style the map rendering using client-side cartocss |
2013-08-21 05:16:37 +08:00
2013-08-21 05:33:15 +08:00
The full CartoCSS spec is not supported by Torque but instead only a limited subset with some additions related to torque rendering. To see the full list of supported parameters, read the [Torque CartoCSS documentation here ](CartoCSS.md ). ``value`` and ``zoom`` variables can be used. ``value`` is the value of aggregation (see ``countby`` constructor option). ``zoom`` is the current zoom being rendered
2013-08-20 18:05:33 +08:00
2013-08-21 05:33:15 +08:00
TorqueLayer currently expects ```marker``` styling
##### CartoCSS Example
2013-08-20 18:05:33 +08:00
2013-08-21 05:34:53 +08:00
This should be ```string``` encoded in Javascript
2013-08-21 05:34:05 +08:00
```css
#layer {,
marker-fill: #662506 ;
marker-width: 20;
[value > 1] { marker-fill: #FEE391 ; }
[value > 2] { marker-fill: #FEC44F ; }
[value > 3] { marker-fill: #FE9929 ; }
[value > 4] { marker-fill: #EC7014 ; }
[value > 5] { marker-fill: #CC4C02 ; }
[value > 6] { marker-fill: #993404 ; }
[value > 7] { marker-fill: #662506 ; }
2013-08-28 18:45:07 +08:00
[frame-offset = 1] { marker-width: 20; marker-fill-opacity: 0.05;}', // renders the previos frame
[frame-offset = 2] { marker-fill: red; marker-width: 30; marker-fill-opacity: 0.02;}', // renders two frames ago from the current being rendered
2013-08-21 05:34:05 +08:00
}
```
2013-08-20 18:05:33 +08:00
## L.TiledTorqueLayer(options)
2013-08-21 05:33:15 +08:00
One of two core classes for the Torque library - it is used to create a static torque layer with client side filtering.
2013-08-20 18:05:33 +08:00
2013-08-21 05:33:15 +08:00
##### Provider options
| Option | type | Default | Description |
|-----------|:-----------|:----------|:---------------------------------------|
| provider | string | ```sql_api``` | Where is the data coming from? Alternative is 'url_template'|
| url | string | ```null``` | Tile template URL for fetching data e.g 'http://host.com/{z}/{x}/{y}.json'|
2013-08-20 18:05:33 +08:00
2013-08-21 05:33:15 +08:00
##### CartoDB data options (Note to Santana: are these really here?)
| Option | type | Default | Description |
|-----------|:-----------|:----------|:---------------------------------------|
| user | string | ```null``` | CartoDB account name. Found as, accountname.cartodb.com|
| table | string | ```null``` | CartoDB table name where data is found |
| column | string | ```null``` | CartoDB table's column name where date information is found (for dynamic type torque layer only)|
| countby | string | ```null``` | The aggregation method to use for each pixel displayed where multiple data are found. Any valid PostgreSQL aggregate function |
##### Display options (Note to Santana: is blendmode here? or above even?)
| Option | type | Default | Description |
|-----------|:-----------|:----------|:---------------------------------------|
| resolution| numeric | ```2``` | The x and y dimensions of each pixel as returned by the data|
2013-08-29 18:53:08 +08:00
| blendmode | boolean | ```source-over``` | The HTML5 Canvas composite operation for when multiple pixels overlap on the canvas |
2013-08-21 05:33:15 +08:00
### Filtering options
| Method | options | returns | Description |
|-----------|:-----------|:----------|:---------------------------------------|
2013-08-21 05:36:39 +08:00
| ```setKey(keys)``` | ```keys numeric/array``` | ```this``` | which data categories to display on the map |
2013-11-11 23:55:34 +08:00
| ```setSQL(sql)``` | ```sql string ``` | ```this``` | by default sql torque layer uses is
"select * from table", this method changes the sql query torque uses to fetch the data |
2013-08-21 05:33:15 +08:00
### Style options
| Method | options | returns | Description |
|-----------|:-----------|:----------|:---------------------------------------|
| ```setCartoCSS(cartocss)``` | ```cartocss string``` | ```this``` | style the map rendering using client-side cartocss |
2013-08-20 18:05:33 +08:00
2013-08-23 00:16:22 +08:00
``value`` and ``zoom`` variables can be used. only ``polygon-fill`` and ``polygon-opacity`` properties are supported currently. To see the full list of supported parameters, read the [Torque CartoCSS documentation here ](CartoCSS.md ).
2013-08-20 18:05:33 +08:00
2013-08-21 05:33:15 +08:00
TorqueLayer currently expects ```polygon``` styling
##### CartoCSS Example
2013-08-21 05:34:53 +08:00
This should be ```string``` encoded in Javascript
2013-08-21 05:34:05 +08:00
```css
#layer {
polygon-fill: #FFFF00 ;
[value >= 10] { polygon-fill: #FFCC00 ; }
[value >= 100] { polygon-fill: #FF9900 ; }
[value >= 1000] { polygon-fill: #FF6600 ; }
[value >= 10000] { polygon-fill: #FF3300 ; }
[value > 100000] { polygon-fill: #C00 ; }
}
```
2013-08-20 18:05:33 +08:00
2013-08-23 00:16:22 +08:00
# Google Maps Layers
2013-08-20 18:05:33 +08:00
2013-09-02 23:26:07 +08:00
## GMapsTorqueLayer(options)
This class does exactly the same than ``L.TorqueLayer`` but using Google Maps. The main difference is that this class
is not a layer is a overlay so in order to add it to the map use ``layer.setMap`` instead of ``overlayMapTypes``. See [Overlay view ](https://developers.google.com/maps/documentation/javascript/reference#OverlayView ) reference in Google Maps API doc.
### Options
2013-09-02 23:40:18 +08:00
##### options
2013-09-02 23:26:07 +08:00
| Option | type | Default | Description |
|-----------|:-----------|:----------|:---------------------------------------|
| map | google.maps.Map | | google.maps.Map instance |
see ``L.TorqueLayer`` for the rest of the options.
2013-08-23 00:16:22 +08:00
## GMapsTiledTorqueLayer(options)
2013-09-02 23:26:07 +08:00
creates a static _overlay_ to use it with google maps.
2013-08-23 00:16:22 +08:00
```js
var torqueLayer = new torque.GMapsTiledTorqueLayer({
provider: 'url_template',
url: GBIF_URL,
resolution: 4,
});
2013-09-02 23:26:07 +08:00
torqueLayer.setMap(map);
2013-08-23 00:16:22 +08:00
torqueLayer.setKey([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
```
see ``L.TiledTorqueLayer`` for options reference