Compare commits
4 Commits
master
...
point_labe
Author | SHA1 | Date | |
---|---|---|---|
|
cdb986f506 | ||
|
e2bcae0c84 | ||
|
a03f9ca4e2 | ||
|
2a47541cc5 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,4 +2,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
*.swp
|
*.swp
|
||||||
node_modules
|
node_modules
|
||||||
test/dist/suite-bundle.js
|
test/suite-bundle.js
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- '10'
|
- "0.10"
|
||||||
before_install:
|
|
||||||
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.9" CC="gcc-4.9"; fi
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
packages:
|
packages:
|
||||||
- pkg-config
|
- pkg-config
|
||||||
- libcairo2-dev
|
- libcairo2-dev
|
||||||
- libpango1.0-dev
|
|
||||||
- libjpeg8-dev
|
- libjpeg8-dev
|
||||||
- libgif-dev
|
- libgif-dev
|
||||||
- gcc-4.9
|
|
||||||
- g++-4.9
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
Contributing
|
|
||||||
---
|
|
||||||
|
|
||||||
The issue tracker is at [github.com/CartoDB/torque](https://github.com/CartoDB/torque).
|
|
||||||
|
|
||||||
We love pull requests from everyone, see [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/#contributing).
|
|
||||||
|
|
||||||
|
|
||||||
## Submitting Contributions
|
|
||||||
|
|
||||||
* You will need to sign a Contributor License Agreement (CLA) before making a submission. [Learn more here](https://carto.com/contributions).
|
|
10
Makefile
10
Makefile
@ -5,7 +5,6 @@ BROWSERIFY=./node_modules/browserify/bin/cmd.js
|
|||||||
JS_CLIENT_FILES= lib/torque/*.js \
|
JS_CLIENT_FILES= lib/torque/*.js \
|
||||||
lib/torque/renderer/*.js \
|
lib/torque/renderer/*.js \
|
||||||
lib/torque/gmaps/*.js \
|
lib/torque/gmaps/*.js \
|
||||||
lib/torque/ol/*.js \
|
|
||||||
lib/torque/leaflet/leaflet_tileloader_mixin.js \
|
lib/torque/leaflet/leaflet_tileloader_mixin.js \
|
||||||
lib/torque/leaflet/canvas_layer.js \
|
lib/torque/leaflet/canvas_layer.js \
|
||||||
lib/torque/leaflet/torque.js
|
lib/torque/leaflet/torque.js
|
||||||
@ -27,9 +26,6 @@ dist/torque.js: dist_folder dist/torque.uncompressed.js
|
|||||||
dist_folder:
|
dist_folder:
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
|
|
||||||
test_dist_folder:
|
|
||||||
mkdir -p test/dist
|
|
||||||
|
|
||||||
dist: dist_folder dist/torque.js
|
dist: dist_folder dist/torque.js
|
||||||
|
|
||||||
clean-results:
|
clean-results:
|
||||||
@ -38,8 +34,8 @@ clean-results:
|
|||||||
add-header:
|
add-header:
|
||||||
node lib/header.js
|
node lib/header.js
|
||||||
|
|
||||||
prepare-test-suite: test_dist_folder
|
prepare-test-suite:
|
||||||
$(BROWSERIFY) test/suite.js > test/dist/suite-bundle.js
|
browserify test/suite.js > test/suite-bundle.js
|
||||||
|
|
||||||
test: prepare-test-suite
|
test: prepare-test-suite
|
||||||
@echo "***tests***"
|
@echo "***tests***"
|
||||||
@ -47,7 +43,7 @@ test: prepare-test-suite
|
|||||||
|
|
||||||
test-acceptance: clean-results
|
test-acceptance: clean-results
|
||||||
@echo "***acceptance***"
|
@echo "***acceptance***"
|
||||||
./node_modules/.bin/qunit -c lib/torque/ -t `find test/acceptance/ -name "*.js"`
|
./node_modules/.bin/qunit -c lib/torque/ -t `find test/acceptance/ -name *.js`
|
||||||
|
|
||||||
test-all: test test-acceptance
|
test-all: test test-acceptance
|
||||||
|
|
||||||
|
61
NEWS
61
NEWS
@ -1,63 +1,4 @@
|
|||||||
3.1.2 (2019-mm-dd)
|
2.11.5
|
||||||
|
|
||||||
|
|
||||||
3.1.1 (2019-06-24)
|
|
||||||
- Fixed reading undefined layer #306
|
|
||||||
|
|
||||||
3.1.0 (2019-04-02)
|
|
||||||
- Upgrade canvas to version 2.4.1
|
|
||||||
|
|
||||||
3.0.0 (2019-03-29)
|
|
||||||
- Drop support for Node.js 6 and 8
|
|
||||||
- Handle exception: Image given has not completed loading
|
|
||||||
|
|
||||||
2.17.1 (2019-01-23)
|
|
||||||
- Upgrade deps:
|
|
||||||
- turbo-carto@0.21.1
|
|
||||||
- Upgrade devel deps:
|
|
||||||
- browserify@16.2.3
|
|
||||||
- qunitz@0.7.7
|
|
||||||
- request@2.88.0
|
|
||||||
- uglify-js@3.4.9
|
|
||||||
|
|
||||||
2.17.0 (2018-11-21)
|
|
||||||
- Use our current fork of mapnik while testing
|
|
||||||
- Add support for Node 8 & 10
|
|
||||||
- Support package-lock.json file
|
|
||||||
|
|
||||||
v2.16.5
|
|
||||||
-
|
|
||||||
|
|
||||||
v2.16.4
|
|
||||||
-
|
|
||||||
|
|
||||||
2.16.2
|
|
||||||
- Re-publish version
|
|
||||||
|
|
||||||
2.16.1
|
|
||||||
- Remove width trick to use clear rect #280
|
|
||||||
- Map option reference broken gmaps #279
|
|
||||||
|
|
||||||
2.16.0
|
|
||||||
- Updated Turbo-carto dependency to version 0.19.0.
|
|
||||||
|
|
||||||
2.15.1
|
|
||||||
- Fixed ready event then rendering more than one step
|
|
||||||
|
|
||||||
2.15.0
|
|
||||||
- Allow to render several steps at the same time (#247)
|
|
||||||
|
|
||||||
2.14.0
|
|
||||||
- Allow custom animator range (#243)
|
|
||||||
|
|
||||||
2.13.0
|
|
||||||
- Pass extra_params to server (#234)
|
|
||||||
|
|
||||||
2.12.0
|
|
||||||
- Added TileJSON provider
|
|
||||||
- Added getValues to fetch values for step
|
|
||||||
- Improved reference/api documentation
|
|
||||||
- Removed out of date examples
|
|
||||||
|
|
||||||
2.11.4
|
2.11.4
|
||||||
- Static torque maps now draw correctly when unhiding them
|
- Static torque maps now draw correctly when unhiding them
|
||||||
|
15
README.md
15
README.md
@ -1,7 +1,7 @@
|
|||||||
Torque
|
Torque
|
||||||
==
|
==
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/CartoDB/torque.svg?branch=master)](https://travis-ci.org/CartoDB/torque)
|
[![Build Status](https://travis-ci.org/CartoDB/torque.svg)](https://travis-ci.org/CartoDB/torque)
|
||||||
|
|
||||||
Render big, timeseries data in the client. Uses CartoDB to generate a datacube format. For a brief introduction to the format and methods, see our [presentation slides](http://gijs.github.com/images/cartodb_datacubes.pdf)
|
Render big, timeseries data in the client. Uses CartoDB to generate a datacube format. For a brief introduction to the format and methods, see our [presentation slides](http://gijs.github.com/images/cartodb_datacubes.pdf)
|
||||||
|
|
||||||
@ -23,14 +23,14 @@ The library uses CartoDB to generate a [layercube](https://github.com/CartoDB/ti
|
|||||||
|
|
||||||
The simplest way to use a visualization with Torque is...
|
The simplest way to use a visualization with Torque is...
|
||||||
|
|
||||||
#### Create a simple Torque visualization
|
<div class="margin20"></div>
|
||||||
|
<div class="code_title">Create a simple Torque visualization</div>
|
||||||
```javascript
|
``` javascript
|
||||||
...
|
...
|
||||||
<body>
|
<body>
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
</body>
|
||||||
...
|
...
|
||||||
<script>
|
|
||||||
// define the torque layer style using cartocss
|
// define the torque layer style using cartocss
|
||||||
var CARTOCSS = [
|
var CARTOCSS = [
|
||||||
'Map {',
|
'Map {',
|
||||||
@ -74,10 +74,9 @@ The simplest way to use a visualization with Torque is...
|
|||||||
});
|
});
|
||||||
torqueLayer.addTo(map);
|
torqueLayer.addTo(map);
|
||||||
torqueLayer.play()
|
torqueLayer.play()
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
```
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
```
|
||||||
[Grab the complete example source code](https://github.com/CartoDB/torque/blob/master/examples/navy_leaflet.html)
|
[Grab the complete example source code](https://github.com/CartoDB/torque/blob/master/examples/navy_leaflet.html)
|
||||||
<div class="margin20"></div>
|
<div class="margin20"></div>
|
||||||
|
|
||||||
|
8
dist/torque.full.js
vendored
8
dist/torque.full.js
vendored
File diff suppressed because one or more lines are too long
28422
dist/torque.full.uncompressed.js
vendored
28422
dist/torque.full.uncompressed.js
vendored
File diff suppressed because it is too large
Load Diff
4
dist/torque.js
vendored
4
dist/torque.js
vendored
File diff suppressed because one or more lines are too long
1790
dist/torque.uncompressed.js
vendored
1790
dist/torque.uncompressed.js
vendored
File diff suppressed because it is too large
Load Diff
160
doc/API.md
Normal file
160
doc/API.md
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
|
||||||
|
# Torque API
|
||||||
|
|
||||||
|
|
||||||
|
## L.TorqueLayer(options)
|
||||||
|
|
||||||
|
One of two core classes for the Torque library - it is used to create an animated torque layer with custom settings.
|
||||||
|
|
||||||
|
### Usage example
|
||||||
|
|
||||||
|
```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',
|
||||||
|
cartocss: CARTOCSS
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
##### Provider options
|
||||||
|
|
||||||
|
| Option | type | Default | Description | Options |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|---------|
|
||||||
|
| provider | string | ```sql_api``` | Where is the data coming from | `sql_api`, `url_template`, or `windshaft` |
|
||||||
|
|
||||||
|
##### CartoDB data options (SQL API provider)
|
||||||
|
|
||||||
|
| Option | type | Default | Description |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|
|
||||||
|
| user_name | string | ```null``` | CartoDB account name. Found from: http://accountname.cartodb.com|
|
||||||
|
| table_name | string | ```null``` | CartoDB table name where data is found |
|
||||||
|
| query | string | ```null``` | SQL query to be performed to fetch the data. You must use this param or table, not at the same time |
|
||||||
|
| cartocss | string | ```null``` | CartoCSS style for this map |
|
||||||
|
| loop | boolean | ```true``` | If ```false```, the animation is paused when it reaches the last frame |
|
||||||
|
|
||||||
|
|
||||||
|
### Time methods
|
||||||
|
|
||||||
|
| Method | options | returns | Description |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|
|
||||||
|
| ```setStep(step)``` | ```time numeric``` | ```this``` | sets the animation to the step indicated by ```step```, must be between 0 and ```steps```|
|
||||||
|
| ```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)
|
||||||
|
| ```toggle()```| | ```this```| toggles (pause/play) the animation
|
||||||
|
| ```getStep()``` | | current animation step (integer) | gets the current animation step
|
||||||
|
| ```getTime()``` | | current animation time (Date) | gets the real animation time
|
||||||
|
| ```isRunning()``` | | `true`/`false` | describes whether the Torque layer is playing or is stopped
|
||||||
|
|
||||||
|
### Layer control methods
|
||||||
|
|
||||||
|
| Method | options | returns | Description |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|
|
||||||
|
| ```hide()``` | none |```this``` | hides the Torque layer |
|
||||||
|
| ```show()```| none| ```this``` | shows the Torque layer |
|
||||||
|
|
||||||
|
### Style methods
|
||||||
|
|
||||||
|
| Method | options | returns | Description |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|
|
||||||
|
| ```setCartoCSS(cartocss)``` | ```cartocss string``` | ```this``` | style the map rendering using client-side cartocss (not available with named maps) |
|
||||||
|
|
||||||
|
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](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
|
||||||
|
|
||||||
|
TorqueLayer currently expects ```marker``` styling.
|
||||||
|
|
||||||
|
##### CartoCSS Example
|
||||||
|
|
||||||
|
This should be ```string``` encoded in Javascript.
|
||||||
|
|
||||||
|
```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; }
|
||||||
|
[frame-offset = 1] { marker-width: 20; marker-fill-opacity: 0.05;}' // renders the previous frame
|
||||||
|
[frame-offset = 2] { marker-fill: red; marker-width: 30; marker-fill-opacity: 0.02;}' // renders two frames ago from the current being rendered
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Data methods
|
||||||
|
| Method | options | returns | Description |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|
|
||||||
|
| ```setSQL(sql statement)``` | ```SQL string``` | ```this``` | Change the SQL on the data table (not available with named maps) |
|
||||||
|
| ```error(callback)``` | ```callback function with a list of errors as argument``` | ```this``` | specifies a callback function to run if there are query errors |
|
||||||
|
|
||||||
|
##### SQL Example
|
||||||
|
|
||||||
|
Limit the data used in the Torque map.
|
||||||
|
```js
|
||||||
|
torqueLayer.setSQL("SELECT * FROM table LIMIT 100");
|
||||||
|
```
|
||||||
|
|
||||||
|
### Interaction methods (only available for Leaflet)
|
||||||
|
| Method | options | returns | Description |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|
|
||||||
|
| ```getValueForPos(x, y[, step])```| | an object like { bbox:[], value: VALUE } if there is value for the pos, null otherwise | allows to get the value for the coordinate (in map reference system) for a concrete step. If step is not specified the animation one is used. This method is expensive in terms of CPU so be careful. It returns the value from the raster data not the rendered data |
|
||||||
|
| ```getValueForBBox(xstart, ystart, xend, yend)```| | a number | returns an accumulated numerical value from all the torque areas within the specified bounds |
|
||||||
|
| ```getActivePointsBBox(step)```| | list of bbox | returns the list of bounding boxes active for ``step``
|
||||||
|
| ```invalidate()```| | | forces a reload of the layer data.
|
||||||
|
|
||||||
|
### Interaction methods (only available for Leaflet)
|
||||||
|
| Method | options | returns | Description |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|
|
||||||
|
| ```getActivePointsBBox(step)```| | list of bbox | returns the list of bounding boxes active for ``step``
|
||||||
|
| ```invalidate()```| | | forces a reload of the layer data.
|
||||||
|
|
||||||
|
|
||||||
|
### Events
|
||||||
|
Events in Torque follow the format:
|
||||||
|
```js
|
||||||
|
torqueLayer.on('event-type', function([callback_obj]) {
|
||||||
|
// do something
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
| Events | callback object | Description |
|
||||||
|
|-----------|:----------|:---------------------------------------|
|
||||||
|
| ```change:steps```| current step | When a map changes steps, this event is triggered |
|
||||||
|
| ```change:time```| current time, step number | When a map changes time, this event is triggered |
|
||||||
|
| ```play```| none | Triggered when the Torque layer is played |
|
||||||
|
| ```pause```| none | Triggered when the Torque layer is paused |
|
||||||
|
| ```stop```| none | Triggered when the Torque layer is stopped |
|
||||||
|
| ```load```| none | Triggered when the Torque layer is loaded |
|
||||||
|
|
||||||
|
##### Event Example
|
||||||
|
|
||||||
|
Print the current step to the console log.
|
||||||
|
```js
|
||||||
|
torqueLayer.on('change:steps', function(step) {
|
||||||
|
// do something with step
|
||||||
|
console.log("Current step is " + step);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# Google Maps Layers
|
||||||
|
|
||||||
|
## GMapsTorqueLayer(options)
|
||||||
|
This class does exactly the same as ``L.TorqueLayer`` but using Google Maps instead. The main difference is that this class
|
||||||
|
is not a layer but is an overlay, so in order to add it to the a map use, ``layer.setMap`` instead of ``overlayMapTypes``. See the [Overlay View](https://developers.google.com/maps/documentation/javascript/reference#OverlayView) reference in Google Maps API doc.
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
##### options
|
||||||
|
| Option | type | Default | Description |
|
||||||
|
|-----------|:-----------|:----------|:---------------------------------------|
|
||||||
|
| map | google.maps.Map | | google.maps.Map instance |
|
||||||
|
|
||||||
|
see ``L.TorqueLayer`` for the rest of the options.
|
||||||
|
|
||||||
|
|
@ -1,24 +1,23 @@
|
|||||||
## Torque CartoCSS
|
|
||||||
|
|
||||||
CartoCSS is one the tools of the CARTO platform. You can learn more about the different [components of CARTO platform]({{site.fundamental_docs}}/components/), or directly dig into [CartoCSS too]({{site.styling_cartocss}}/) details.
|
# Torque CartoCSS
|
||||||
|
|
||||||
`-torque-clear-color`
|
## -torque-clear-color
|
||||||
Color used to clear canvas on each frame.
|
Color used to clear canvas on each frame.
|
||||||
|
|
||||||
`-torque-frame-count`
|
## -torque-frame-count
|
||||||
Number of animation steps/frames used in the animation. If the data contains a fewer number of total frames, the lesser value will be used.
|
Number of animation steps/frames used in the animation. If the data contains a fewer number of total frames, the lesser value will be used.
|
||||||
|
|
||||||
`-torque-resolution`
|
## -torque-resolution
|
||||||
Spatial resolution in pixels. A resolution of 1 means no spatial aggregation of the data. Any other resolution of N results in spatial aggregation into cells of NxN pixels. The value N must be power of 2.
|
Spatial resolution in pixels. A resolution of 1 means no spatial aggregation of the data. Any other resolution of N results in spatial aggregation into cells of NxN pixels. The value N must be power of 2.
|
||||||
|
|
||||||
`-torque-animation-duration`
|
## -torque-animation-duration
|
||||||
Animation duration in seconds.
|
Animation duration in seconds.
|
||||||
|
|
||||||
`-torque-aggregation-function`
|
## -torque-aggregation-function
|
||||||
A function used to calculate a value from the aggregate data for each cell. See [-torque-resolution](#-torque-resolution).
|
A function used to calculate a value from the aggregate data for each cell. See [-torque-resolution](#-torque-resolution).
|
||||||
|
|
||||||
`-torque-time-attribute`
|
## -torque-time-attribute
|
||||||
The table column that contains the time information used create the animation.
|
The table column that contains the time information used create the animation.
|
||||||
|
|
||||||
`-torque-data-aggregation`
|
## -torque-data-aggregation
|
||||||
A linear animation will discard previous values while a cumulative animation will accumulate them until it restarts.
|
A linear animation will discard previous values while a cumulative animation will accumulate them until it restarts.
|
@ -1,57 +0,0 @@
|
|||||||
{
|
|
||||||
"main": {
|
|
||||||
"file": "static_bubble_map.html"
|
|
||||||
},
|
|
||||||
"categories": [
|
|
||||||
{
|
|
||||||
"title": "Static",
|
|
||||||
"samples": [
|
|
||||||
{
|
|
||||||
"title": "Bubble Map",
|
|
||||||
"desc": "",
|
|
||||||
"file": "static_bubble_map.html"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Heatmap",
|
|
||||||
"desc": "",
|
|
||||||
"file": "static_heat_map.html"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Heatmap Simple",
|
|
||||||
"desc": "",
|
|
||||||
"file": "static_heat_map_simple.html"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Misc",
|
|
||||||
"samples": [
|
|
||||||
{
|
|
||||||
"title": "Light Bright",
|
|
||||||
"desc": "",
|
|
||||||
"file": "light_bright.html"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Dual Encode",
|
|
||||||
"desc": "",
|
|
||||||
"file": "dual_encode.html"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Navy Ships GMaps",
|
|
||||||
"desc": "",
|
|
||||||
"file": "navy_gmaps.html"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Navy Ships Leaflet",
|
|
||||||
"desc": "",
|
|
||||||
"file": "navy_leaflet.html"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Navy Ships OpenLayers",
|
|
||||||
"desc": "",
|
|
||||||
"file": "navy_ol.html"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head lang="en">
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>CartoDb Torque Layer Example</title>
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.17.1/ol.css" type="text/css">
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.17.1/ol.js"></script>
|
|
||||||
<style>
|
|
||||||
#map, html, body {
|
|
||||||
width: 100%; height: 100%; padding: 0; margin: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="map"></div>
|
|
||||||
<script src="https://libs.cartocdn.com/torque.js/2.16.5/torque.full.js" type="application/javascript" charset="utf-8"></script>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// define the torque layer style using cartocss
|
|
||||||
var CARTOCSS = [
|
|
||||||
'Map {',
|
|
||||||
'-torque-time-attribute: "date";',
|
|
||||||
'-torque-aggregation-function: "count(cartodb_id)";',
|
|
||||||
'-torque-frame-count: 760;',
|
|
||||||
'-torque-animation-duration: 15;',
|
|
||||||
'-torque-resolution: 2',
|
|
||||||
'}',
|
|
||||||
'#layer {',
|
|
||||||
' marker-width: 3;',
|
|
||||||
' marker-fill-opacity: 0.8;',
|
|
||||||
' marker-fill: #FEE391; ',
|
|
||||||
' comp-op: "lighten";',
|
|
||||||
' [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; }',
|
|
||||||
' [frame-offset = 1] { marker-width: 10; marker-fill-opacity: 0.05;}',
|
|
||||||
' [frame-offset = 2] { marker-width: 15; marker-fill-opacity: 0.02;}',
|
|
||||||
'}'
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
var map = new ol.Map({
|
|
||||||
target: "map",
|
|
||||||
view: new ol.View({
|
|
||||||
center: [40, 0],
|
|
||||||
zoom: 3
|
|
||||||
}),
|
|
||||||
layers: [
|
|
||||||
new ol.layer.Tile({
|
|
||||||
source: new ol.source.XYZ({ url: 'https://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png'})
|
|
||||||
})
|
|
||||||
],
|
|
||||||
interactions: ol.interaction.defaults({
|
|
||||||
dragPan: false
|
|
||||||
}).extend([
|
|
||||||
new ol.interaction.DragPan({kinetic: false})
|
|
||||||
])
|
|
||||||
});
|
|
||||||
|
|
||||||
var torqueLayer = new ol.TorqueLayer({
|
|
||||||
user : 'viz2',
|
|
||||||
table : 'ow',
|
|
||||||
cartocss: CARTOCSS,
|
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443
|
|
||||||
});
|
|
||||||
|
|
||||||
torqueLayer.onAdd(map);
|
|
||||||
torqueLayer.play()
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,83 +0,0 @@
|
|||||||
<html>
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" />
|
|
||||||
<style>
|
|
||||||
#map, html, body {
|
|
||||||
width: 100%; height: 100%; padding: 0; margin: 0;
|
|
||||||
}
|
|
||||||
#range-control {
|
|
||||||
text-align: right;
|
|
||||||
padding: 4px 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<body>
|
|
||||||
<div id="range-control">
|
|
||||||
Render range:
|
|
||||||
<label for="start">start</label> <input id="start" value="90">
|
|
||||||
<label for="end">end</label> <input id="end" value="180">
|
|
||||||
<button onclick="renderRange()">Apply</button>
|
|
||||||
<button onclick="resetRenderRange()">Reset</button>
|
|
||||||
</div>
|
|
||||||
<div id="map"></div>
|
|
||||||
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script>
|
|
||||||
<script src="https://libs.cartocdn.com/torque.js/2.16.5/torque.full.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// define the torque layer style using cartocss
|
|
||||||
var CARTOCSS = [
|
|
||||||
'Map {',
|
|
||||||
' -torque-frame-count: 360;',
|
|
||||||
' -torque-animation-duration: 30;',
|
|
||||||
' -torque-time-attribute: "cartodb_id";',
|
|
||||||
' -torque-aggregation-function: "count(cartodb_id)";',
|
|
||||||
' -torque-resolution: 1;',
|
|
||||||
' -torque-data-aggregation: linear;',
|
|
||||||
'}',
|
|
||||||
'#generate_series {',
|
|
||||||
' comp-op: lighter;',
|
|
||||||
' marker-fill-opacity: 0.9;',
|
|
||||||
' marker-line-color: #FFF;',
|
|
||||||
' marker-line-width: 0;',
|
|
||||||
' marker-line-opacity: 1;',
|
|
||||||
' marker-type: rectable;',
|
|
||||||
' marker-width: 6;',
|
|
||||||
' marker-fill: #0F3B82;',
|
|
||||||
'}'
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
|
|
||||||
var map = new L.Map('map', {
|
|
||||||
zoomControl: true,
|
|
||||||
center: [0, 0],
|
|
||||||
zoom: 2
|
|
||||||
});
|
|
||||||
|
|
||||||
L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {
|
|
||||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
|
||||||
}).addTo(map);
|
|
||||||
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
|
||||||
user: 'documentation',
|
|
||||||
sql: 'SELECT s + 181 as cartodb_id, st_transform(ST_SetSRID (st_makepoint(s, 10*sin(s)), 4326), 3857) as the_geom_webmercator FROM generate_series(-180, 180, 1) as s',
|
|
||||||
cartocss: CARTOCSS,
|
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443,
|
|
||||||
zIndex: 10
|
|
||||||
});
|
|
||||||
torqueLayer.error(console.warn);
|
|
||||||
torqueLayer.addTo(map);
|
|
||||||
torqueLayer.play();
|
|
||||||
|
|
||||||
function renderRange() {
|
|
||||||
var start = document.getElementById('start').value;
|
|
||||||
var end = document.getElementById('end').value;
|
|
||||||
torqueLayer.renderRange(+start, +end);
|
|
||||||
}
|
|
||||||
function resetRenderRange() {
|
|
||||||
torqueLayer.resetRenderRange();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
|||||||
<html>
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" />
|
|
||||||
<style>
|
|
||||||
#map, html, body {
|
|
||||||
width: 100%; height: 100%; padding: 0; margin: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<body>
|
|
||||||
<div id="map"></div>
|
|
||||||
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script>
|
|
||||||
<script src="../dist/torque.full.uncompressed.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// define the torque layer style using cartocss
|
|
||||||
var CARTOCSS = [
|
|
||||||
'Map {',
|
|
||||||
'-torque-time-attribute: "date";',
|
|
||||||
'-torque-aggregation-function: "count(cartodb_id)";',
|
|
||||||
'-torque-frame-count: 760;',
|
|
||||||
'-torque-animation-duration: 15;',
|
|
||||||
'-torque-resolution: 2',
|
|
||||||
'}',
|
|
||||||
'#layer {',
|
|
||||||
' marker-width: 3;',
|
|
||||||
' marker-fill-opacity: 0.8;',
|
|
||||||
' marker-fill: #FEE391; ',
|
|
||||||
' comp-op: "lighten";',
|
|
||||||
' [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; }',
|
|
||||||
' [frame-offset = 1] { marker-width: 10; marker-fill-opacity: 0.05;}',
|
|
||||||
' [frame-offset = 2] { marker-width: 15; marker-fill-opacity: 0.02;}',
|
|
||||||
'}'
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
|
|
||||||
var map = new L.Map('map', {
|
|
||||||
zoomControl: true,
|
|
||||||
center: [40, 0],
|
|
||||||
zoom: 3
|
|
||||||
});
|
|
||||||
|
|
||||||
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
|
|
||||||
attribution: 'CartoDB'
|
|
||||||
}).addTo(map);
|
|
||||||
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
|
||||||
tileJSON: "http://localhost:4000/examples/tilejson.json",
|
|
||||||
cartocss: CARTOCSS
|
|
||||||
});
|
|
||||||
torqueLayer.error(function(err){
|
|
||||||
for(error in err){
|
|
||||||
console.warn(err[error]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
torqueLayer.addTo(map);
|
|
||||||
torqueLayer.play()
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"start": -1796072400000,
|
|
||||||
"end": -1414843200000,
|
|
||||||
"resolution": 2,
|
|
||||||
"data_steps": 861786,
|
|
||||||
"column_type": "date",
|
|
||||||
"tiles": ["http://{s}.ashbu.cartocdn.com/viz2/api/v1/map/cf28c540d3cf15a29a759f84ff440679:0/0/{z}/{x}/{y}.json.torque"]
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
## Getting Started
|
|
||||||
|
|
||||||
Although the most straightforward way to use Torque is through either CARTO Builder, or by passing the layer's viz.json to [CARTO.js]({{site.cartojs_docs}}/), many use cases work best with the standalone Torque.js. Assuming you have a public dataset with a `date` column, it is really simple to create an animated map with the library. First, you need to have a Leaflet map prepared in an HTML page:
|
|
||||||
|
|
||||||
```html
|
|
||||||
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
|
|
||||||
<body>
|
|
||||||
<div id="map"></div>
|
|
||||||
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
|
|
||||||
<script>
|
|
||||||
var map = new L.Map('map', {
|
|
||||||
zoomControl: true,
|
|
||||||
center: [40, 0],
|
|
||||||
zoom: 3
|
|
||||||
});
|
|
||||||
|
|
||||||
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
|
|
||||||
attribution: 'CARTO'
|
|
||||||
}).addTo(map);
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
```
|
|
||||||
|
|
||||||
This HTML file automatically generates the Torque.js library, which includes any Torque dependencies. For Torque to work with your table, you only need a username, the name of the table, and a [CartoCSS]({{site.styling_cartocss}}/) string to style the map. Leaflet's method `addTo` adds the Torque layer to the map. `play` runs the animation with the options specified in the CartoCSS properties.
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script>
|
|
||||||
var CARTOCSS = [
|
|
||||||
'Map {',
|
|
||||||
'-torque-time-attribute: "date";',
|
|
||||||
'-torque-aggregation-function: "count(cartodb_id)";',
|
|
||||||
'-torque-frame-count: 760;',
|
|
||||||
'-torque-animation-duration: 15;',
|
|
||||||
'-torque-resolution: 2',
|
|
||||||
'}',
|
|
||||||
'#layer {',
|
|
||||||
' marker-width: 3;',
|
|
||||||
' marker-fill-opacity: 0.8;',
|
|
||||||
' marker-fill: #FEE391; ',
|
|
||||||
' comp-op: "lighten";',
|
|
||||||
'}'
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
|
||||||
user : 'your_username',
|
|
||||||
table : 'your_table_name',
|
|
||||||
cartocss: CARTOCSS
|
|
||||||
});
|
|
||||||
torqueLayer.addTo(map);
|
|
||||||
torqueLayer.play()
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
You can use any kind of tile source outside CARTO, by specifying the location of a [valid TileJSON](https://github.com/mapbox/tilejson-spec) file:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
|
||||||
tileJSON: 'http://url.to/tile.json'
|
|
||||||
cartocss: CARTOCSS
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
Optionally, it is also possible to use a custom SQL query for your visualization:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
|
||||||
user : 'your_username',
|
|
||||||
table : 'your_table_name',
|
|
||||||
sql_query : 'SELECT * FROM your_table_name WHERE whatever'
|
|
||||||
cartocss: CARTOCSS
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
Like in a video player, you can use animation control methods such as `play`, `stop` and `pause` at any point. Torque's animator fires a `change:time` event each time the animation "ticks" to the next frame, and there are a number of properties and methods that can be run during playback, which are detailed in the [API reference]({{site.torque_docs}}/reference/). At any point, for example, the styling of the layer's markers can be changed using the `layer.setCartoCSS('##style##')`.
|
|
||||||
|
|
||||||
### Usage Examples
|
|
||||||
The best way to start learning about the library is by taking a look at the [examples section]({{site.torque_docs}}/examples/).
|
|
@ -1,138 +0,0 @@
|
|||||||
## Advanced Torque.js Interaction Methods
|
|
||||||
|
|
||||||
### Torque Layers
|
|
||||||
|
|
||||||
While you can add multiple layers with Torque.js, this is not recommended as it effects performance.
|
|
||||||
|
|
||||||
#### Torque Layer Source Object (_type: 'torque'_)
|
|
||||||
|
|
||||||
This layer source object is used for Torque maps. Note that it does not allow sublayers.
|
|
||||||
|
|
||||||
##### Example
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
{
|
|
||||||
type: 'torque', // Required
|
|
||||||
order: 1, // Optional
|
|
||||||
options: {
|
|
||||||
query: "SQL statement", // Required if table_name is not given
|
|
||||||
table_name: "table_name", // Required if query is not given
|
|
||||||
user_name: "your_user_name", // Required
|
|
||||||
cartocss: "CartoCSS styles" // Required
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Interaction Methods for a Torque Layer
|
|
||||||
|
|
||||||
Used to create an animated torque layer with customized settings.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// initialize a torque layer that uses the CARTO account details and SQL API to pull in data
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
|
||||||
user : 'viz2',
|
|
||||||
table : 'ow',
|
|
||||||
cartocss: CARTOCSS
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
#### getValueForPos(_x, y[, step]_)
|
|
||||||
|
|
||||||
##### Arguments
|
|
||||||
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
`getValueForPos(_x, y[, step]_)` | Allows to get the value for the coordinate (in map reference system) for a concrete step. If a step is not specified, the animation step is used. Use caution, as this method increases CPU usage
|
|
||||||
|
|
||||||
##### Returns
|
|
||||||
|
|
||||||
An object, such as a { bbox:[], value: VALUE } if there is value for the pos, otherwise, it is null.
|
|
||||||
It returns the value from the raster data, not the rendered data.
|
|
||||||
|
|
||||||
#### getValueForBBox(_xstart, ystart, xend, yend_)
|
|
||||||
|
|
||||||
##### Arguments
|
|
||||||
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
`getValueForBBox(_xstart, ystart, xend, yend_)` | An accumulated numerical value from all the torque areas, within the specified bounds
|
|
||||||
|
|
||||||
##### Returns
|
|
||||||
|
|
||||||
Returns a number.
|
|
||||||
|
|
||||||
#### getActivePointsBBox(_step_)
|
|
||||||
|
|
||||||
##### Arguments
|
|
||||||
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
`getActivePointsBBox(_step_)` | The list of bounding boxes active for `step`
|
|
||||||
|
|
||||||
##### Returns
|
|
||||||
|
|
||||||
Returns a list of values.
|
|
||||||
|
|
||||||
#### invalidate()
|
|
||||||
|
|
||||||
##### Arguments
|
|
||||||
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
`invalidate()` | Forces a reload of the layer data
|
|
||||||
|
|
||||||
**Tip:** All of these interaction methods are available for Google Map layers, with the exception of `invalidate`.
|
|
||||||
|
|
||||||
##### Example of Interaction Methods for a Torque Layer
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
<script>
|
|
||||||
// define the torque layer style using cartocss
|
|
||||||
// this creates a kind of density map
|
|
||||||
// color scale from http://colorbrewer2.org/
|
|
||||||
var CARTOCSS = [
|
|
||||||
'Map {',
|
|
||||||
'-torque-time-attribute: "date";',
|
|
||||||
'-torque-aggregation-function: "avg(temp::float)";',
|
|
||||||
'-torque-frame-count: 1;',
|
|
||||||
'-torque-animation-duration: 15;',
|
|
||||||
'-torque-resolution: 16',
|
|
||||||
'}',
|
|
||||||
'#layer {',
|
|
||||||
' marker-width: 8;',
|
|
||||||
' marker-fill-opacity: 1.0;',
|
|
||||||
' marker-fill: #fff5eb; ',
|
|
||||||
' marker-type: rectangle;',
|
|
||||||
' [value > 1] { marker-fill: #fee6ce; }',
|
|
||||||
' [value > 2] { marker-fill: #fdd0a2; }',
|
|
||||||
' [value > 4] { marker-fill: #fdae6b; }',
|
|
||||||
' [value > 10] { marker-fill: #fd8d3c; }',
|
|
||||||
' [value > 15] { marker-fill: #f16913; }',
|
|
||||||
' [value > 20] { marker-fill: #d94801; }',
|
|
||||||
' [value > 25] { marker-fill: #8c2d04; }',
|
|
||||||
'}'
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
var map = new L.Map('map', {
|
|
||||||
zoomControl: true,
|
|
||||||
center: [40, 0],
|
|
||||||
zoom: 3
|
|
||||||
});
|
|
||||||
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
|
|
||||||
attribution: 'CARTO'
|
|
||||||
}).addTo(map);
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
|
||||||
user : 'viz2',
|
|
||||||
table : 'ow',
|
|
||||||
cartocss: CARTOCSS
|
|
||||||
});
|
|
||||||
torqueLayer.addTo(map);
|
|
||||||
map.on('click', function(e) {
|
|
||||||
var p = e.containerPoint
|
|
||||||
var value = torqueLayer.getValueForPos(p.x, p.y);
|
|
||||||
if (value !== null) {
|
|
||||||
map.openPopup('average temperature: ' + value.value + "C", e.latlng);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
```
|
|
@ -1,60 +0,0 @@
|
|||||||
## Torque Time Slider
|
|
||||||
|
|
||||||
You can use the `time_slider` option to show an animated time slider with Torque layers. This option is enabled by default when creating visualizations with [cartodb.createVis]({{site.cartojs_docs}}/v3/reference/#cartodbcreatevis) and [createLayer]({{site.cartojs_docs}}/v3/reference/#cartodbcreatelayermap-layersource--options--callback). Both require a map_id DOM object.
|
|
||||||
|
|
||||||
**Enable / Disable the Torque Time Slider**
|
|
||||||
|
|
||||||
Description | The Torque time slider is enabled by default, for your visualization or layer.
|
|
||||||
Sample Torque.js Code | `{ time_slider: true });`
|
|
||||||
Default Value | `true`, enabled by default.
|
|
||||||
Available Values | See [boolean]({{site.styling_cartocss}}/#boolean).
|
|
||||||
Related Examples | To disable the time slider option, use `time_slider: false`. See [No Torque Time Slider - Example Code](http://bl.ocks.org/michellechandra/081ca7160a8c782266d2).<br/><br/>For a code example about how to use the `time_slider` option to modify a Torque map, see [Torque with a Custom Time Slider](http://bl.ocks.org/csobier/cebdd47242d7ca98ec5e).
|
|
||||||
|
|
||||||
**Note:** The `time_slider` option is specific for Torque.js only. All the other CARTO.js options are also supported for Torque.js. For the complete list of arguments, options, and returns, see [CARTO.js API Methods]({{site.cartojs_docs}}/v3/reference/#api-methods).
|
|
||||||
|
|
||||||
|
|
||||||
### Customize Animation for your Time Slider
|
|
||||||
|
|
||||||
You can customize the animation of your Torque time slider by editing the `-torque-frame-count` and `-torque-animation-duration` CartoCSS properties. (Optionally, you can create a [CARTO.js]({{site.cartojs_docs}}/v3/reference/#api-methods) map to create a custom time slider). This section also describes how time interval data is aggregated, and describes the formula used to calculate time buckets.
|
|
||||||
|
|
||||||
- [`-torque-frame-count`]({{site.styling_cartocss}}/#-torque-frame-count-number) specifies the number of animation steps/frames in your torque animation. You can change the time slider timestamp by adjusting the number of steps.<br /><br />**Tip:** In CARTO Builder, this is the STEPS value when the style is ANIMATED.
|
|
||||||
|
|
||||||
- [`-torque-animation-duration`]({{site.styling_cartocss}}/#-torque-animation-duration-number) specifies the length of time for your animation, in seconds. You can adjust the duration of the animation as needed.<br /><br />**Tip:** In CARTO Builder, this is the DURATION value when the style is ANIMATED.
|
|
||||||
|
|
||||||
#### Aggregating Time Interval Data
|
|
||||||
|
|
||||||
Before customizing the time slider, you should understand how Torque time interval data is calculated. Torque aggregates time (rather than use an exact start time and end from your column fields). Torque calculates the time interval as follows:
|
|
||||||
|
|
||||||
- Reads the first date/time stamp from your dataset
|
|
||||||
- Reads the last date/time stamp to from your dataset
|
|
||||||
- Aggregates the time period based on the first and last date/time stamp (including seconds)
|
|
||||||
- Once the time interval is defined, it breaks the time period up in smaller "buckets"
|
|
||||||
- The number of buckets is based on the number of [Steps]({{site.styling_cartocss}}/#-torque-frame-count-number) you select for your Torque map
|
|
||||||
- Each bucket, or step, is one animation frame
|
|
||||||
|
|
||||||
Thus, the start and end time for each bucket depends on the number of divided steps (not a specific start time or end time that you entered).
|
|
||||||
|
|
||||||
**Note:** If you are creating Torque maps with CARTO Builder, the date format of the Torque time slider is automatically calculated by CARTO and cannot be edited. See [Calculating the Time Slider in CARTO Builder](#calculating-the-time-slider-in-carto-builder) for more details.
|
|
||||||
|
|
||||||
#### Formula for Calculating Time Buckets
|
|
||||||
|
|
||||||
The following formula can help you calculate the number of steps for your Torque data.
|
|
||||||
|
|
||||||
`time = times.start + (times.end - times.start)*(step/total_steps);`
|
|
||||||
|
|
||||||
Where:
|
|
||||||
|
|
||||||
- `time` = time at each hop
|
|
||||||
- `times.start` = the earliest time in your date/time column
|
|
||||||
- `times.end` = the latest time in your date/time column
|
|
||||||
|
|
||||||
The Torque time slider displays these buckets of time, animating the entire sequence of your dataset, and divides the time according to the number of specified steps. You can alter the [duration]({{site.styling_cartocss}}/#-torque-animation-duration-number) of the animation, and adjust the time slider timestamp with the number of [Steps]({{site.styling_cartocss}}/#-torque-frame-count-number).
|
|
||||||
|
|
||||||
##### Calculating the Time Slider in CARTO Builder
|
|
||||||
|
|
||||||
When creating Torque maps with CARTO Builder, the date format of the Torque time slider is automatically calculated by CARTO, depending on the range of time in your dataset. It cannot be edited. If your data contains the following range of time, the time slider displays as described:
|
|
||||||
|
|
||||||
- Time range is _less than one day_, the time slider displays the _time_
|
|
||||||
- Time range is _less than three days_, the time slider displays the _day and time_
|
|
||||||
- Time range is _more than three days, but less than a year_, the time slider displays the _month/day/year_
|
|
||||||
- Time range is _more than a year_, the time slider displays the _month/year_
|
|
@ -1,69 +0,0 @@
|
|||||||
## How spatial aggregation works
|
|
||||||
|
|
||||||
When the Torque library renders points, it does not render exactly the same points you have in the database; instead it aggregates the points in clusters in order to speed up rendering and data transfer.
|
|
||||||
|
|
||||||
So imagine you have this CartoCSS:
|
|
||||||
|
|
||||||
```css
|
|
||||||
Map {
|
|
||||||
-torque-aggregation-function:"count(cartodb_id)";
|
|
||||||
-torque-resolution: 2;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This means that for the current zoom level, Torque will fetch points in clusters of 2x2 pixels. Every cluster has a value calculated by the function defined after ``-torque-aggregation-function``. In the case above, the value will be the number of points inside that cluster. That value can be accessed from CartoCSS using the variable `value`.
|
|
||||||
|
|
||||||
Every cluster is renderer as a point.
|
|
||||||
|
|
||||||
Given that you can do:
|
|
||||||
|
|
||||||
```css
|
|
||||||
#layer {
|
|
||||||
[value > 1] { marker-fill: #000; }
|
|
||||||
[value > 4] { marker-fill: #400; }
|
|
||||||
[value > 16] { marker-fill: #800; }
|
|
||||||
[value > 32] { marker-fill: #F00; }
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This would render the point with different colors depending on the number of points inside it.
|
|
||||||
|
|
||||||
## Can I use strings with Torque?
|
|
||||||
|
|
||||||
In general you can **not** do:
|
|
||||||
```css
|
|
||||||
[column = 'mytext'] { marker-fill: red; }
|
|
||||||
```
|
|
||||||
|
|
||||||
There are two reasons for this limitation:
|
|
||||||
- cluster does not contain values for all the columns, you can only use ``value`` variable
|
|
||||||
- you would need to use an aggregation function for strings
|
|
||||||
|
|
||||||
So how could I use strings column with Torque?
|
|
||||||
|
|
||||||
Imagine you have a string column (`team`) with two values, "team A" and "team B", and you want to color "team A" points to be red and "team B" to be blue, you could add a new column on the fly:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
torqueLayer.setSQL("select *, (CASE WHEN team='team A' THEN 1 ELSE 2 END) as team_n from table");
|
|
||||||
```
|
|
||||||
|
|
||||||
and then apply this CartoCSS:
|
|
||||||
|
|
||||||
```css
|
|
||||||
Map {
|
|
||||||
...
|
|
||||||
-torque-aggregation-function: "round(avg(team_n))";
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
#layer {
|
|
||||||
...
|
|
||||||
marker-fill: #FF0000;
|
|
||||||
// avg of 1 and 2
|
|
||||||
[value > 1.5] { marker-fill: #0000FF; }
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Tip:** CartoCSS is one the tools of the CARTO platform. You can learn more about the different [components of CARTO platform]({{site.fundamental_docs}}/components/), or directly dig into [CartoCSS]({{site.styling_cartocss}}/) details.
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
## Introduction
|
|
||||||
|
|
||||||
Torque.js is an efficient and stylish rendering method to animate your data.
|
|
||||||
|
|
||||||
The contents described in this document are subject to CARTO's [Terms of Service](https://carto.com/legal/)
|
|
@ -1,3 +0,0 @@
|
|||||||
## Versioning
|
|
||||||
|
|
||||||
Torque.js uses [Semantic Versioning](http://semver.org/). View our Github repository to find tags for each [release](https://github.com/CartoDB/torque/releases).
|
|
@ -1,28 +0,0 @@
|
|||||||
## L.TorqueLayer
|
|
||||||
|
|
||||||
A layer to be added to a Leaflet map. It works as a regular tiled layer within the Leaflet tile pane, but instead of containing `<img>` elements, it's composed of a single [`<canvas>`](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API) where all markers are drawn.
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
```javascript
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
|
||||||
user: 'viz2',
|
|
||||||
table: 'ow',
|
|
||||||
cartocss: '<cartocss here>'
|
|
||||||
});
|
|
||||||
|
|
||||||
map.addLayer(torqueLayer);
|
|
||||||
```
|
|
||||||
|
|
||||||
### Options
|
|
||||||
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
cartocss | A string object, the CartoCSS style for the map. Default value is ```null```
|
|
||||||
loop | A boolean object that defines the animation loop. Default value is ```true```. If ```false```, the animation is paused when it reaches the last frame
|
|
||||||
resolution | Spatial resolution in pixels. A resolution of 1 means no spatial aggregation of the data. Its value must be a power of 2
|
|
||||||
steps | Number of steps that the animation is divided into
|
|
||||||
animationDuration | Duration, in seconds, of the animation
|
|
||||||
zIndex | Z-Index CSS property of the layer
|
|
||||||
attribution | Attribution to be added in the bottom right of the map
|
|
||||||
maxZoom | Maximum zoom for the layer.
|
|
||||||
tileSize | Size, in pixels of the tiles
|
|
@ -1,6 +0,0 @@
|
|||||||
## Using a CARTO table directly
|
|
||||||
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
user | A string object, your CARTO [account name](https://carto.com/docs/carto-editor/your-account/#account). Default value is ```null```
|
|
||||||
table | A string object, the CARTO table name where data is found (also known as a dataset.) Default value is ```null```
|
|
@ -1,5 +0,0 @@
|
|||||||
## Using a custom SQL query
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
query | A string object, the SQL query to be performed to fetch the data. Default value is ```null```.<br/><br/>You must use this param or table, but not at the same time
|
|
||||||
**Tip:** For a Torque category layer that is created dynamically with `cartodb.createLayer`, the SQL query must explicitly include how to build the torque_category column. You must include both the `sql` and `table_name` parameters. See this [createLayer with torque category layer](https://gist.github.com/danicarrion/dcaf6f00a71aa55134b4) example.
|
|
@ -1,9 +0,0 @@
|
|||||||
## Providing a TileJSON file
|
|
||||||
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
tileJSON | A URL pointing to a valid [TileJSON](https://github.com/mapbox/tilejson-spec) file from which to get the Torque tile templates
|
|
||||||
|
|
||||||
Add Comment
|
|
||||||
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
|||||||
## Time Methods
|
|
||||||
|
|
||||||
Method | Options | Returns | Description |
|
|
||||||
---|---|---|---|
|
|
||||||
`setStep(step)` | `time numeric` | `this` | the value must be between 0 and the total number of `steps` in the animation
|
|
||||||
`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)
|
|
||||||
`toggle()` | | `this` | toggles (pause/play) the animation
|
|
||||||
`getStep()` | | current animation step (integer) | gets the current animation step. A step is considered an animation frame
|
|
||||||
`getTime()` | | current animation time (Date) | gets the real animation time
|
|
||||||
`isRunning()` | | `true`/`false` | describes whether the Torque layer is playing or is stopped
|
|
||||||
|
|
||||||
**Note:** Torque.js interprets the beginning and ending date/time from your "Time Column" as one block, then divides that up into [Steps]({{site.styling_cartocss}}/#-torque-frame-count-number), depending on the number you set. It does not necessarily draw one frame for each row.
|
|
@ -1,6 +0,0 @@
|
|||||||
## Layer Control Methods
|
|
||||||
|
|
||||||
Method | Options | Returns | Description
|
|
||||||
---|---|---|---
|
|
||||||
`hide()` | none | `this` | hides the Torque layer
|
|
||||||
`show()` | none| `this` | shows the Torque layer
|
|
@ -1,33 +0,0 @@
|
|||||||
## Style Methods
|
|
||||||
|
|
||||||
Method | Options | Returns | Description
|
|
||||||
---|---|---|---|
|
|
||||||
`setCartoCSS(cartocss)` | `cartocss string` | `this` | style the map rendering using client-side CartoCSS (not available with [Named maps](https://carto.com/docs/{{site.mapsapi_docs}}/guides/named-maps//maps-api/named-maps/))
|
|
||||||
|
|
||||||
Torque supports a limited subset of CartoCSS rules defined in the [torque-reference](https://github.com/cartodb/torque-reference). To see the full list of supported rules, read the [Torque CartoCSS documentation]({{site.styling_cartocss}}/#cartocss-properties-for-torque-style-maps). `value` and `zoom` variables can be used. `value` is the value of aggregation. `zoom` is the current zoom being rendered.
|
|
||||||
|
|
||||||
TorqueLayer currently expects `marker` styling.
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
```css
|
|
||||||
/* This is how a minimal example of a stylesheet for a Torque visualisation would look like. */
|
|
||||||
|
|
||||||
Map {
|
|
||||||
-torque-time-attribute: "date";
|
|
||||||
-torque-aggregation-function: "count(cartodb_id)";
|
|
||||||
-torque-frame-count: 760;
|
|
||||||
-torque-animation-duration: 15;
|
|
||||||
-torque-resolution: 2;
|
|
||||||
}
|
|
||||||
#layer {
|
|
||||||
marker-width: 3;
|
|
||||||
marker-fill-opacity: 0.8;
|
|
||||||
marker-fill: #FEE391;
|
|
||||||
}
|
|
||||||
#layer[value = 4] { // Use of the value variable, generated by the function specified in -torque-aggregation-function
|
|
||||||
marker-fill: #FABADA;
|
|
||||||
}
|
|
||||||
#layer[zoom = 12] { // Use of the zoom variable
|
|
||||||
marker-width: 10;
|
|
||||||
}
|
|
||||||
```
|
|
@ -1,12 +0,0 @@
|
|||||||
## Data Methods
|
|
||||||
|
|
||||||
Method | Options | Returns | Description
|
|
||||||
---|---|---|---
|
|
||||||
`setSQL(sql statement)` | `SQL string` | `this` | Change the SQL on the data table (not available with named maps)
|
|
||||||
`error(callback)` | `callback function with a list of errors as argument` | `this` | specifies a callback function to run if there are query errors
|
|
||||||
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
```js
|
|
||||||
// SQL Example to limit the data used in the Torque map.
|
|
||||||
torqueLayer.setSQL("SELECT * FROM table LIMIT 100");
|
|
@ -1,28 +0,0 @@
|
|||||||
## Events
|
|
||||||
|
|
||||||
Events in Torque follow the format:
|
|
||||||
|
|
||||||
```js
|
|
||||||
torqueLayer.on('event-type', function([callback_obj]) {
|
|
||||||
// do something
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
Events | Callback Object | Description
|
|
||||||
---|---|---
|
|
||||||
`change:steps` | current step | When a map changes steps, this event is triggered
|
|
||||||
`change:time` | current time, step number | When a map changes time, this event is triggered
|
|
||||||
`play` | none | Triggered when the Torque layer is played
|
|
||||||
`pause` | none | Triggered when the Torque layer is paused
|
|
||||||
`stop` | none | Triggered when the Torque layer is stopped
|
|
||||||
`load` | none | Triggered when the Torque layer is loaded
|
|
||||||
|
|
||||||
**Example:**
|
|
||||||
```js
|
|
||||||
// An event example to print the current step to the console log.
|
|
||||||
|
|
||||||
torqueLayer.on('change:steps', function(step) {
|
|
||||||
// do something with step
|
|
||||||
console.log('Current step is ' + step);
|
|
||||||
});
|
|
||||||
```
|
|
@ -1,12 +0,0 @@
|
|||||||
## Google Maps Layers
|
|
||||||
|
|
||||||
### GMapsTorqueLayer(_options_)
|
|
||||||
|
|
||||||
This class does exactly the same as ``L.TorqueLayer`` but using Google Maps instead. The main difference is that this class
|
|
||||||
is not a layer but is an overlay, so in order to add it to the a map use, ``layer.setMap`` instead of ``overlayMapTypes``. See the [Overlay View](https://developers.google.com/maps/documentation/javascript/reference#OverlayView) reference in Google Maps API doc.
|
|
||||||
|
|
||||||
#### Options
|
|
||||||
|
|
||||||
Name | Description
|
|
||||||
--- | ---
|
|
||||||
map | A google.maps.Map instance
|
|
@ -1,36 +0,0 @@
|
|||||||
## Support Options
|
|
||||||
|
|
||||||
Feeling stuck? There are many ways to find help.
|
|
||||||
|
|
||||||
* Ask a question on [GIS StackExchange](https://gis.stackexchange.com/questions/tagged/carto) using the `CARTO` tag.
|
|
||||||
* [Report an issue](https://github.com/CartoDB/torque/issues/new) in Github.
|
|
||||||
* Engine Plan customers have additional access to enterprise-level support through CARTO's support representatives.
|
|
||||||
|
|
||||||
If you just want to describe an issue or share an idea, just <a class="typeform-share" href="https://cartohq.typeform.com/to/mH6RRl" data-mode="popup" target="_blank"> send your feedback</a>
|
|
||||||
|
|
||||||
### Issues on Github
|
|
||||||
|
|
||||||
If you think you may have found a bug, or if you have a feature request that you would like to share with the Torque team, please [open an issue](https://github.com/CartoDB/torque/issues/new).
|
|
||||||
|
|
||||||
Before opening an issue, review the [contributing guidelines](https://github.com/CartoDB/torque/blob/master/CONTRIBUTING.md).
|
|
||||||
|
|
||||||
|
|
||||||
### Community support on GIS Stack Exchange
|
|
||||||
|
|
||||||
GIS Stack Exchange is the most popular community in the geospatial industry. This is a collaboratively-edited question and answer site for geospatial programmers and technicians. It is a fantastic resource for asking technical questions about developing and maintaining your application.
|
|
||||||
|
|
||||||
|
|
||||||
When posting a new question, please consider the following:
|
|
||||||
|
|
||||||
* Read the GIS Stack Exchange [help](https://gis.stackexchange.com/help) and [how to ask](https://gis.stackexchange.com/help/how-to-ask) pages for guidelines and tips about posting questions.
|
|
||||||
* Be very clear about your question in the subject. A clear explanation helps those trying to answer your question, as well as those who may be looking for information in the future.
|
|
||||||
* Be informative in your post. Details, code snippets, logs, screenshots, etc. help others to understand your problem.
|
|
||||||
* Use code that demonstrates the problem. It is very hard to debug errors without sample code to reproduce the problem.
|
|
||||||
|
|
||||||
### Engine Plan Customers
|
|
||||||
|
|
||||||
Engine Plan customers have additional support options beyond general community support. As per your account Terms of Service, you have access to enterprise-level support through CARTO's support representatives available at [enterprise-support@carto.com](mailto:enterprise-support@carto.com)
|
|
||||||
|
|
||||||
In order to speed up the resolution of your issue, provide as much information as possible (even if it is a link from community support). This allows our engineers to investigate your problem as soon as possible.
|
|
||||||
|
|
||||||
If you are not yet CARTO customer, browse our [plans & pricing](https://carto.com/pricing/) and find the right plan for you.
|
|
@ -1,36 +0,0 @@
|
|||||||
## Contribute
|
|
||||||
|
|
||||||
CARTO platform is an open-source ecosystem. You can read about the [fundamentals]({{site.fundamental_docs}}/components/) of CARTO architecture and its components.
|
|
||||||
We are more than happy to receive your contributions to the code and the documentation as well.
|
|
||||||
|
|
||||||
## Filling a ticket
|
|
||||||
|
|
||||||
If you want to open a new issue in our repository, please follow these instructions:
|
|
||||||
|
|
||||||
1. Descriptive title.
|
|
||||||
2. Write a good description, it always helps.
|
|
||||||
3. Specify the steps to reproduce the problem.
|
|
||||||
4. Try to add an example showing the problem.
|
|
||||||
|
|
||||||
## Contributing code
|
|
||||||
|
|
||||||
Best part of open source, collaborate in Torque.js code!. We like hearing from you, so if you have any bug fixed, or a new feature ready to be merged, those are the steps you should follow:
|
|
||||||
|
|
||||||
1. Fork the repository.
|
|
||||||
2. Create a new branch in your forked repository.
|
|
||||||
3. Commit your changes. Add new tests if it is necessary.
|
|
||||||
4. Open a pull request.
|
|
||||||
5. Any of the maintainers will take a look.
|
|
||||||
6. If everything works, it will merged and released \o/.
|
|
||||||
|
|
||||||
If you want more detailed information, this [GitHub guide](https://guides.github.com/activities/contributing-to-open-source/) is a must.
|
|
||||||
|
|
||||||
## Completing documentation
|
|
||||||
|
|
||||||
Torque.js documentation is located in ```docs/```. That folder is the content that appears in the [Developer Center](http://carto.com/developers/torque-js/). Just follow the instructions described in [contributing code](#contributing-code) and after accepting your pull request, we will make it appear online :).
|
|
||||||
|
|
||||||
**Tip:** A convenient, easy way of proposing changes in documentation is by using the GitHub editor directly on the web. You can easily create a branch with your changes and make a PR from there.
|
|
||||||
|
|
||||||
## Submitting contributions
|
|
||||||
|
|
||||||
You will need to sign a Contributor License Agreement (CLA) before making a submission. [Learn more here](https://carto.com/contributions).
|
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
<html>
|
<html>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" />
|
<link rel="stylesheet" href="vendor/leaflet.css" />
|
||||||
<style>
|
<style>
|
||||||
#map, html, body {
|
#map, html, body {
|
||||||
width: 100%; height: 100%; padding: 0; margin: 0;
|
width: 100%; height: 100%; padding: 0; margin: 0;
|
||||||
@ -9,8 +9,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
|
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
|
||||||
<script src="https://libs.cartocdn.com/torque.js/2.16.5/torque.full.js"></script>
|
<script src="../dist/torque.full.uncompressed.js"></script>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -55,8 +55,7 @@
|
|||||||
steps: 1024,
|
steps: 1024,
|
||||||
blendmode : 'lighter',
|
blendmode : 'lighter',
|
||||||
animationDuration: 20,
|
animationDuration: 20,
|
||||||
map: map,
|
map: map
|
||||||
tiler_protocol: 'https'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var DEFAULT_CARTOCSS = [
|
var DEFAULT_CARTOCSS = [
|
@ -1,5 +1,5 @@
|
|||||||
<html>
|
<html>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" />
|
<link rel="stylesheet" href="vendor/leaflet.css" />
|
||||||
<style>
|
<style>
|
||||||
#map, html, body {
|
#map, html, body {
|
||||||
width: 100%; height: 100%; padding: 0; margin: 0;
|
width: 100%; height: 100%; padding: 0; margin: 0;
|
||||||
@ -8,8 +8,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script>
|
<script src="vendor/leaflet.js"></script>
|
||||||
<script src="https://libs.cartocdn.com/torque.js/2.16.5/torque.full.js"></script>
|
<script src="../dist/torque.full.uncompressed.js"></script>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -24,7 +24,7 @@
|
|||||||
'}',
|
'}',
|
||||||
'#layer {',
|
'#layer {',
|
||||||
'image-filters: colorize-alpha(blue, cyan, lightgreen, yellow , orange, red);',
|
'image-filters: colorize-alpha(blue, cyan, lightgreen, yellow , orange, red);',
|
||||||
'marker-file: url(https://s3.amazonaws.com/com.cartodb.assets.static/alphamarker.png);',
|
'marker-file: url(http://s3.amazonaws.com/com.cartodb.assets.static/alphamarker.png);',
|
||||||
'marker-fill-opacity: 0.4;',
|
'marker-fill-opacity: 0.4;',
|
||||||
'marker-width: 35;',
|
'marker-width: 35;',
|
||||||
'}'
|
'}'
|
||||||
@ -37,21 +37,17 @@
|
|||||||
zoom: 3
|
zoom: 3
|
||||||
});
|
});
|
||||||
|
|
||||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
|
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
|
||||||
attribution: 'CartoDB'
|
attribution: 'CartoDB'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
var torqueLayer = new L.TorqueLayer({
|
||||||
user : 'fdansv',
|
user : 'fdansv',
|
||||||
table : 'snow',
|
table : 'snow',
|
||||||
cartocss: CARTOCSS,
|
cartocss: CARTOCSS
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443,
|
|
||||||
zIndex: 10
|
|
||||||
});
|
});
|
||||||
torqueLayer.addTo(map);
|
torqueLayer.addTo(map);
|
||||||
torqueLayer.play();
|
torqueLayer.play();
|
||||||
torqueLayer.bringToFront();
|
|
||||||
var rect = document.createElement("div");
|
var rect = document.createElement("div");
|
||||||
var size = 50;
|
var size = 50;
|
||||||
rect.setAttribute('style', "position:absolute; background-color: #fff; width: 100px; height: 30px;");
|
rect.setAttribute('style', "position:absolute; background-color: #fff; width: 100px; height: 30px;");
|
@ -4,7 +4,7 @@
|
|||||||
<title>Heat map simple | CartoDB.js</title>
|
<title>Heat map simple | CartoDB.js</title>
|
||||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||||
<link rel="shortcut icon" href="https://cartodb.com/assets/favicon.ico" />
|
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html, body, #map {
|
html, body, #map {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -12,7 +12,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="https://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
||||||
<!--[if lte IE 8]>
|
<!--[if lte IE 8]>
|
||||||
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
@ -95,7 +95,7 @@
|
|||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<!-- include cartodb.js library -->
|
<!-- include cartodb.js library -->
|
||||||
<script src="https://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function main() {
|
function main() {
|
||||||
@ -105,7 +105,7 @@
|
|||||||
zoom: 14
|
zoom: 14
|
||||||
});
|
});
|
||||||
|
|
||||||
var layer = L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',{
|
var layer = L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',{
|
||||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
@ -118,10 +118,6 @@
|
|||||||
user_name: "andrew",
|
user_name: "andrew",
|
||||||
tile_style: $('#cartocss_template').html()
|
tile_style: $('#cartocss_template').html()
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
https: true,
|
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443
|
|
||||||
}).done(function(layer) {
|
}).done(function(layer) {
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
});
|
});
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
<html>
|
<html>
|
||||||
|
<link rel="stylesheet" href="vendor/leaflet.css" />
|
||||||
<style>
|
<style>
|
||||||
#map, html, body {
|
#map, html, body {
|
||||||
width: 100%; height: 100%; padding: 0; margin: 0;
|
width: 100%; height: 100%; padding: 0; margin: 0;
|
||||||
@ -17,8 +18,8 @@
|
|||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
<div id="title">Average temperature collected by Britain's Royal Navy (1913-1925)</div>
|
<div id="title">Average temperature collected by Britain's Royal Navy (1913-1925)</div>
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" />
|
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script>
|
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
|
||||||
<script src="../dist/torque.full.uncompressed.js"></script>
|
<script src="../dist/torque.full.uncompressed.js"></script>
|
||||||
|
|
||||||
|
|
||||||
@ -56,17 +57,14 @@
|
|||||||
zoom: 3
|
zoom: 3
|
||||||
});
|
});
|
||||||
|
|
||||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
|
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
|
||||||
attribution: 'CartoDB'
|
attribution: 'CartoDB'
|
||||||
}).addTo(map, true);
|
}).addTo(map);
|
||||||
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
var torqueLayer = new L.TorqueLayer({
|
||||||
user : 'viz2',
|
user : 'viz2',
|
||||||
table : 'ow',
|
table : 'ow',
|
||||||
cartocss: CARTOCSS,
|
cartocss: CARTOCSS
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443,
|
|
||||||
zIndex: 10
|
|
||||||
});
|
});
|
||||||
torqueLayer.addTo(map);
|
torqueLayer.addTo(map);
|
||||||
|
|
@ -4,7 +4,7 @@
|
|||||||
<title>Light bright effect | CartoDB.js</title>
|
<title>Light bright effect | CartoDB.js</title>
|
||||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||||
<link rel="shortcut icon" href="https://cartodb.com/assets/favicon.ico" />
|
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html, body, #map {
|
html, body, #map {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -12,7 +12,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="https://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
||||||
<!--[if lte IE 8]>
|
<!--[if lte IE 8]>
|
||||||
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
@ -60,7 +60,7 @@
|
|||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<!-- include cartodb.js library -->
|
<!-- include cartodb.js library -->
|
||||||
<script src="https://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function main() {
|
function main() {
|
||||||
@ -69,7 +69,7 @@
|
|||||||
center: [-6.964483, 107.634506],
|
center: [-6.964483, 107.634506],
|
||||||
zoom: 7
|
zoom: 7
|
||||||
});
|
});
|
||||||
var layer = L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',{
|
var layer = L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',{
|
||||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
@ -81,10 +81,6 @@
|
|||||||
user_name: "andrew",
|
user_name: "andrew",
|
||||||
tile_style: $('#cartocss_template').html()
|
tile_style: $('#cartocss_template').html()
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
https: true,
|
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443
|
|
||||||
}).done(function(layer) {
|
}).done(function(layer) {
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
});
|
});
|
@ -8,8 +8,8 @@
|
|||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
|
|
||||||
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
|
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
|
||||||
<script src="https://libs.cartocdn.com/torque.js/2.16.5/torque.full.js" type="application/javascript" charset="utf-8"></script>
|
<script src="../dist/torque.full.uncompressed.js"></script>
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -75,8 +75,7 @@
|
|||||||
user : 'viz2',
|
user : 'viz2',
|
||||||
table : 'ow',
|
table : 'ow',
|
||||||
cartocss: CARTOCSS,
|
cartocss: CARTOCSS,
|
||||||
tiler_protocol: 'https',
|
map: map
|
||||||
tiler_port: 443
|
|
||||||
});
|
});
|
||||||
torqueLayer.error(function(err){
|
torqueLayer.error(function(err){
|
||||||
for(error in err){
|
for(error in err){
|
@ -1,4 +1,5 @@
|
|||||||
<html>
|
<html>
|
||||||
|
<link rel="stylesheet" href="vendor/leaflet.css" />
|
||||||
<style>
|
<style>
|
||||||
#map, html, body {
|
#map, html, body {
|
||||||
width: 100%; height: 100%; padding: 0; margin: 0;
|
width: 100%; height: 100%; padding: 0; margin: 0;
|
||||||
@ -7,9 +8,8 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" />
|
<script src="vendor/leaflet.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script>
|
<script src="../dist/torque.full.uncompressed.js"></script>
|
||||||
<script src="https://libs.cartocdn.com/torque.js/2.16.5/torque.full.js" type="application/javascript" charset="utf-8"></script>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -45,17 +45,14 @@
|
|||||||
zoom: 3
|
zoom: 3
|
||||||
});
|
});
|
||||||
|
|
||||||
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
|
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
|
||||||
attribution: 'CartoDB'
|
attribution: 'CartoDB'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
var torqueLayer = new L.TorqueLayer({
|
var torqueLayer = new L.TorqueLayer({
|
||||||
user : 'viz2',
|
user : 'viz2',
|
||||||
table : 'ow',
|
table : 'ow',
|
||||||
zIndex: 100,
|
cartocss: CARTOCSS
|
||||||
cartocss: CARTOCSS,
|
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443
|
|
||||||
});
|
});
|
||||||
torqueLayer.error(function(err){
|
torqueLayer.error(function(err){
|
||||||
for(error in err){
|
for(error in err){
|
@ -4,7 +4,7 @@
|
|||||||
<title>Static bubble map | CartoDB.js</title>
|
<title>Static bubble map | CartoDB.js</title>
|
||||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||||
<link rel="shortcut icon" href="https://cartodb.com/assets/favicon.ico" />
|
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html, body, #map {
|
html, body, #map {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -12,7 +12,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="https://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
||||||
<!--[if lte IE 8]>
|
<!--[if lte IE 8]>
|
||||||
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
@ -57,7 +57,7 @@
|
|||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<!-- include cartodb.js library -->
|
<!-- include cartodb.js library -->
|
||||||
<script src="https://libs.cartocdn.com/cartodb.js/v3/cartodb.uncompressed.js"></script>
|
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function main() {
|
function main() {
|
||||||
@ -66,7 +66,7 @@
|
|||||||
center: [39.9304, 116.423239],
|
center: [39.9304, 116.423239],
|
||||||
zoom: 8
|
zoom: 8
|
||||||
});
|
});
|
||||||
var layer = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',{
|
var layer = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',{
|
||||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
@ -78,10 +78,6 @@
|
|||||||
user_name: "andrew",
|
user_name: "andrew",
|
||||||
tile_style: $('#cartocss_template').html()
|
tile_style: $('#cartocss_template').html()
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
https: true,
|
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443
|
|
||||||
}).done(function(layer) {
|
}).done(function(layer) {
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
});
|
});
|
@ -4,7 +4,7 @@
|
|||||||
<title>Torque heatmap | CartoDB.js</title>
|
<title>Torque heatmap | CartoDB.js</title>
|
||||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||||
<link rel="shortcut icon" href="https://cartodb.com/assets/favicon.ico" />
|
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html, body, #map {
|
html, body, #map {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -12,7 +12,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="https://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
||||||
<!--[if lte IE 8]>
|
<!--[if lte IE 8]>
|
||||||
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
@ -54,7 +54,7 @@
|
|||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<!-- include cartodb.js library -->
|
<!-- include cartodb.js library -->
|
||||||
<script src="https://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function main() {
|
function main() {
|
||||||
@ -64,7 +64,7 @@
|
|||||||
zoom: 7
|
zoom: 7
|
||||||
});
|
});
|
||||||
|
|
||||||
var layer = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',{
|
var layer = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',{
|
||||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
@ -77,10 +77,6 @@
|
|||||||
user_name: "andrew",
|
user_name: "andrew",
|
||||||
tile_style: $('#cartocss_template').html()
|
tile_style: $('#cartocss_template').html()
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
https: true,
|
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443
|
|
||||||
}).done(function(layer) {
|
}).done(function(layer) {
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
});
|
});
|
@ -4,7 +4,7 @@
|
|||||||
<title>Heat map simple | CartoDB.js</title>
|
<title>Heat map simple | CartoDB.js</title>
|
||||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||||
<link rel="shortcut icon" href="https://cartodb.com/assets/favicon.ico" />
|
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
|
||||||
<style>
|
<style>
|
||||||
html, body, #map {
|
html, body, #map {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -12,7 +12,7 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" href="https://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
|
||||||
<!--[if lte IE 8]>
|
<!--[if lte IE 8]>
|
||||||
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
@ -41,7 +41,7 @@
|
|||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<!-- include cartodb.js library -->
|
<!-- include cartodb.js library -->
|
||||||
<script src="https://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function main() {
|
function main() {
|
||||||
@ -51,7 +51,7 @@
|
|||||||
zoom: 7
|
zoom: 7
|
||||||
});
|
});
|
||||||
|
|
||||||
var layer = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',{
|
var layer = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',{
|
||||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
@ -64,10 +64,6 @@
|
|||||||
user_name: "andrew",
|
user_name: "andrew",
|
||||||
tile_style: $('#cartocss_template').html()
|
tile_style: $('#cartocss_template').html()
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
https: true,
|
|
||||||
tiler_protocol: 'https',
|
|
||||||
tiler_port: 443
|
|
||||||
}).done(function(layer) {
|
}).done(function(layer) {
|
||||||
map.addLayer(layer);
|
map.addLayer(layer);
|
||||||
});
|
});
|
112
examples/text_render_example.html
Normal file
112
examples/text_render_example.html
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
|
||||||
|
<html>
|
||||||
|
<link rel="stylesheet" href="vendor/leaflet.css" />
|
||||||
|
<style>
|
||||||
|
#map, html, body {
|
||||||
|
width: 100%; height: 100%; padding: 0; margin: 0;
|
||||||
|
}
|
||||||
|
#title {
|
||||||
|
position: absolute;
|
||||||
|
top: 100px;
|
||||||
|
left: 50px;
|
||||||
|
color: white;
|
||||||
|
font-size: 27px;
|
||||||
|
font-family: Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<div id="map"></div>
|
||||||
|
<div id="title">Average temperature collected by Britain's Royal Navy (1913-1925)</div>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
|
||||||
|
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
|
||||||
|
<script src="../dist/torque.full.uncompressed.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// define the torque layer style using cartocss
|
||||||
|
// this creates a kind of density map
|
||||||
|
//color scale from http://colorbrewer2.org/
|
||||||
|
var CARTOCSS = [
|
||||||
|
'Map {',
|
||||||
|
'-torque-time-attribute: "date";',
|
||||||
|
'-torque-aggregation-function: "avg(temp::float)";',
|
||||||
|
'-torque-frame-count: 1;',
|
||||||
|
'-torque-animation-duration: 15;',
|
||||||
|
'-torque-resolution: 32',
|
||||||
|
|
||||||
|
'}',
|
||||||
|
'#layer {',
|
||||||
|
' marker-width: 16;',
|
||||||
|
' marker-fill-opacity: 1.0;',
|
||||||
|
' marker-fill: #fff5eb; ',
|
||||||
|
' marker-type: rectangle;',
|
||||||
|
'text-name: "{{value}}c";',
|
||||||
|
'text-face-name: "Arial";',
|
||||||
|
'text-fill: #036;',
|
||||||
|
'text-size: 100px;',
|
||||||
|
' [value > 1] { marker-fill: #fee6ce; }',
|
||||||
|
' [value > 2] { marker-fill: #fdd0a2; }',
|
||||||
|
' [value > 4] { marker-fill: #fdae6b; }',
|
||||||
|
' [value > 10] { marker-fill: #fd8d3c; }',
|
||||||
|
' [value > 15] { marker-fill: #f16913; }',
|
||||||
|
' [value > 20] { marker-fill: #d94801; }',
|
||||||
|
' [value > 25] { marker-fill: #8c2d04; }',
|
||||||
|
|
||||||
|
'}'
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
|
||||||
|
var map = new L.Map('map', {
|
||||||
|
zoomControl: true,
|
||||||
|
center: [40, 0],
|
||||||
|
zoom: 3
|
||||||
|
});
|
||||||
|
|
||||||
|
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
|
||||||
|
attribution: 'CartoDB'
|
||||||
|
}).addTo(map);
|
||||||
|
|
||||||
|
var torqueLayer = new L.TorqueLayer({
|
||||||
|
user : 'viz2',
|
||||||
|
table : 'ow',
|
||||||
|
cartocss: CARTOCSS
|
||||||
|
});
|
||||||
|
torqueLayer.addTo(map);
|
||||||
|
|
||||||
|
map.on('click', function(e) {
|
||||||
|
var p = e.containerPoint
|
||||||
|
var value = torqueLayer.getValueForPos(p.x, p.y);
|
||||||
|
if (value !== null) {
|
||||||
|
map.openPopup('average temperature: ' + value.value + "C", e.latlng);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// show small rectable and change cursor on hover
|
||||||
|
var hover = null;
|
||||||
|
map.on('mousemove', function(e) {
|
||||||
|
var p = e.containerPoint
|
||||||
|
var value = torqueLayer.getValueForPos(p.x, p.y);
|
||||||
|
|
||||||
|
// remove previous hover box
|
||||||
|
if (hover) {
|
||||||
|
map.removeLayer(hover);
|
||||||
|
hover = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value !== null) {
|
||||||
|
hover = L.rectangle(value.bbox, {
|
||||||
|
color: '#000',
|
||||||
|
weight: 1
|
||||||
|
}).addTo(map);
|
||||||
|
map._container.style.cursor = 'pointer';
|
||||||
|
} else {
|
||||||
|
map._container.style.cursor = 'auto';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
7323
examples/vendor/carto.js
vendored
Normal file
7323
examples/vendor/carto.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
263
examples/vendor/codemirror.css
vendored
Normal file
263
examples/vendor/codemirror.css
vendored
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
/* BASICS */
|
||||||
|
|
||||||
|
.CodeMirror {
|
||||||
|
/* Set height, width, borders, and global font properties here */
|
||||||
|
font-family: monospace;
|
||||||
|
height: 300px;
|
||||||
|
}
|
||||||
|
.CodeMirror-scroll {
|
||||||
|
/* Set scrolling behaviour here */
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PADDING */
|
||||||
|
|
||||||
|
.CodeMirror-lines {
|
||||||
|
padding: 4px 0; /* Vertical padding around content */
|
||||||
|
}
|
||||||
|
.CodeMirror pre {
|
||||||
|
padding: 0 4px; /* Horizontal padding of content */
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
||||||
|
background-color: white; /* The little square between H and V scrollbars */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GUTTER */
|
||||||
|
|
||||||
|
.CodeMirror-gutters {
|
||||||
|
border-right: 1px solid #ddd;
|
||||||
|
background-color: #f7f7f7;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.CodeMirror-linenumbers {}
|
||||||
|
.CodeMirror-linenumber {
|
||||||
|
padding: 0 3px 0 5px;
|
||||||
|
min-width: 20px;
|
||||||
|
text-align: right;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CURSOR */
|
||||||
|
|
||||||
|
.CodeMirror div.CodeMirror-cursor {
|
||||||
|
border-left: 1px solid black;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
/* Shown when moving in bi-directional text */
|
||||||
|
.CodeMirror div.CodeMirror-secondarycursor {
|
||||||
|
border-left: 1px solid silver;
|
||||||
|
}
|
||||||
|
.CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor {
|
||||||
|
width: auto;
|
||||||
|
border: 0;
|
||||||
|
background: #7e7;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
/* Can style cursor different in overwrite (non-insert) mode */
|
||||||
|
.CodeMirror div.CodeMirror-cursor.CodeMirror-overwrite {}
|
||||||
|
|
||||||
|
.cm-tab { display: inline-block; }
|
||||||
|
|
||||||
|
/* DEFAULT THEME */
|
||||||
|
|
||||||
|
.cm-s-default .cm-keyword {color: #708;}
|
||||||
|
.cm-s-default .cm-atom {color: #219;}
|
||||||
|
.cm-s-default .cm-number {color: #164;}
|
||||||
|
.cm-s-default .cm-def {color: #00f;}
|
||||||
|
.cm-s-default .cm-variable {color: black;}
|
||||||
|
.cm-s-default .cm-variable-2 {color: #05a;}
|
||||||
|
.cm-s-default .cm-variable-3 {color: #085;}
|
||||||
|
.cm-s-default .cm-property {color: black;}
|
||||||
|
.cm-s-default .cm-operator {color: black;}
|
||||||
|
.cm-s-default .cm-comment {color: #a50;}
|
||||||
|
.cm-s-default .cm-string {color: #a11;}
|
||||||
|
.cm-s-default .cm-string-2 {color: #f50;}
|
||||||
|
.cm-s-default .cm-meta {color: #555;}
|
||||||
|
.cm-s-default .cm-error {color: #f00;}
|
||||||
|
.cm-s-default .cm-qualifier {color: #555;}
|
||||||
|
.cm-s-default .cm-builtin {color: #30a;}
|
||||||
|
.cm-s-default .cm-bracket {color: #997;}
|
||||||
|
.cm-s-default .cm-tag {color: #170;}
|
||||||
|
.cm-s-default .cm-attribute {color: #00c;}
|
||||||
|
.cm-s-default .cm-header {color: blue;}
|
||||||
|
.cm-s-default .cm-quote {color: #090;}
|
||||||
|
.cm-s-default .cm-hr {color: #999;}
|
||||||
|
.cm-s-default .cm-link {color: #00c;}
|
||||||
|
|
||||||
|
.cm-negative {color: #d44;}
|
||||||
|
.cm-positive {color: #292;}
|
||||||
|
.cm-header, .cm-strong {font-weight: bold;}
|
||||||
|
.cm-em {font-style: italic;}
|
||||||
|
.cm-link {text-decoration: underline;}
|
||||||
|
|
||||||
|
.cm-invalidchar {color: #f00;}
|
||||||
|
|
||||||
|
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
|
||||||
|
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
|
||||||
|
.CodeMirror-activeline-background {background: #e8f2ff;}
|
||||||
|
|
||||||
|
/* STOP */
|
||||||
|
|
||||||
|
/* The rest of this file contains styles related to the mechanics of
|
||||||
|
the editor. You probably shouldn't touch them. */
|
||||||
|
|
||||||
|
.CodeMirror {
|
||||||
|
line-height: 1;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
background: white;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-scroll {
|
||||||
|
/* 30px is the magic margin used to hide the element's real scrollbars */
|
||||||
|
/* See overflow: hidden in .CodeMirror */
|
||||||
|
margin-bottom: -30px; margin-right: -30px;
|
||||||
|
padding-bottom: 30px; padding-right: 30px;
|
||||||
|
height: 100%;
|
||||||
|
outline: none; /* Prevent dragging from highlighting the element */
|
||||||
|
position: relative;
|
||||||
|
-moz-box-sizing: content-box;
|
||||||
|
box-sizing: content-box;
|
||||||
|
}
|
||||||
|
.CodeMirror-sizer {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The fake, visible scrollbars. Used to force redraw during scrolling
|
||||||
|
before actuall scrolling happens, thus preventing shaking and
|
||||||
|
flickering artifacts. */
|
||||||
|
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 6;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.CodeMirror-vscrollbar {
|
||||||
|
right: 0; top: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
.CodeMirror-hscrollbar {
|
||||||
|
bottom: 0; left: 0;
|
||||||
|
overflow-y: hidden;
|
||||||
|
overflow-x: scroll;
|
||||||
|
}
|
||||||
|
.CodeMirror-scrollbar-filler {
|
||||||
|
right: 0; bottom: 0;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter-filler {
|
||||||
|
left: 0; bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-gutters {
|
||||||
|
position: absolute; left: 0; top: 0;
|
||||||
|
padding-bottom: 30px;
|
||||||
|
z-index: 3;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter {
|
||||||
|
white-space: normal;
|
||||||
|
height: 100%;
|
||||||
|
-moz-box-sizing: content-box;
|
||||||
|
box-sizing: content-box;
|
||||||
|
padding-bottom: 30px;
|
||||||
|
margin-bottom: -32px;
|
||||||
|
display: inline-block;
|
||||||
|
/* Hack to make IE7 behave */
|
||||||
|
*zoom:1;
|
||||||
|
*display:inline;
|
||||||
|
}
|
||||||
|
.CodeMirror-gutter-elt {
|
||||||
|
position: absolute;
|
||||||
|
cursor: default;
|
||||||
|
z-index: 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-lines {
|
||||||
|
cursor: text;
|
||||||
|
}
|
||||||
|
.CodeMirror pre {
|
||||||
|
/* Reset some styles that the rest of the page might have set */
|
||||||
|
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
|
||||||
|
border-width: 0;
|
||||||
|
background: transparent;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: inherit;
|
||||||
|
margin: 0;
|
||||||
|
white-space: pre;
|
||||||
|
word-wrap: normal;
|
||||||
|
line-height: inherit;
|
||||||
|
color: inherit;
|
||||||
|
z-index: 2;
|
||||||
|
position: relative;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
.CodeMirror-wrap pre {
|
||||||
|
word-wrap: break-word;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: normal;
|
||||||
|
}
|
||||||
|
.CodeMirror-code pre {
|
||||||
|
border-right: 30px solid transparent;
|
||||||
|
width: -webkit-fit-content;
|
||||||
|
width: -moz-fit-content;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
.CodeMirror-wrap .CodeMirror-code pre {
|
||||||
|
border-right: none;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
.CodeMirror-linebackground {
|
||||||
|
position: absolute;
|
||||||
|
left: 0; right: 0; top: 0; bottom: 0;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-linewidget {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-widget {}
|
||||||
|
|
||||||
|
.CodeMirror-wrap .CodeMirror-scroll {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-measure {
|
||||||
|
position: absolute;
|
||||||
|
width: 100%;
|
||||||
|
height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
.CodeMirror-measure pre { position: static; }
|
||||||
|
|
||||||
|
.CodeMirror div.CodeMirror-cursor {
|
||||||
|
position: absolute;
|
||||||
|
visibility: hidden;
|
||||||
|
border-right: none;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
.CodeMirror-focused div.CodeMirror-cursor {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CodeMirror-selected { background: #d9d9d9; }
|
||||||
|
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
||||||
|
|
||||||
|
.cm-searching {
|
||||||
|
background: #ffa;
|
||||||
|
background: rgba(255, 255, 0, .4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IE7 hack to prevent it from returning funny offsetTops on the spans */
|
||||||
|
.CodeMirror span { *vertical-align: text-bottom; }
|
||||||
|
|
||||||
|
@media print {
|
||||||
|
/* Hide the cursor when printing */
|
||||||
|
.CodeMirror div.CodeMirror-cursor {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
}
|
5887
examples/vendor/codemirror.js
vendored
Normal file
5887
examples/vendor/codemirror.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
639
examples/vendor/css.js
vendored
Normal file
639
examples/vendor/css.js
vendored
Normal file
@ -0,0 +1,639 @@
|
|||||||
|
CodeMirror.defineMode("css", function(config, parserConfig) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
|
||||||
|
|
||||||
|
var indentUnit = config.indentUnit || config.tabSize || 2,
|
||||||
|
hooks = parserConfig.hooks || {},
|
||||||
|
atMediaTypes = parserConfig.atMediaTypes || {},
|
||||||
|
atMediaFeatures = parserConfig.atMediaFeatures || {},
|
||||||
|
propertyKeywords = parserConfig.propertyKeywords || {},
|
||||||
|
colorKeywords = parserConfig.colorKeywords || {},
|
||||||
|
valueKeywords = parserConfig.valueKeywords || {},
|
||||||
|
allowNested = !!parserConfig.allowNested,
|
||||||
|
type = null;
|
||||||
|
|
||||||
|
function ret(style, tp) { type = tp; return style; }
|
||||||
|
|
||||||
|
function tokenBase(stream, state) {
|
||||||
|
var ch = stream.next();
|
||||||
|
if (hooks[ch]) {
|
||||||
|
// result[0] is style and result[1] is type
|
||||||
|
var result = hooks[ch](stream, state);
|
||||||
|
if (result !== false) return result;
|
||||||
|
}
|
||||||
|
if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("def", stream.current());}
|
||||||
|
else if (ch == "=") ret(null, "compare");
|
||||||
|
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
|
||||||
|
else if (ch == "\"" || ch == "'") {
|
||||||
|
state.tokenize = tokenString(ch);
|
||||||
|
return state.tokenize(stream, state);
|
||||||
|
}
|
||||||
|
else if (ch == "#") {
|
||||||
|
stream.eatWhile(/[\w\\\-]/);
|
||||||
|
return ret("atom", "hash");
|
||||||
|
}
|
||||||
|
else if (ch == "!") {
|
||||||
|
stream.match(/^\s*\w*/);
|
||||||
|
return ret("keyword", "important");
|
||||||
|
}
|
||||||
|
else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
|
||||||
|
stream.eatWhile(/[\w.%]/);
|
||||||
|
return ret("number", "unit");
|
||||||
|
}
|
||||||
|
else if (ch === "-") {
|
||||||
|
if (/\d/.test(stream.peek())) {
|
||||||
|
stream.eatWhile(/[\w.%]/);
|
||||||
|
return ret("number", "unit");
|
||||||
|
} else if (stream.match(/^[^-]+-/)) {
|
||||||
|
return ret("meta", "meta");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (/[,+>*\/]/.test(ch)) {
|
||||||
|
return ret(null, "select-op");
|
||||||
|
}
|
||||||
|
else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
|
||||||
|
return ret("qualifier", "qualifier");
|
||||||
|
}
|
||||||
|
else if (ch == ":") {
|
||||||
|
return ret("operator", ch);
|
||||||
|
}
|
||||||
|
else if (/[;{}\[\]\(\)]/.test(ch)) {
|
||||||
|
return ret(null, ch);
|
||||||
|
}
|
||||||
|
else if (ch == "u" && stream.match("rl(")) {
|
||||||
|
stream.backUp(1);
|
||||||
|
state.tokenize = tokenParenthesized;
|
||||||
|
return ret("property", "variable");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
stream.eatWhile(/[\w\\\-]/);
|
||||||
|
return ret("property", "variable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function tokenString(quote, nonInclusive) {
|
||||||
|
return function(stream, state) {
|
||||||
|
var escaped = false, ch;
|
||||||
|
while ((ch = stream.next()) != null) {
|
||||||
|
if (ch == quote && !escaped)
|
||||||
|
break;
|
||||||
|
escaped = !escaped && ch == "\\";
|
||||||
|
}
|
||||||
|
if (!escaped) {
|
||||||
|
if (nonInclusive) stream.backUp(1);
|
||||||
|
state.tokenize = tokenBase;
|
||||||
|
}
|
||||||
|
return ret("string", "string");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function tokenParenthesized(stream, state) {
|
||||||
|
stream.next(); // Must be '('
|
||||||
|
if (!stream.match(/\s*[\"\']/, false))
|
||||||
|
state.tokenize = tokenString(")", true);
|
||||||
|
else
|
||||||
|
state.tokenize = tokenBase;
|
||||||
|
return ret(null, "(");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
startState: function(base) {
|
||||||
|
return {tokenize: tokenBase,
|
||||||
|
baseIndent: base || 0,
|
||||||
|
stack: [],
|
||||||
|
lastToken: null};
|
||||||
|
},
|
||||||
|
|
||||||
|
token: function(stream, state) {
|
||||||
|
|
||||||
|
// Use these terms when applicable (see http://www.xanthir.com/blog/b4E50)
|
||||||
|
//
|
||||||
|
// rule** or **ruleset:
|
||||||
|
// A selector + braces combo, or an at-rule.
|
||||||
|
//
|
||||||
|
// declaration block:
|
||||||
|
// A sequence of declarations.
|
||||||
|
//
|
||||||
|
// declaration:
|
||||||
|
// A property + colon + value combo.
|
||||||
|
//
|
||||||
|
// property value:
|
||||||
|
// The entire value of a property.
|
||||||
|
//
|
||||||
|
// component value:
|
||||||
|
// A single piece of a property value. Like the 5px in
|
||||||
|
// text-shadow: 0 0 5px blue;. Can also refer to things that are
|
||||||
|
// multiple terms, like the 1-4 terms that make up the background-size
|
||||||
|
// portion of the background shorthand.
|
||||||
|
//
|
||||||
|
// term:
|
||||||
|
// The basic unit of author-facing CSS, like a single number (5),
|
||||||
|
// dimension (5px), string ("foo"), or function. Officially defined
|
||||||
|
// by the CSS 2.1 grammar (look for the 'term' production)
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// simple selector:
|
||||||
|
// A single atomic selector, like a type selector, an attr selector, a
|
||||||
|
// class selector, etc.
|
||||||
|
//
|
||||||
|
// compound selector:
|
||||||
|
// One or more simple selectors without a combinator. div.example is
|
||||||
|
// compound, div > .example is not.
|
||||||
|
//
|
||||||
|
// complex selector:
|
||||||
|
// One or more compound selectors chained with combinators.
|
||||||
|
//
|
||||||
|
// combinator:
|
||||||
|
// The parts of selectors that express relationships. There are four
|
||||||
|
// currently - the space (descendant combinator), the greater-than
|
||||||
|
// bracket (child combinator), the plus sign (next sibling combinator),
|
||||||
|
// and the tilda (following sibling combinator).
|
||||||
|
//
|
||||||
|
// sequence of selectors:
|
||||||
|
// One or more of the named type of selector chained with commas.
|
||||||
|
|
||||||
|
state.tokenize = state.tokenize || tokenBase;
|
||||||
|
if (state.tokenize == tokenBase && stream.eatSpace()) return null;
|
||||||
|
var style = state.tokenize(stream, state);
|
||||||
|
if (style && typeof style != "string") style = ret(style[0], style[1]);
|
||||||
|
|
||||||
|
// Changing style returned based on context
|
||||||
|
var context = state.stack[state.stack.length-1];
|
||||||
|
if (style == "variable") {
|
||||||
|
if (type == "variable-definition") state.stack.push("propertyValue");
|
||||||
|
return state.lastToken = "variable-2";
|
||||||
|
} else if (style == "property") {
|
||||||
|
var word = stream.current().toLowerCase();
|
||||||
|
if (context == "propertyValue") {
|
||||||
|
if (valueKeywords.hasOwnProperty(word)) {
|
||||||
|
style = "string-2";
|
||||||
|
} else if (colorKeywords.hasOwnProperty(word)) {
|
||||||
|
style = "keyword";
|
||||||
|
} else {
|
||||||
|
style = "variable-2";
|
||||||
|
}
|
||||||
|
} else if (context == "rule") {
|
||||||
|
if (!propertyKeywords.hasOwnProperty(word)) {
|
||||||
|
style += " error";
|
||||||
|
}
|
||||||
|
} else if (context == "block") {
|
||||||
|
// if a value is present in both property, value, or color, the order
|
||||||
|
// of preference is property -> color -> value
|
||||||
|
if (propertyKeywords.hasOwnProperty(word)) {
|
||||||
|
style = "property";
|
||||||
|
} else if (colorKeywords.hasOwnProperty(word)) {
|
||||||
|
style = "keyword";
|
||||||
|
} else if (valueKeywords.hasOwnProperty(word)) {
|
||||||
|
style = "string-2";
|
||||||
|
} else {
|
||||||
|
style = "tag";
|
||||||
|
}
|
||||||
|
} else if (!context || context == "@media{") {
|
||||||
|
style = "tag";
|
||||||
|
} else if (context == "@media") {
|
||||||
|
if (atMediaTypes[stream.current()]) {
|
||||||
|
style = "attribute"; // Known attribute
|
||||||
|
} else if (/^(only|not)$/.test(word)) {
|
||||||
|
style = "keyword";
|
||||||
|
} else if (word == "and") {
|
||||||
|
style = "error"; // "and" is only allowed in @mediaType
|
||||||
|
} else if (atMediaFeatures.hasOwnProperty(word)) {
|
||||||
|
style = "error"; // Known property, should be in @mediaType(
|
||||||
|
} else {
|
||||||
|
// Unknown, expecting keyword or attribute, assuming attribute
|
||||||
|
style = "attribute error";
|
||||||
|
}
|
||||||
|
} else if (context == "@mediaType") {
|
||||||
|
if (atMediaTypes.hasOwnProperty(word)) {
|
||||||
|
style = "attribute";
|
||||||
|
} else if (word == "and") {
|
||||||
|
style = "operator";
|
||||||
|
} else if (/^(only|not)$/.test(word)) {
|
||||||
|
style = "error"; // Only allowed in @media
|
||||||
|
} else {
|
||||||
|
// Unknown attribute or property, but expecting property (preceded
|
||||||
|
// by "and"). Should be in parentheses
|
||||||
|
style = "error";
|
||||||
|
}
|
||||||
|
} else if (context == "@mediaType(") {
|
||||||
|
if (propertyKeywords.hasOwnProperty(word)) {
|
||||||
|
// do nothing, remains "property"
|
||||||
|
} else if (atMediaTypes.hasOwnProperty(word)) {
|
||||||
|
style = "error"; // Known property, should be in parentheses
|
||||||
|
} else if (word == "and") {
|
||||||
|
style = "operator";
|
||||||
|
} else if (/^(only|not)$/.test(word)) {
|
||||||
|
style = "error"; // Only allowed in @media
|
||||||
|
} else {
|
||||||
|
style += " error";
|
||||||
|
}
|
||||||
|
} else if (context == "@import") {
|
||||||
|
style = "tag";
|
||||||
|
} else {
|
||||||
|
style = "error";
|
||||||
|
}
|
||||||
|
} else if (style == "atom") {
|
||||||
|
if(!context || context == "@media{" || context == "block") {
|
||||||
|
style = "builtin";
|
||||||
|
} else if (context == "propertyValue") {
|
||||||
|
if (!/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) {
|
||||||
|
style += " error";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
style = "error";
|
||||||
|
}
|
||||||
|
} else if (context == "@media" && type == "{") {
|
||||||
|
style = "error";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push/pop context stack
|
||||||
|
if (type == "{") {
|
||||||
|
if (context == "@media" || context == "@mediaType") {
|
||||||
|
state.stack[state.stack.length-1] = "@media{";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var newContext = allowNested ? "block" : "rule";
|
||||||
|
state.stack.push(newContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == "}") {
|
||||||
|
if (context == "interpolation") style = "operator";
|
||||||
|
// Pop off end of array until { is reached
|
||||||
|
while(state.stack.length){
|
||||||
|
var removed = state.stack.pop();
|
||||||
|
if(removed.indexOf("{") > -1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == "interpolation") state.stack.push("interpolation");
|
||||||
|
else if (type == "@media") state.stack.push("@media");
|
||||||
|
else if (type == "@import") state.stack.push("@import");
|
||||||
|
else if (context == "@media" && /\b(keyword|attribute)\b/.test(style))
|
||||||
|
state.stack[state.stack.length-1] = "@mediaType";
|
||||||
|
else if (context == "@mediaType" && stream.current() == ",")
|
||||||
|
state.stack[state.stack.length-1] = "@media";
|
||||||
|
else if (type == "(") {
|
||||||
|
if (context == "@media" || context == "@mediaType") {
|
||||||
|
// Make sure @mediaType is used to avoid error on {
|
||||||
|
state.stack[state.stack.length-1] = "@mediaType";
|
||||||
|
state.stack.push("@mediaType(");
|
||||||
|
}
|
||||||
|
else state.stack.push("(");
|
||||||
|
}
|
||||||
|
else if (type == ")") {
|
||||||
|
// Pop off end of array until ( is reached
|
||||||
|
while(state.stack.length){
|
||||||
|
var removed = state.stack.pop();
|
||||||
|
if(removed.indexOf("(") > -1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == ":" && state.lastToken == "property") state.stack.push("propertyValue");
|
||||||
|
else if (context == "propertyValue" && type == ";") state.stack.pop();
|
||||||
|
else if (context == "@import" && type == ";") state.stack.pop();
|
||||||
|
|
||||||
|
return state.lastToken = style;
|
||||||
|
},
|
||||||
|
|
||||||
|
indent: function(state, textAfter) {
|
||||||
|
var n = state.stack.length;
|
||||||
|
if (/^\}/.test(textAfter))
|
||||||
|
n -= state.stack[n-1] == "propertyValue" ? 2 : 1;
|
||||||
|
return state.baseIndent + n * indentUnit;
|
||||||
|
},
|
||||||
|
|
||||||
|
electricChars: "}",
|
||||||
|
blockCommentStart: "/*",
|
||||||
|
blockCommentEnd: "*/",
|
||||||
|
fold: "brace"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
function keySet(array) {
|
||||||
|
var keys = {};
|
||||||
|
for (var i = 0; i < array.length; ++i) {
|
||||||
|
keys[array[i]] = true;
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
var atMediaTypes = keySet([
|
||||||
|
"all", "aural", "braille", "handheld", "print", "projection", "screen",
|
||||||
|
"tty", "tv", "embossed"
|
||||||
|
]);
|
||||||
|
|
||||||
|
var atMediaFeatures = keySet([
|
||||||
|
"width", "min-width", "max-width", "height", "min-height", "max-height",
|
||||||
|
"device-width", "min-device-width", "max-device-width", "device-height",
|
||||||
|
"min-device-height", "max-device-height", "aspect-ratio",
|
||||||
|
"min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
|
||||||
|
"min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
|
||||||
|
"max-color", "color-index", "min-color-index", "max-color-index",
|
||||||
|
"monochrome", "min-monochrome", "max-monochrome", "resolution",
|
||||||
|
"min-resolution", "max-resolution", "scan", "grid"
|
||||||
|
]);
|
||||||
|
|
||||||
|
var propertyKeywords = keySet([
|
||||||
|
"align-content", "align-items", "align-self", "alignment-adjust",
|
||||||
|
"alignment-baseline", "anchor-point", "animation", "animation-delay",
|
||||||
|
"animation-direction", "animation-duration", "animation-iteration-count",
|
||||||
|
"animation-name", "animation-play-state", "animation-timing-function",
|
||||||
|
"appearance", "azimuth", "backface-visibility", "background",
|
||||||
|
"background-attachment", "background-clip", "background-color",
|
||||||
|
"background-image", "background-origin", "background-position",
|
||||||
|
"background-repeat", "background-size", "baseline-shift", "binding",
|
||||||
|
"bleed", "bookmark-label", "bookmark-level", "bookmark-state",
|
||||||
|
"bookmark-target", "border", "border-bottom", "border-bottom-color",
|
||||||
|
"border-bottom-left-radius", "border-bottom-right-radius",
|
||||||
|
"border-bottom-style", "border-bottom-width", "border-collapse",
|
||||||
|
"border-color", "border-image", "border-image-outset",
|
||||||
|
"border-image-repeat", "border-image-slice", "border-image-source",
|
||||||
|
"border-image-width", "border-left", "border-left-color",
|
||||||
|
"border-left-style", "border-left-width", "border-radius", "border-right",
|
||||||
|
"border-right-color", "border-right-style", "border-right-width",
|
||||||
|
"border-spacing", "border-style", "border-top", "border-top-color",
|
||||||
|
"border-top-left-radius", "border-top-right-radius", "border-top-style",
|
||||||
|
"border-top-width", "border-width", "bottom", "box-decoration-break",
|
||||||
|
"box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
|
||||||
|
"caption-side", "clear", "clip", "color", "color-profile", "column-count",
|
||||||
|
"column-fill", "column-gap", "column-rule", "column-rule-color",
|
||||||
|
"column-rule-style", "column-rule-width", "column-span", "column-width",
|
||||||
|
"columns", "content", "counter-increment", "counter-reset", "crop", "cue",
|
||||||
|
"cue-after", "cue-before", "cursor", "direction", "display",
|
||||||
|
"dominant-baseline", "drop-initial-after-adjust",
|
||||||
|
"drop-initial-after-align", "drop-initial-before-adjust",
|
||||||
|
"drop-initial-before-align", "drop-initial-size", "drop-initial-value",
|
||||||
|
"elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
|
||||||
|
"flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
|
||||||
|
"float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
|
||||||
|
"font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
|
||||||
|
"font-stretch", "font-style", "font-synthesis", "font-variant",
|
||||||
|
"font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
|
||||||
|
"font-variant-ligatures", "font-variant-numeric", "font-variant-position",
|
||||||
|
"font-weight", "grid-cell", "grid-column", "grid-column-align",
|
||||||
|
"grid-column-sizing", "grid-column-span", "grid-columns", "grid-flow",
|
||||||
|
"grid-row", "grid-row-align", "grid-row-sizing", "grid-row-span",
|
||||||
|
"grid-rows", "grid-template", "hanging-punctuation", "height", "hyphens",
|
||||||
|
"icon", "image-orientation", "image-rendering", "image-resolution",
|
||||||
|
"inline-box-align", "justify-content", "left", "letter-spacing",
|
||||||
|
"line-break", "line-height", "line-stacking", "line-stacking-ruby",
|
||||||
|
"line-stacking-shift", "line-stacking-strategy", "list-style",
|
||||||
|
"list-style-image", "list-style-position", "list-style-type", "margin",
|
||||||
|
"margin-bottom", "margin-left", "margin-right", "margin-top",
|
||||||
|
"marker-offset", "marks", "marquee-direction", "marquee-loop",
|
||||||
|
"marquee-play-count", "marquee-speed", "marquee-style", "max-height",
|
||||||
|
"max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
|
||||||
|
"nav-left", "nav-right", "nav-up", "opacity", "order", "orphans", "outline",
|
||||||
|
"outline-color", "outline-offset", "outline-style", "outline-width",
|
||||||
|
"overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
|
||||||
|
"padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
|
||||||
|
"page", "page-break-after", "page-break-before", "page-break-inside",
|
||||||
|
"page-policy", "pause", "pause-after", "pause-before", "perspective",
|
||||||
|
"perspective-origin", "pitch", "pitch-range", "play-during", "position",
|
||||||
|
"presentation-level", "punctuation-trim", "quotes", "region-break-after",
|
||||||
|
"region-break-before", "region-break-inside", "region-fragment",
|
||||||
|
"rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
|
||||||
|
"right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
|
||||||
|
"ruby-position", "ruby-span", "shape-inside", "shape-outside", "size",
|
||||||
|
"speak", "speak-as", "speak-header",
|
||||||
|
"speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
|
||||||
|
"tab-size", "table-layout", "target", "target-name", "target-new",
|
||||||
|
"target-position", "text-align", "text-align-last", "text-decoration",
|
||||||
|
"text-decoration-color", "text-decoration-line", "text-decoration-skip",
|
||||||
|
"text-decoration-style", "text-emphasis", "text-emphasis-color",
|
||||||
|
"text-emphasis-position", "text-emphasis-style", "text-height",
|
||||||
|
"text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
|
||||||
|
"text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
|
||||||
|
"text-wrap", "top", "transform", "transform-origin", "transform-style",
|
||||||
|
"transition", "transition-delay", "transition-duration",
|
||||||
|
"transition-property", "transition-timing-function", "unicode-bidi",
|
||||||
|
"vertical-align", "visibility", "voice-balance", "voice-duration",
|
||||||
|
"voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
|
||||||
|
"voice-volume", "volume", "white-space", "widows", "width", "word-break",
|
||||||
|
"word-spacing", "word-wrap", "z-index", "zoom",
|
||||||
|
// SVG-specific
|
||||||
|
"clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
|
||||||
|
"flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
|
||||||
|
"color-interpolation", "color-interpolation-filters", "color-profile",
|
||||||
|
"color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
|
||||||
|
"marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
|
||||||
|
"stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
|
||||||
|
"stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
|
||||||
|
"baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
|
||||||
|
"glyph-orientation-vertical", "kerning", "text-anchor", "writing-mode"
|
||||||
|
]);
|
||||||
|
|
||||||
|
var colorKeywords = keySet([
|
||||||
|
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
|
||||||
|
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
|
||||||
|
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
|
||||||
|
"cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
|
||||||
|
"darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
|
||||||
|
"darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
|
||||||
|
"darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
|
||||||
|
"deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
|
||||||
|
"floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
|
||||||
|
"gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
|
||||||
|
"hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
|
||||||
|
"lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
|
||||||
|
"lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
|
||||||
|
"lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
|
||||||
|
"lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
|
||||||
|
"maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
|
||||||
|
"mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
|
||||||
|
"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
|
||||||
|
"navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
|
||||||
|
"orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
|
||||||
|
"papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
|
||||||
|
"purple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon",
|
||||||
|
"sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
|
||||||
|
"slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
|
||||||
|
"teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
|
||||||
|
"whitesmoke", "yellow", "yellowgreen"
|
||||||
|
]);
|
||||||
|
|
||||||
|
var valueKeywords = keySet([
|
||||||
|
"above", "absolute", "activeborder", "activecaption", "afar",
|
||||||
|
"after-white-space", "ahead", "alias", "all", "all-scroll", "alternate",
|
||||||
|
"always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
|
||||||
|
"arabic-indic", "armenian", "asterisks", "auto", "avoid", "avoid-column", "avoid-page",
|
||||||
|
"avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
|
||||||
|
"bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
|
||||||
|
"both", "bottom", "break", "break-all", "break-word", "button", "button-bevel",
|
||||||
|
"buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian",
|
||||||
|
"capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
|
||||||
|
"cell", "center", "checkbox", "circle", "cjk-earthly-branch",
|
||||||
|
"cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
|
||||||
|
"col-resize", "collapse", "column", "compact", "condensed", "contain", "content",
|
||||||
|
"content-box", "context-menu", "continuous", "copy", "cover", "crop",
|
||||||
|
"cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal",
|
||||||
|
"decimal-leading-zero", "default", "default-button", "destination-atop",
|
||||||
|
"destination-in", "destination-out", "destination-over", "devanagari",
|
||||||
|
"disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted",
|
||||||
|
"double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
|
||||||
|
"element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
|
||||||
|
"ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
|
||||||
|
"ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
|
||||||
|
"ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
|
||||||
|
"ethiopic-halehame-gez", "ethiopic-halehame-om-et",
|
||||||
|
"ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
|
||||||
|
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et",
|
||||||
|
"ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed",
|
||||||
|
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes",
|
||||||
|
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
|
||||||
|
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
|
||||||
|
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
|
||||||
|
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
|
||||||
|
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
|
||||||
|
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
|
||||||
|
"inline-block", "inline-table", "inset", "inside", "intrinsic", "invert",
|
||||||
|
"italic", "justify", "kannada", "katakana", "katakana-iroha", "keep-all", "khmer",
|
||||||
|
"landscape", "lao", "large", "larger", "left", "level", "lighter",
|
||||||
|
"line-through", "linear", "lines", "list-item", "listbox", "listitem",
|
||||||
|
"local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
|
||||||
|
"lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
|
||||||
|
"lower-roman", "lowercase", "ltr", "malayalam", "match",
|
||||||
|
"media-controls-background", "media-current-time-display",
|
||||||
|
"media-fullscreen-button", "media-mute-button", "media-play-button",
|
||||||
|
"media-return-to-realtime-button", "media-rewind-button",
|
||||||
|
"media-seek-back-button", "media-seek-forward-button", "media-slider",
|
||||||
|
"media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
|
||||||
|
"media-volume-slider-container", "media-volume-sliderthumb", "medium",
|
||||||
|
"menu", "menulist", "menulist-button", "menulist-text",
|
||||||
|
"menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
|
||||||
|
"mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
|
||||||
|
"narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
|
||||||
|
"no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
|
||||||
|
"ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
|
||||||
|
"optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
|
||||||
|
"outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
|
||||||
|
"painted", "page", "paused", "persian", "plus-darker", "plus-lighter", "pointer",
|
||||||
|
"polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button",
|
||||||
|
"radio", "read-only", "read-write", "read-write-plaintext-only", "rectangle", "region",
|
||||||
|
"relative", "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba",
|
||||||
|
"ridge", "right", "round", "row-resize", "rtl", "run-in", "running",
|
||||||
|
"s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield",
|
||||||
|
"searchfield-cancel-button", "searchfield-decoration",
|
||||||
|
"searchfield-results-button", "searchfield-results-decoration",
|
||||||
|
"semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
|
||||||
|
"single", "skip-white-space", "slide", "slider-horizontal",
|
||||||
|
"slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
|
||||||
|
"small", "small-caps", "small-caption", "smaller", "solid", "somali",
|
||||||
|
"source-atop", "source-in", "source-out", "source-over", "space", "square",
|
||||||
|
"square-button", "start", "static", "status-bar", "stretch", "stroke",
|
||||||
|
"sub", "subpixel-antialiased", "super", "sw-resize", "table",
|
||||||
|
"table-caption", "table-cell", "table-column", "table-column-group",
|
||||||
|
"table-footer-group", "table-header-group", "table-row", "table-row-group",
|
||||||
|
"telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
|
||||||
|
"thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
|
||||||
|
"threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
|
||||||
|
"tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
|
||||||
|
"transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
|
||||||
|
"upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
|
||||||
|
"upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
|
||||||
|
"vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
|
||||||
|
"visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
|
||||||
|
"window", "windowframe", "windowtext", "x-large", "x-small", "xor",
|
||||||
|
"xx-large", "xx-small"
|
||||||
|
]);
|
||||||
|
|
||||||
|
function tokenCComment(stream, state) {
|
||||||
|
var maybeEnd = false, ch;
|
||||||
|
while ((ch = stream.next()) != null) {
|
||||||
|
if (maybeEnd && ch == "/") {
|
||||||
|
state.tokenize = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
maybeEnd = (ch == "*");
|
||||||
|
}
|
||||||
|
return ["comment", "comment"];
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeMirror.defineMIME("text/css", {
|
||||||
|
atMediaTypes: atMediaTypes,
|
||||||
|
atMediaFeatures: atMediaFeatures,
|
||||||
|
propertyKeywords: propertyKeywords,
|
||||||
|
colorKeywords: colorKeywords,
|
||||||
|
valueKeywords: valueKeywords,
|
||||||
|
hooks: {
|
||||||
|
"<": function(stream, state) {
|
||||||
|
function tokenSGMLComment(stream, state) {
|
||||||
|
var dashes = 0, ch;
|
||||||
|
while ((ch = stream.next()) != null) {
|
||||||
|
if (dashes >= 2 && ch == ">") {
|
||||||
|
state.tokenize = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dashes = (ch == "-") ? dashes + 1 : 0;
|
||||||
|
}
|
||||||
|
return ["comment", "comment"];
|
||||||
|
}
|
||||||
|
if (stream.eat("!")) {
|
||||||
|
state.tokenize = tokenSGMLComment;
|
||||||
|
return tokenSGMLComment(stream, state);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/": function(stream, state) {
|
||||||
|
if (stream.eat("*")) {
|
||||||
|
state.tokenize = tokenCComment;
|
||||||
|
return tokenCComment(stream, state);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
name: "css"
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.defineMIME("text/x-scss", {
|
||||||
|
atMediaTypes: atMediaTypes,
|
||||||
|
atMediaFeatures: atMediaFeatures,
|
||||||
|
propertyKeywords: propertyKeywords,
|
||||||
|
colorKeywords: colorKeywords,
|
||||||
|
valueKeywords: valueKeywords,
|
||||||
|
allowNested: true,
|
||||||
|
hooks: {
|
||||||
|
":": function(stream) {
|
||||||
|
if (stream.match(/\s*{/)) {
|
||||||
|
return [null, "{"];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
"$": function(stream) {
|
||||||
|
stream.match(/^[\w-]+/);
|
||||||
|
if (stream.peek() == ":") {
|
||||||
|
return ["variable", "variable-definition"];
|
||||||
|
}
|
||||||
|
return ["variable", "variable"];
|
||||||
|
},
|
||||||
|
",": function(_stream, state) {
|
||||||
|
if (state.stack[state.stack.length - 1] == "propertyValue") {
|
||||||
|
return ["operator", ";"];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/": function(stream, state) {
|
||||||
|
if (stream.eat("/")) {
|
||||||
|
stream.skipToEnd();
|
||||||
|
return ["comment", "comment"];
|
||||||
|
} else if (stream.eat("*")) {
|
||||||
|
state.tokenize = tokenCComment;
|
||||||
|
return tokenCComment(stream, state);
|
||||||
|
} else {
|
||||||
|
return ["operator", "operator"];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"#": function(stream) {
|
||||||
|
if (stream.eat("{")) {
|
||||||
|
return ["operator", "interpolation"];
|
||||||
|
} else {
|
||||||
|
stream.eatWhile(/[\w\\\-]/);
|
||||||
|
return ["atom", "hash"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
name: "css"
|
||||||
|
});
|
||||||
|
})();
|
94
examples/vendor/dat.gui.min.js
vendored
Normal file
94
examples/vendor/dat.gui.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
478
examples/vendor/leaflet.css
vendored
Normal file
478
examples/vendor/leaflet.css
vendored
Normal file
@ -0,0 +1,478 @@
|
|||||||
|
/* required styles */
|
||||||
|
|
||||||
|
.leaflet-map-pane,
|
||||||
|
.leaflet-tile,
|
||||||
|
.leaflet-marker-icon,
|
||||||
|
.leaflet-marker-shadow,
|
||||||
|
.leaflet-tile-pane,
|
||||||
|
.leaflet-tile-container,
|
||||||
|
.leaflet-overlay-pane,
|
||||||
|
.leaflet-shadow-pane,
|
||||||
|
.leaflet-marker-pane,
|
||||||
|
.leaflet-popup-pane,
|
||||||
|
.leaflet-overlay-pane svg,
|
||||||
|
.leaflet-zoom-box,
|
||||||
|
.leaflet-image-layer,
|
||||||
|
.leaflet-layer {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
.leaflet-container {
|
||||||
|
overflow: hidden;
|
||||||
|
-ms-touch-action: none;
|
||||||
|
}
|
||||||
|
.leaflet-tile,
|
||||||
|
.leaflet-marker-icon,
|
||||||
|
.leaflet-marker-shadow {
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-moz-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-drag: none;
|
||||||
|
}
|
||||||
|
.leaflet-marker-icon,
|
||||||
|
.leaflet-marker-shadow {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
/* map is broken in FF if you have max-width: 100% on tiles */
|
||||||
|
.leaflet-container img {
|
||||||
|
max-width: none !important;
|
||||||
|
}
|
||||||
|
/* stupid Android 2 doesn't understand "max-width: none" properly */
|
||||||
|
.leaflet-container img.leaflet-image-layer {
|
||||||
|
max-width: 15000px !important;
|
||||||
|
}
|
||||||
|
.leaflet-tile {
|
||||||
|
filter: inherit;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
.leaflet-tile-loaded {
|
||||||
|
visibility: inherit;
|
||||||
|
}
|
||||||
|
.leaflet-zoom-box {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
/* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */
|
||||||
|
.leaflet-overlay-pane svg {
|
||||||
|
-moz-user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-tile-pane { z-index: 2; }
|
||||||
|
.leaflet-objects-pane { z-index: 3; }
|
||||||
|
.leaflet-overlay-pane { z-index: 4; }
|
||||||
|
.leaflet-shadow-pane { z-index: 5; }
|
||||||
|
.leaflet-marker-pane { z-index: 6; }
|
||||||
|
.leaflet-popup-pane { z-index: 7; }
|
||||||
|
|
||||||
|
.leaflet-vml-shape {
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
}
|
||||||
|
.lvml {
|
||||||
|
behavior: url(#default#VML);
|
||||||
|
display: inline-block;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* control positioning */
|
||||||
|
|
||||||
|
.leaflet-control {
|
||||||
|
position: relative;
|
||||||
|
z-index: 7;
|
||||||
|
pointer-events: auto;
|
||||||
|
}
|
||||||
|
.leaflet-top,
|
||||||
|
.leaflet-bottom {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1000;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.leaflet-top {
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
.leaflet-right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
.leaflet-bottom {
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
.leaflet-left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
.leaflet-control {
|
||||||
|
float: left;
|
||||||
|
clear: both;
|
||||||
|
}
|
||||||
|
.leaflet-right .leaflet-control {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
.leaflet-top .leaflet-control {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.leaflet-bottom .leaflet-control {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
.leaflet-left .leaflet-control {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
.leaflet-right .leaflet-control {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* zoom and fade animations */
|
||||||
|
|
||||||
|
.leaflet-fade-anim .leaflet-tile,
|
||||||
|
.leaflet-fade-anim .leaflet-popup {
|
||||||
|
opacity: 0;
|
||||||
|
-webkit-transition: opacity 0.2s linear;
|
||||||
|
-moz-transition: opacity 0.2s linear;
|
||||||
|
-o-transition: opacity 0.2s linear;
|
||||||
|
transition: opacity 0.2s linear;
|
||||||
|
}
|
||||||
|
.leaflet-fade-anim .leaflet-tile-loaded,
|
||||||
|
.leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-zoom-anim .leaflet-zoom-animated {
|
||||||
|
-webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1);
|
||||||
|
-moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1);
|
||||||
|
-o-transition: -o-transform 0.25s cubic-bezier(0,0,0.25,1);
|
||||||
|
transition: transform 0.25s cubic-bezier(0,0,0.25,1);
|
||||||
|
}
|
||||||
|
.leaflet-zoom-anim .leaflet-tile,
|
||||||
|
.leaflet-pan-anim .leaflet-tile,
|
||||||
|
.leaflet-touching .leaflet-zoom-animated {
|
||||||
|
-webkit-transition: none;
|
||||||
|
-moz-transition: none;
|
||||||
|
-o-transition: none;
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-zoom-anim .leaflet-zoom-hide {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* cursors */
|
||||||
|
|
||||||
|
.leaflet-clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.leaflet-container {
|
||||||
|
cursor: -webkit-grab;
|
||||||
|
cursor: -moz-grab;
|
||||||
|
}
|
||||||
|
.leaflet-popup-pane,
|
||||||
|
.leaflet-control {
|
||||||
|
cursor: auto;
|
||||||
|
}
|
||||||
|
.leaflet-dragging .leaflet-container,
|
||||||
|
.leaflet-dragging .leaflet-clickable {
|
||||||
|
cursor: move;
|
||||||
|
cursor: -webkit-grabbing;
|
||||||
|
cursor: -moz-grabbing;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* visual tweaks */
|
||||||
|
|
||||||
|
.leaflet-container {
|
||||||
|
background: #ddd;
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
.leaflet-container a {
|
||||||
|
color: #0078A8;
|
||||||
|
}
|
||||||
|
.leaflet-container a.leaflet-active {
|
||||||
|
outline: 2px solid orange;
|
||||||
|
}
|
||||||
|
.leaflet-zoom-box {
|
||||||
|
border: 2px dotted #38f;
|
||||||
|
background: rgba(255,255,255,0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* general typography */
|
||||||
|
.leaflet-container {
|
||||||
|
font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* general toolbar styles */
|
||||||
|
|
||||||
|
.leaflet-bar {
|
||||||
|
box-shadow: 0 1px 5px rgba(0,0,0,0.65);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.leaflet-bar a,
|
||||||
|
.leaflet-bar a:hover {
|
||||||
|
background-color: #fff;
|
||||||
|
border-bottom: 1px solid #ccc;
|
||||||
|
width: 26px;
|
||||||
|
height: 26px;
|
||||||
|
line-height: 26px;
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
text-decoration: none;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
.leaflet-bar a,
|
||||||
|
.leaflet-control-layers-toggle {
|
||||||
|
background-position: 50% 50%;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.leaflet-bar a:hover {
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
}
|
||||||
|
.leaflet-bar a:first-child {
|
||||||
|
border-top-left-radius: 4px;
|
||||||
|
border-top-right-radius: 4px;
|
||||||
|
}
|
||||||
|
.leaflet-bar a:last-child {
|
||||||
|
border-bottom-left-radius: 4px;
|
||||||
|
border-bottom-right-radius: 4px;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
.leaflet-bar a.leaflet-disabled {
|
||||||
|
cursor: default;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
color: #bbb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-touch .leaflet-bar a {
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
line-height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* zoom control */
|
||||||
|
|
||||||
|
.leaflet-control-zoom-in,
|
||||||
|
.leaflet-control-zoom-out {
|
||||||
|
font: bold 18px 'Lucida Console', Monaco, monospace;
|
||||||
|
text-indent: 1px;
|
||||||
|
}
|
||||||
|
.leaflet-control-zoom-out {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-touch .leaflet-control-zoom-in {
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
.leaflet-touch .leaflet-control-zoom-out {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* layers control */
|
||||||
|
|
||||||
|
.leaflet-control-layers {
|
||||||
|
box-shadow: 0 1px 5px rgba(0,0,0,0.4);
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
.leaflet-control-layers-toggle {
|
||||||
|
background-image: url(images/layers.png);
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
}
|
||||||
|
.leaflet-retina .leaflet-control-layers-toggle {
|
||||||
|
background-image: url(images/layers-2x.png);
|
||||||
|
background-size: 26px 26px;
|
||||||
|
}
|
||||||
|
.leaflet-touch .leaflet-control-layers-toggle {
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
}
|
||||||
|
.leaflet-control-layers .leaflet-control-layers-list,
|
||||||
|
.leaflet-control-layers-expanded .leaflet-control-layers-toggle {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.leaflet-control-layers-expanded .leaflet-control-layers-list {
|
||||||
|
display: block;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.leaflet-control-layers-expanded {
|
||||||
|
padding: 6px 10px 6px 6px;
|
||||||
|
color: #333;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
.leaflet-control-layers-selector {
|
||||||
|
margin-top: 2px;
|
||||||
|
position: relative;
|
||||||
|
top: 1px;
|
||||||
|
}
|
||||||
|
.leaflet-control-layers label {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.leaflet-control-layers-separator {
|
||||||
|
height: 0;
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
margin: 5px -10px 5px -6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* attribution and scale controls */
|
||||||
|
|
||||||
|
.leaflet-container .leaflet-control-attribution {
|
||||||
|
background: #fff;
|
||||||
|
background: rgba(255, 255, 255, 0.7);
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.leaflet-control-attribution,
|
||||||
|
.leaflet-control-scale-line {
|
||||||
|
padding: 0 5px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.leaflet-control-attribution a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.leaflet-control-attribution a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
.leaflet-container .leaflet-control-attribution,
|
||||||
|
.leaflet-container .leaflet-control-scale {
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
.leaflet-left .leaflet-control-scale {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
.leaflet-bottom .leaflet-control-scale {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
.leaflet-control-scale-line {
|
||||||
|
border: 2px solid #777;
|
||||||
|
border-top: none;
|
||||||
|
line-height: 1.1;
|
||||||
|
padding: 2px 5px 1px;
|
||||||
|
font-size: 11px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
-moz-box-sizing: content-box;
|
||||||
|
box-sizing: content-box;
|
||||||
|
|
||||||
|
background: #fff;
|
||||||
|
background: rgba(255, 255, 255, 0.5);
|
||||||
|
}
|
||||||
|
.leaflet-control-scale-line:not(:first-child) {
|
||||||
|
border-top: 2px solid #777;
|
||||||
|
border-bottom: none;
|
||||||
|
margin-top: -2px;
|
||||||
|
}
|
||||||
|
.leaflet-control-scale-line:not(:first-child):not(:last-child) {
|
||||||
|
border-bottom: 2px solid #777;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-touch .leaflet-control-attribution,
|
||||||
|
.leaflet-touch .leaflet-control-layers,
|
||||||
|
.leaflet-touch .leaflet-bar {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
.leaflet-touch .leaflet-control-layers,
|
||||||
|
.leaflet-touch .leaflet-bar {
|
||||||
|
border: 2px solid rgba(0,0,0,0.2);
|
||||||
|
background-clip: padding-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* popup */
|
||||||
|
|
||||||
|
.leaflet-popup {
|
||||||
|
position: absolute;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.leaflet-popup-content-wrapper {
|
||||||
|
padding: 1px;
|
||||||
|
text-align: left;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
.leaflet-popup-content {
|
||||||
|
margin: 13px 19px;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
.leaflet-popup-content p {
|
||||||
|
margin: 18px 0;
|
||||||
|
}
|
||||||
|
.leaflet-popup-tip-container {
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 40px;
|
||||||
|
height: 20px;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.leaflet-popup-tip {
|
||||||
|
width: 17px;
|
||||||
|
height: 17px;
|
||||||
|
padding: 1px;
|
||||||
|
|
||||||
|
margin: -10px auto 0;
|
||||||
|
|
||||||
|
-webkit-transform: rotate(45deg);
|
||||||
|
-moz-transform: rotate(45deg);
|
||||||
|
-ms-transform: rotate(45deg);
|
||||||
|
-o-transform: rotate(45deg);
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
.leaflet-popup-content-wrapper,
|
||||||
|
.leaflet-popup-tip {
|
||||||
|
background: white;
|
||||||
|
|
||||||
|
box-shadow: 0 3px 14px rgba(0,0,0,0.4);
|
||||||
|
}
|
||||||
|
.leaflet-container a.leaflet-popup-close-button {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
padding: 4px 4px 0 0;
|
||||||
|
text-align: center;
|
||||||
|
width: 18px;
|
||||||
|
height: 14px;
|
||||||
|
font: 16px/14px Tahoma, Verdana, sans-serif;
|
||||||
|
color: #c3c3c3;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: bold;
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
.leaflet-container a.leaflet-popup-close-button:hover {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
.leaflet-popup-scrolled {
|
||||||
|
overflow: auto;
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-oldie .leaflet-popup-content-wrapper {
|
||||||
|
zoom: 1;
|
||||||
|
}
|
||||||
|
.leaflet-oldie .leaflet-popup-tip {
|
||||||
|
width: 24px;
|
||||||
|
margin: 0 auto;
|
||||||
|
|
||||||
|
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678)";
|
||||||
|
filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678, M12=0.70710678, M21=-0.70710678, M22=0.70710678);
|
||||||
|
}
|
||||||
|
.leaflet-oldie .leaflet-popup-tip-container {
|
||||||
|
margin-top: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.leaflet-oldie .leaflet-control-zoom,
|
||||||
|
.leaflet-oldie .leaflet-control-layers,
|
||||||
|
.leaflet-oldie .leaflet-popup-content-wrapper,
|
||||||
|
.leaflet-oldie .leaflet-popup-tip {
|
||||||
|
border: 1px solid #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* div icon */
|
||||||
|
|
||||||
|
.leaflet-div-icon {
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #666;
|
||||||
|
}
|
9180
examples/vendor/leaflet.js
vendored
Normal file
9180
examples/vendor/leaflet.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -15,14 +15,9 @@ headerString = headerString.replace("{{version}}", packageJSON.version)
|
|||||||
|
|
||||||
['torque.uncompressed.js'].forEach(function(v){
|
['torque.uncompressed.js'].forEach(function(v){
|
||||||
fs.readFile('dist/' + v, 'utf8', function(err, torque) {
|
fs.readFile('dist/' + v, 'utf8', function(err, torque) {
|
||||||
if (err) {
|
if(!err){
|
||||||
return console.error(err);
|
|
||||||
}
|
|
||||||
var torqueString = headerString.replace("{{lib}}", torque);
|
var torqueString = headerString.replace("{{lib}}", torque);
|
||||||
fs.writeFile('dist/' + v, torqueString, function (err) {
|
fs.writeFile('dist/' + v, torqueString);
|
||||||
if (err) {
|
|
||||||
return console.error(err);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Abstract handler for animator steps
|
|
||||||
*/
|
|
||||||
var AnimatorStepsRange = function(start, end) {
|
|
||||||
if (start < 0) throw new Error('start must be a positive number');
|
|
||||||
if (start >= end) throw new Error('start must be smaller than end');
|
|
||||||
|
|
||||||
this.start = start;
|
|
||||||
this.end = end;
|
|
||||||
};
|
|
||||||
|
|
||||||
AnimatorStepsRange.prototype = {
|
|
||||||
|
|
||||||
diff: function() {
|
|
||||||
return this.end - this.start;
|
|
||||||
},
|
|
||||||
|
|
||||||
isLast: function(step) {
|
|
||||||
// round step into an integer, to be able to compare number as expected (also converts bad input to 0)
|
|
||||||
return (step | 0) === this.end;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = AnimatorStepsRange;
|
|
@ -1,5 +1,4 @@
|
|||||||
var torque = require('./');
|
var torque = require('./');
|
||||||
var AnimatorStepsRange = require('./animator-steps-range');
|
|
||||||
|
|
||||||
var requestAnimationFrame = global.requestAnimationFrame
|
var requestAnimationFrame = global.requestAnimationFrame
|
||||||
|| global.mozRequestAnimationFrame
|
|| global.mozRequestAnimationFrame
|
||||||
@ -36,16 +35,18 @@ var cancelAnimationFrame = global.cancelAnimationFrame
|
|||||||
loop: options.loop === undefined ? true : options.loop
|
loop: options.loop === undefined ? true : options.loop
|
||||||
}, this.options);
|
}, this.options);
|
||||||
|
|
||||||
this.steps(options.steps);
|
this.rescale();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Animator.prototype = {
|
Animator.prototype = {
|
||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
this.running = true;
|
this.running = true;
|
||||||
requestAnimationFrame(this._tick);
|
requestAnimationFrame(this._tick);
|
||||||
this.options.onStart && this.options.onStart();
|
this.options.onStart && this.options.onStart();
|
||||||
if (this.stepsRange().diff() === 1) {
|
if(this.options.steps === 1){
|
||||||
this.running = false;
|
this.running = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -56,7 +57,7 @@ var cancelAnimationFrame = global.cancelAnimationFrame
|
|||||||
|
|
||||||
stop: function() {
|
stop: function() {
|
||||||
this.pause();
|
this.pause();
|
||||||
this.time(this.stepsRange().start);
|
this.time(0);
|
||||||
this.options.onStop && this.options.onStop();
|
this.options.onStop && this.options.onStop();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ var cancelAnimationFrame = global.cancelAnimationFrame
|
|||||||
rescale: function() {
|
rescale: function() {
|
||||||
this.domainInv = torque.math.linear(this.options.animationDelay, this.options.animationDelay + this.options.animationDuration);
|
this.domainInv = torque.math.linear(this.options.animationDelay, this.options.animationDelay + this.options.animationDuration);
|
||||||
this.domain = this.domainInv.invert();
|
this.domain = this.domainInv.invert();
|
||||||
this.range = torque.math.linear(0, this._defaultStepsRange.end);
|
this.range = torque.math.linear(0, this.options.steps);
|
||||||
this.rangeInv = this.range.invert();
|
this.rangeInv = this.range.invert();
|
||||||
this.time(this._time);
|
this.time(this._time);
|
||||||
this.running? this.start(): this.pause();
|
this.running? this.start(): this.pause();
|
||||||
@ -98,34 +99,9 @@ var cancelAnimationFrame = global.cancelAnimationFrame
|
|||||||
|
|
||||||
steps: function(_) {
|
steps: function(_) {
|
||||||
this.options.steps = _;
|
this.options.steps = _;
|
||||||
this._defaultStepsRange = new AnimatorStepsRange(0, _);
|
|
||||||
return this.rescale();
|
return this.rescale();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Returns or sets a (custom) steps range
|
|
||||||
// Setting a steps range must be within the full range
|
|
||||||
stepsRange: function(start, end) {
|
|
||||||
if (arguments.length === 2) {
|
|
||||||
if (start < this._defaultStepsRange.start) throw new Error('start must be within default steps range');
|
|
||||||
if (end > this._defaultStepsRange.end) throw new Error('end must be within default steps range');
|
|
||||||
|
|
||||||
this._customStepsRange = new AnimatorStepsRange(start, end);
|
|
||||||
this.options.onStepsRange && this.options.onStepsRange();
|
|
||||||
|
|
||||||
// Change current step if it's outside the new custom range
|
|
||||||
var step = this.step() | 0; // round to an integer
|
|
||||||
if (step < start || step > end) {
|
|
||||||
this.step(start);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this._customStepsRange || this._defaultStepsRange;
|
|
||||||
},
|
|
||||||
|
|
||||||
removeCustomStepsRange: function() {
|
|
||||||
this._customStepsRange = undefined;
|
|
||||||
this.options.onStepsRange && this.options.onStepsRange();
|
|
||||||
},
|
|
||||||
|
|
||||||
step: function(s) {
|
step: function(s) {
|
||||||
if(arguments.length === 0) return this.range(this.domain(this._time));
|
if(arguments.length === 0) return this.range(this.domain(this._time));
|
||||||
this._time = this.domainInv(this.rangeInv(s));
|
this._time = this.domainInv(this.rangeInv(s));
|
||||||
@ -145,15 +121,13 @@ var cancelAnimationFrame = global.cancelAnimationFrame
|
|||||||
delta = Math.min(this.options.maxDelta, delta);
|
delta = Math.min(this.options.maxDelta, delta);
|
||||||
this._t0 = t1;
|
this._t0 = t1;
|
||||||
this._time += delta;
|
this._time += delta;
|
||||||
|
if(this.step() >= this.options.steps) {
|
||||||
var stepsRange = this.stepsRange();
|
|
||||||
if (stepsRange.isLast(this.step())) {
|
|
||||||
if(!this.options.loop){
|
if(!this.options.loop){
|
||||||
// set time to max time
|
// set time to max time
|
||||||
this.time(this.options.animationDuration);
|
this.time(this.options.animationDuration);
|
||||||
this.pause();
|
this.pause();
|
||||||
} else {
|
} else {
|
||||||
this.step(stepsRange.start);
|
this._time = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(this.running) {
|
if(this.running) {
|
||||||
|
@ -9,12 +9,7 @@ function GMapsTorqueLayer(options) {
|
|||||||
if (!torque.isBrowserSupported()) {
|
if (!torque.isBrowserSupported()) {
|
||||||
throw new Error("browser is not supported by torque");
|
throw new Error("browser is not supported by torque");
|
||||||
}
|
}
|
||||||
this.keys = [0];
|
this.key = 0;
|
||||||
Object.defineProperty(this, 'key', {
|
|
||||||
get: function() {
|
|
||||||
return this.getKey();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.shader = null;
|
this.shader = null;
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
this.options = torque.extend({}, options);
|
this.options = torque.extend({}, options);
|
||||||
@ -30,31 +25,14 @@ function GMapsTorqueLayer(options) {
|
|||||||
torque.common.TorqueLayer.optionsFromCartoCSS(options.cartocss));
|
torque.common.TorqueLayer.optionsFromCartoCSS(options.cartocss));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options.tileJSON) this.options.provider = "tileJSON";
|
|
||||||
|
|
||||||
this.hidden = !this.options.visible;
|
this.hidden = !this.options.visible;
|
||||||
|
|
||||||
this.showLimitErrors = options.showLimitErrors;
|
|
||||||
|
|
||||||
this.animator = new torque.Animator(function(time) {
|
this.animator = new torque.Animator(function(time) {
|
||||||
var k = time | 0;
|
var k = time | 0;
|
||||||
if(self.getKey() !== k) {
|
if(self.key !== k) {
|
||||||
self.setKey(k);
|
self.setKey(k);
|
||||||
}
|
}
|
||||||
}, torque.extend(torque.clone(this.options), {
|
}, torque.clone(this.options));
|
||||||
onPause: function() {
|
|
||||||
self.fire('pause');
|
|
||||||
},
|
|
||||||
onStop: function() {
|
|
||||||
self.fire('stop');
|
|
||||||
},
|
|
||||||
onStart: function() {
|
|
||||||
self.fire('play');
|
|
||||||
},
|
|
||||||
onStepsRange: function() {
|
|
||||||
self.fire('change:stepsRange', self.animator.stepsRange());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
this.play = this.animator.start.bind(this.animator);
|
this.play = this.animator.start.bind(this.animator);
|
||||||
this.stop = this.animator.stop.bind(this.animator);
|
this.stop = this.animator.stop.bind(this.animator);
|
||||||
@ -65,6 +43,8 @@ function GMapsTorqueLayer(options) {
|
|||||||
|
|
||||||
|
|
||||||
CanvasLayer.call(this, {
|
CanvasLayer.call(this, {
|
||||||
|
map: this.options.map,
|
||||||
|
//resizeHandler: this.redraw,
|
||||||
animate: false,
|
animate: false,
|
||||||
updateHandler: this.render,
|
updateHandler: this.render,
|
||||||
readyHandler: this.initialize
|
readyHandler: this.initialize
|
||||||
@ -84,8 +64,7 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
providers: {
|
providers: {
|
||||||
'sql_api': torque.providers.json,
|
'sql_api': torque.providers.json,
|
||||||
'url_template': torque.providers.JsonArray,
|
'url_template': torque.providers.JsonArray,
|
||||||
'windshaft': torque.providers.windshaft,
|
'windshaft': torque.providers.windshaft
|
||||||
'tileJSON': torque.providers.tileJSON
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderers: {
|
renderers: {
|
||||||
@ -107,7 +86,7 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
self.fire('change:steps', {
|
self.fire('change:steps', {
|
||||||
steps: self.provider.getSteps()
|
steps: self.provider.getSteps()
|
||||||
});
|
});
|
||||||
self.setKeys(self.getKeys());
|
self.setKey(self.key);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.provider = new this.providers[this.options.provider](this.options);
|
this.provider = new this.providers[this.options.provider](this.options);
|
||||||
@ -115,11 +94,11 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
this.renderer.options.errorCallback = this.options.errorCallback;
|
this.renderer.options.errorCallback = this.options.errorCallback;
|
||||||
|
|
||||||
// this listener should be before tile loader
|
// this listener should be before tile loader
|
||||||
this._cacheListener = google.maps.event.addListener(this.map, 'zoom_changed', function() {
|
this._cacheListener = google.maps.event.addListener(this.options.map, 'zoom_changed', function() {
|
||||||
self.renderer && self.renderer.clearSpriteCache();
|
self.renderer && self.renderer.clearSpriteCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
this._initTileLoader(this.map, this.getProjection());
|
this._initTileLoader(this.options.map, this.getProjection());
|
||||||
|
|
||||||
if (this.shader) {
|
if (this.shader) {
|
||||||
this.renderer.setShader(this.shader);
|
this.renderer.setShader(this.shader);
|
||||||
@ -182,24 +161,14 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
// for each tile shown on the map request the data
|
// for each tile shown on the map request the data
|
||||||
onTileAdded: function(t) {
|
onTileAdded: function(t) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var callback = function (tileData, error) {
|
this.provider.getTileData(t, t.zoom, function(tileData) {
|
||||||
// don't load tiles that are not being shown
|
// don't load tiles that are not being shown
|
||||||
if (t.zoom !== self.map.getZoom()) return;
|
if (t.zoom !== self.options.map.getZoom()) return;
|
||||||
|
|
||||||
self._tileLoaded(t, tileData);
|
self._tileLoaded(t, tileData);
|
||||||
|
|
||||||
if (tileData) {
|
if (tileData) {
|
||||||
self.redraw();
|
self.redraw();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
self.fire('tileLoaded');
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
self.fire('tileError', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.provider.getTileData(t, t.zoom, callback);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: function() {
|
clear: function() {
|
||||||
@ -225,7 +194,7 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
if (tile) {
|
if (tile) {
|
||||||
pos = this.getTilePos(tile.coord);
|
pos = this.getTilePos(tile.coord);
|
||||||
ctx.setTransform(1, 0, 0, 1, pos.x, pos.y);
|
ctx.setTransform(1, 0, 0, 1, pos.x, pos.y);
|
||||||
this.renderer.renderTile(tile, this.keys);
|
this.renderer.renderTile(tile, this.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.renderer.applyFilters();
|
this.renderer.applyFilters();
|
||||||
@ -247,25 +216,10 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
* accumulated
|
* accumulated
|
||||||
*/
|
*/
|
||||||
setKey: function(key) {
|
setKey: function(key) {
|
||||||
this.setKeys([key]);
|
this.key = key;
|
||||||
},
|
this.animator.step(key);
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the array of keys being rendered
|
|
||||||
*/
|
|
||||||
getKeys: function() {
|
|
||||||
return this.keys;
|
|
||||||
},
|
|
||||||
|
|
||||||
setKeys: function(keys) {
|
|
||||||
this.keys = keys;
|
|
||||||
this.animator.step(this.getKey());
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
this.fire('change:time', { time: this.getTime(), step: this.getKey() });
|
this.fire('change:time', { time: this.getTime(), step: this.key });
|
||||||
},
|
|
||||||
|
|
||||||
getKey: function() {
|
|
||||||
return this.keys[0];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -279,20 +233,6 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
this.setKey(time);
|
this.setKey(time);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderRange: function(start, end) {
|
|
||||||
this.pause();
|
|
||||||
var keys = [];
|
|
||||||
for (var i = start; i <= end; i++) {
|
|
||||||
keys.push(i);
|
|
||||||
}
|
|
||||||
this.setKeys(keys);
|
|
||||||
},
|
|
||||||
|
|
||||||
resetRenderRange: function() {
|
|
||||||
this.stop();
|
|
||||||
this.play();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* transform from animation step to Date object
|
* transform from animation step to Date object
|
||||||
* that contains the animation time
|
* that contains the animation time
|
||||||
@ -315,7 +255,7 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
},
|
},
|
||||||
|
|
||||||
getStep: function() {
|
getStep: function() {
|
||||||
return this.getKey();
|
return this.key;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -323,20 +263,14 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
* in the defined column. Date object
|
* in the defined column. Date object
|
||||||
*/
|
*/
|
||||||
getTime: function() {
|
getTime: function() {
|
||||||
return this.stepToTime(this.getKey());
|
return this.stepToTime(this.key);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the cartocss for the current renderer
|
* set the cartocss for the current renderer
|
||||||
*/
|
*/
|
||||||
setCartoCSS: function(cartocss) {
|
setCartoCSS: function(cartocss) {
|
||||||
if (!this.renderer) throw new Error('renderer is not valid');
|
if (this.provider && this.provider.options.named_map) throw new Error("CartoCSS style on named maps is read-only");
|
||||||
|
|
||||||
if (this.provider && this.provider.options.named_map) {
|
|
||||||
console.log('Torque layer: CartoCSS style on named maps is read-only');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var shader = new carto.RendererJS().render(cartocss);
|
var shader = new carto.RendererJS().render(cartocss);
|
||||||
this.shader = shader;
|
this.shader = shader;
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
@ -372,22 +306,8 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
google.maps.event.removeListener(this._cacheListener);
|
google.maps.event.removeListener(this._cacheListener);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* return an array with the values for all the pixels active for the step
|
|
||||||
*/
|
|
||||||
getValues: function(step) {
|
|
||||||
var values = [];
|
|
||||||
step = step === undefined ? this.getKey(): step;
|
|
||||||
var t, tile;
|
|
||||||
for(t in this._tiles) {
|
|
||||||
tile = this._tiles[t];
|
|
||||||
this.renderer.getValues(tile, step, values);
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
},
|
|
||||||
|
|
||||||
getValueForPos: function(x, y, step) {
|
getValueForPos: function(x, y, step) {
|
||||||
step = step === undefined ? this.getKey(): step;
|
step = step === undefined ? this.key: step;
|
||||||
var t, tile, pos, value = null, xx, yy;
|
var t, tile, pos, value = null, xx, yy;
|
||||||
for(t in this._tiles) {
|
for(t in this._tiles) {
|
||||||
tile = this._tiles[t];
|
tile = this._tiles[t];
|
||||||
@ -403,21 +323,6 @@ GMapsTorqueLayer.prototype = torque.extend({},
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/** return the number of points for a step */
|
|
||||||
pointCount: function(step) {
|
|
||||||
var t, tile;
|
|
||||||
step = step === undefined ? this.key: step;
|
|
||||||
var c = 0;
|
|
||||||
for(t in this._tiles) {
|
|
||||||
tile = this._tiles[t];
|
|
||||||
if (tile) {
|
|
||||||
c += tile.timeCount[step];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
},
|
|
||||||
|
|
||||||
getValueForBBox: function(x, y, w, h) {
|
getValueForBBox: function(x, y, w, h) {
|
||||||
var xf = x + w, yf = y + h;
|
var xf = x + w, yf = y + h;
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
@ -466,7 +371,7 @@ GMapsTiledTorqueLayer.prototype = torque.extend({}, CanvasTileLayer.prototype, {
|
|||||||
|
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.keys = [0];
|
this.key = 0;
|
||||||
|
|
||||||
this.options.renderer = this.options.renderer || 'pixel';
|
this.options.renderer = this.options.renderer || 'pixel';
|
||||||
this.options.provider = this.options.provider || 'sql_api';
|
this.options.provider = this.options.provider || 'sql_api';
|
||||||
@ -502,12 +407,12 @@ GMapsTiledTorqueLayer.prototype = torque.extend({}, CanvasTileLayer.prototype, {
|
|||||||
|
|
||||||
this.renderer.setCanvas(canvas);
|
this.renderer.setCanvas(canvas);
|
||||||
|
|
||||||
var accum = this.renderer.accumulate(tile.data, this.getKey());
|
var accum = this.renderer.accumulate(tile.data, this.key);
|
||||||
this.renderer.renderTileAccum(accum, 0, 0);
|
this.renderer.renderTileAccum(accum, 0, 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
setKey: function(key) {
|
setKey: function(key) {
|
||||||
this.keys = [key];
|
this.key = key;
|
||||||
this.redraw();
|
this.redraw();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -517,18 +422,6 @@ GMapsTiledTorqueLayer.prototype = torque.extend({}, CanvasTileLayer.prototype, {
|
|||||||
setCartoCSS: function(cartocss) {
|
setCartoCSS: function(cartocss) {
|
||||||
if (!this.renderer) throw new Error('renderer is not valid');
|
if (!this.renderer) throw new Error('renderer is not valid');
|
||||||
return this.renderer.setCartoCSS(cartocss);
|
return this.renderer.setCartoCSS(cartocss);
|
||||||
},
|
|
||||||
|
|
||||||
setStepsRange: function(start, end) {
|
|
||||||
this.animator.stepsRange(start, end);
|
|
||||||
},
|
|
||||||
|
|
||||||
removeStepsRange: function() {
|
|
||||||
this.animator.removeCustomStepsRange();
|
|
||||||
},
|
|
||||||
|
|
||||||
getStepsRange: function() {
|
|
||||||
return this.animator.stepsRange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -15,5 +15,3 @@ var gmaps = require('./gmaps');
|
|||||||
module.exports.GMapsTileLoader = gmaps.GMapsTileLoader;
|
module.exports.GMapsTileLoader = gmaps.GMapsTileLoader;
|
||||||
module.exports.GMapsTorqueLayer = gmaps.GMapsTorqueLayer;
|
module.exports.GMapsTorqueLayer = gmaps.GMapsTorqueLayer;
|
||||||
module.exports.GMapsTiledTorqueLayer = gmaps.GMapsTiledTorqueLayer;
|
module.exports.GMapsTiledTorqueLayer = gmaps.GMapsTiledTorqueLayer;
|
||||||
|
|
||||||
require('./ol');
|
|
@ -4,7 +4,7 @@ require('./leaflet_tileloader_mixin');
|
|||||||
* full canvas layer implementation for Leaflet
|
* full canvas layer implementation for Leaflet
|
||||||
*/
|
*/
|
||||||
|
|
||||||
L.CanvasLayer = L.Layer.extend({
|
L.CanvasLayer = L.Class.extend({
|
||||||
|
|
||||||
includes: [L.Mixin.Events, L.Mixin.TileLoader],
|
includes: [L.Mixin.Events, L.Mixin.TileLoader],
|
||||||
|
|
||||||
@ -128,13 +128,13 @@ L.CanvasLayer = L.Layer.extend({
|
|||||||
|
|
||||||
var origin = {
|
var origin = {
|
||||||
x: newCenter.x - oldCenter.x + pos.x,
|
x: newCenter.x - oldCenter.x + pos.x,
|
||||||
y: newCenter.y - oldCenter.y + pos.y
|
y: newCenter.y - oldCenter.y + pos.y,
|
||||||
};
|
};
|
||||||
|
|
||||||
var bg = back;
|
var bg = back;
|
||||||
var transform = L.DomUtil.TRANSFORM;
|
var transform = L.DomUtil.TRANSFORM;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
bg.style[transform] = 'translate(' + origin.x + 'px, ' + origin.y + 'px) scale(' + e.scale + ') ';
|
bg.style[transform] = L.DomUtil.getTranslateString(origin) + ' scale(' + e.scale + ') ';
|
||||||
}, 0)
|
}, 0)
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ L.CanvasLayer = L.Layer.extend({
|
|||||||
this._container.parentNode.removeChild(this._container);
|
this._container.parentNode.removeChild(this._container);
|
||||||
map.off({
|
map.off({
|
||||||
'viewreset': this._reset,
|
'viewreset': this._reset,
|
||||||
'move': this.redraw,
|
'move': this._render,
|
||||||
'moveend': this._reset,
|
'moveend': this._reset,
|
||||||
'resize': this._reset,
|
'resize': this._reset,
|
||||||
'zoomanim': this._animateZoom,
|
'zoomanim': this._animateZoom,
|
||||||
@ -186,8 +186,6 @@ L.CanvasLayer = L.Layer.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
setZIndex: function(zIndex) {
|
setZIndex: function(zIndex) {
|
||||||
zIndex = zIndex !== void 0 ? zIndex : 1;
|
|
||||||
this._container.style.zIndex = zIndex;
|
|
||||||
this._canvas.style.zIndex = zIndex;
|
this._canvas.style.zIndex = zIndex;
|
||||||
if (this.options.zoomAnimation) {
|
if (this.options.zoomAnimation) {
|
||||||
this._backCanvas.style.zIndex = zIndex;
|
this._backCanvas.style.zIndex = zIndex;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
L.Mixin.TileLoader = {
|
L.Mixin.TileLoader = {
|
||||||
|
|
||||||
_initTileLoader: function() {
|
_initTileLoader: function() {
|
||||||
|
this._tiles = {}
|
||||||
this._tilesLoading = {};
|
this._tilesLoading = {};
|
||||||
this._tilesToLoad = 0;
|
this._tilesToLoad = 0;
|
||||||
this._map.on({
|
this._map.on({
|
||||||
@ -99,7 +100,7 @@ L.Mixin.TileLoader = {
|
|||||||
|
|
||||||
getTilePos: function (tilePoint) {
|
getTilePos: function (tilePoint) {
|
||||||
tilePoint = new L.Point(tilePoint.x, tilePoint.y);
|
tilePoint = new L.Point(tilePoint.x, tilePoint.y);
|
||||||
var origin = this._map._getTopLeftPoint(this._map.getCenter()),
|
var origin = this._map._getNewTopLeftPoint(this._map.getCenter()),
|
||||||
tileSize = this.options.tileSize;
|
tileSize = this.options.tileSize;
|
||||||
|
|
||||||
return tilePoint.multiplyBy(tileSize).subtract(origin);
|
return tilePoint.multiplyBy(tileSize).subtract(origin);
|
||||||
@ -110,8 +111,6 @@ L.Mixin.TileLoader = {
|
|||||||
center = bounds.getCenter(),
|
center = bounds.getCenter(),
|
||||||
zoom = this._map.getZoom();
|
zoom = this._map.getZoom();
|
||||||
|
|
||||||
zoom = Math.round(zoom);
|
|
||||||
|
|
||||||
var j, i, point;
|
var j, i, point;
|
||||||
|
|
||||||
for (j = bounds.min.y; j <= bounds.max.y; j++) {
|
for (j = bounds.min.y; j <= bounds.max.y; j++) {
|
||||||
|
@ -11,8 +11,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
providers: {
|
providers: {
|
||||||
'sql_api': torque.providers.json,
|
'sql_api': torque.providers.json,
|
||||||
'url_template': torque.providers.JsonArray,
|
'url_template': torque.providers.JsonArray,
|
||||||
'windshaft': torque.providers.windshaft,
|
'windshaft': torque.providers.windshaft
|
||||||
'tileJSON': torque.providers.tileJSON
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderers: {
|
renderers: {
|
||||||
@ -26,18 +25,10 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
throw new Error("browser is not supported by torque");
|
throw new Error("browser is not supported by torque");
|
||||||
}
|
}
|
||||||
options.tileLoader = true;
|
options.tileLoader = true;
|
||||||
this.keys = [0];
|
this.key = 0;
|
||||||
this._tiles = {};
|
|
||||||
Object.defineProperty(this, 'key', {
|
|
||||||
get: function() {
|
|
||||||
return this.getKey();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.prevRenderedKey = 0;
|
this.prevRenderedKey = 0;
|
||||||
if (options.cartocss) {
|
if (options.cartocss) {
|
||||||
// We're only passing the Map header to the global options because the parser won't like turbocarto expressions
|
torque.extend(options, torque.common.TorqueLayer.optionsFromCartoCSS(options.cartocss));
|
||||||
var headerCartoCSS = options.cartocss.replace(/\n/g,'').match(/Map\s*?\{.*?}/g)[0];
|
|
||||||
torque.extend(options, torque.common.TorqueLayer.optionsFromCartoCSS(headerCartoCSS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
options.resolution = options.resolution || 2;
|
options.resolution = options.resolution || 2;
|
||||||
@ -47,7 +38,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
|
|
||||||
this.animator = new torque.Animator(function(time) {
|
this.animator = new torque.Animator(function(time) {
|
||||||
var k = time | 0;
|
var k = time | 0;
|
||||||
if(self.getKey() !== k) {
|
if(self.key !== k) {
|
||||||
self.setKey(k, { direct: true });
|
self.setKey(k, { direct: true });
|
||||||
}
|
}
|
||||||
}, torque.extend(torque.clone(options), {
|
}, torque.extend(torque.clone(options), {
|
||||||
@ -59,9 +50,6 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
},
|
},
|
||||||
onStart: function() {
|
onStart: function() {
|
||||||
self.fire('play');
|
self.fire('play');
|
||||||
},
|
|
||||||
onStepsRange: function() {
|
|
||||||
self.fire('change:stepsRange', self.animator.stepsRange());
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -72,20 +60,15 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
this.setDuration = this.animator.duration.bind(this.animator);
|
this.setDuration = this.animator.duration.bind(this.animator);
|
||||||
this.isRunning = this.animator.isRunning.bind(this.animator);
|
this.isRunning = this.animator.isRunning.bind(this.animator);
|
||||||
|
|
||||||
|
|
||||||
L.CanvasLayer.prototype.initialize.call(this, options);
|
L.CanvasLayer.prototype.initialize.call(this, options);
|
||||||
|
|
||||||
this.options.renderer = this.options.renderer || 'point';
|
this.options.renderer = this.options.renderer || 'point';
|
||||||
this.options.provider = this.options.provider || 'windshaft';
|
this.options.provider = this.options.provider || 'windshaft';
|
||||||
|
|
||||||
if (this.options.tileJSON) this.options.provider = 'tileJSON';
|
|
||||||
|
|
||||||
this.showLimitErrors = options.showLimitErrors;
|
|
||||||
|
|
||||||
this.provider = new this.providers[this.options.provider](options);
|
this.provider = new this.providers[this.options.provider](options);
|
||||||
options.layer = this;
|
|
||||||
this.renderer = new this.renderers[this.options.renderer](this.getCanvas(), options);
|
this.renderer = new this.renderers[this.options.renderer](this.getCanvas(), options);
|
||||||
|
|
||||||
|
|
||||||
options.ready = function() {
|
options.ready = function() {
|
||||||
self.fire("change:bounds", {
|
self.fire("change:bounds", {
|
||||||
bounds: self.provider.getBounds()
|
bounds: self.provider.getBounds()
|
||||||
@ -95,37 +78,25 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
self.fire('change:steps', {
|
self.fire('change:steps', {
|
||||||
steps: self.provider.getSteps()
|
steps: self.provider.getSteps()
|
||||||
});
|
});
|
||||||
self.setKeys(self.getKeys());
|
self.setKey(self.key);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.on('tileLoaded', function () {
|
|
||||||
self.renderer.setCartoCSS(self.renderer.style);
|
|
||||||
})
|
|
||||||
|
|
||||||
this.renderer.on("allIconsLoaded", this.render.bind(this));
|
this.renderer.on("allIconsLoaded", this.render.bind(this));
|
||||||
|
|
||||||
|
|
||||||
// for each tile shown on the map request the data
|
// for each tile shown on the map request the data
|
||||||
this.on('tileAdded', function(t) {
|
this.on('tileAdded', function(t) {
|
||||||
var callback = function (tileData, error) {
|
var tileData = this.provider.getTileData(t, t.zoom, function(tileData) {
|
||||||
// don't load tiles that are not being shown
|
// don't load tiles that are not being shown
|
||||||
if (t.zoom !== self._map.getZoom()) return;
|
if (t.zoom !== self._map.getZoom()) return;
|
||||||
|
|
||||||
self._tileLoaded(t, tileData);
|
self._tileLoaded(t, tileData);
|
||||||
self._clearTileCaches();
|
self._clearTileCaches();
|
||||||
|
|
||||||
if (tileData) {
|
if (tileData) {
|
||||||
self.redraw();
|
self.redraw();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
self.fire('tileLoaded');
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
self.fire('tileError', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var tileData = this.provider.getTileData(t, t.zoom, callback);
|
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_clearTileCaches: function() {
|
_clearTileCaches: function() {
|
||||||
@ -146,7 +117,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
onAdd: function (map) {
|
onAdd: function (map) {
|
||||||
map.on({
|
map.on({
|
||||||
'zoomend': this._clearCaches,
|
'zoomend': this._clearCaches,
|
||||||
'zoomstart': this._pauseOnZoom
|
'zoomstart': this._pauseOnZoom,
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
map.on({
|
map.on({
|
||||||
@ -160,7 +131,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
this._removeTileLoader();
|
this._removeTileLoader();
|
||||||
map.off({
|
map.off({
|
||||||
'zoomend': this._clearCaches,
|
'zoomend': this._clearCaches,
|
||||||
'zoomstart': this._pauseOnZoom
|
'zoomstart': this._pauseOnZoom,
|
||||||
}, this);
|
}, this);
|
||||||
map.off({
|
map.off({
|
||||||
'zoomend': this._resumeOnZoom
|
'zoomend': this._resumeOnZoom
|
||||||
@ -261,7 +232,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
// all the points
|
// all the points
|
||||||
this.renderer._ctx.drawImage(tile._tileCache, 0, 0);
|
this.renderer._ctx.drawImage(tile._tileCache, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
this.renderer.renderTile(tile, this.keys);
|
this.renderer.renderTile(tile, this.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,7 +241,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
// prepare caches if the animation is not running
|
// prepare caches if the animation is not running
|
||||||
// don't cache if the key has just changed, this avoids to cache
|
// don't cache if the key has just changed, this avoids to cache
|
||||||
// when the user is dragging, it only cache when the map is still
|
// when the user is dragging, it only cache when the map is still
|
||||||
if (!this.animator.isRunning() && this.getKey() === this.prevRenderedKey) {
|
if (!this.animator.isRunning() && this.key === this.prevRenderedKey) {
|
||||||
var tile_size = this.renderer.TILE_SIZE;
|
var tile_size = this.renderer.TILE_SIZE;
|
||||||
for(t in this._tiles) {
|
for(t in this._tiles) {
|
||||||
tile = this._tiles[t];
|
tile = this._tiles[t];
|
||||||
@ -290,7 +261,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.prevRenderedKey = this.getKey();
|
this.prevRenderedKey = this.key;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -300,35 +271,11 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
* accumulated
|
* accumulated
|
||||||
*/
|
*/
|
||||||
setKey: function(key, options) {
|
setKey: function(key, options) {
|
||||||
this.setKeys([key], options);
|
this.key = key;
|
||||||
},
|
this.animator.step(key);
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the array of keys being rendered
|
|
||||||
*/
|
|
||||||
getKeys: function() {
|
|
||||||
return this.keys;
|
|
||||||
},
|
|
||||||
|
|
||||||
setKeys: function(keys, options) {
|
|
||||||
this.keys = keys;
|
|
||||||
this.animator.step(this.getKey());
|
|
||||||
this._clearTileCaches();
|
this._clearTileCaches();
|
||||||
this.redraw(options && options.direct);
|
this.redraw(options && options.direct);
|
||||||
this.fire('change:time', {
|
this.fire('change:time', { time: this.getTime(), step: this.key });
|
||||||
time: this.getTime(),
|
|
||||||
step: this.getKey(),
|
|
||||||
start: this.getKey(),
|
|
||||||
end: this.getLastKey()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
getKey: function() {
|
|
||||||
return this.keys[0];
|
|
||||||
},
|
|
||||||
|
|
||||||
getLastKey: function() {
|
|
||||||
return this.keys[this.keys.length - 1];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -342,20 +289,6 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
this.setKey(time);
|
this.setKey(time);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderRange: function(start, end) {
|
|
||||||
this.pause();
|
|
||||||
var keys = [];
|
|
||||||
for (var i = start; i <= end; i++) {
|
|
||||||
keys.push(i);
|
|
||||||
}
|
|
||||||
this.setKeys(keys);
|
|
||||||
},
|
|
||||||
|
|
||||||
resetRenderRange: function() {
|
|
||||||
this.stop();
|
|
||||||
this.play();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* transform from animation step to Date object
|
* transform from animation step to Date object
|
||||||
* that contains the animation time
|
* that contains the animation time
|
||||||
@ -377,7 +310,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getStep: function() {
|
getStep: function() {
|
||||||
return this.getKey();
|
return this.key;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -385,7 +318,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
* in the defined column. Date object
|
* in the defined column. Date object
|
||||||
*/
|
*/
|
||||||
getTime: function() {
|
getTime: function() {
|
||||||
return this.stepToTime(this.getKey());
|
return this.stepToTime(this.key);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -399,16 +332,13 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
* set the cartocss for the current renderer
|
* set the cartocss for the current renderer
|
||||||
*/
|
*/
|
||||||
setCartoCSS: function(cartocss) {
|
setCartoCSS: function(cartocss) {
|
||||||
|
if (this.provider.options.named_map) throw new Error("CartoCSS style on named maps is read-only");
|
||||||
if (!this.renderer) throw new Error('renderer is not valid');
|
if (!this.renderer) throw new Error('renderer is not valid');
|
||||||
|
var shader = new carto.RendererJS().render(cartocss);
|
||||||
|
this.renderer.setShader(shader);
|
||||||
|
|
||||||
if (this.provider && this.provider.options.named_map) {
|
|
||||||
console.log('Torque layer: CartoCSS style on named maps is read-only');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.renderer.setCartoCSS(cartocss, function () {
|
|
||||||
// provider options
|
// provider options
|
||||||
var options = torque.common.TorqueLayer.optionsFromLayer(this.renderer._shader.findLayer({ name: 'Map' }));
|
var options = torque.common.TorqueLayer.optionsFromLayer(shader.findLayer({ name: 'Map' }));
|
||||||
this.provider.setCartoCSS && this.provider.setCartoCSS(cartocss);
|
this.provider.setCartoCSS && this.provider.setCartoCSS(cartocss);
|
||||||
if(this.provider.setOptions(options)) {
|
if(this.provider.setOptions(options)) {
|
||||||
this._reloadTiles();
|
this._reloadTiles();
|
||||||
@ -423,8 +353,6 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
this._clearCaches();
|
this._clearCaches();
|
||||||
this.redraw();
|
this.redraw();
|
||||||
return this;
|
return this;
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,25 +369,11 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
return positions;
|
return positions;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* return an array with the values for all the pixels active for the step
|
|
||||||
*/
|
|
||||||
getValues: function(step) {
|
|
||||||
var values = [];
|
|
||||||
step = step === undefined ? this.getKey(): step;
|
|
||||||
var t, tile;
|
|
||||||
for(t in this._tiles) {
|
|
||||||
tile = this._tiles[t];
|
|
||||||
this.renderer.getValues(tile, step, values);
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the value for position relative to map coordinates. null for no value
|
* return the value for position relative to map coordinates. null for no value
|
||||||
*/
|
*/
|
||||||
getValueForPos: function(x, y, step) {
|
getValueForPos: function(x, y, step) {
|
||||||
step = step === undefined ? this.getKey(): step;
|
step = step === undefined ? this.key: step;
|
||||||
var t, tile, pos, value = null, xx, yy;
|
var t, tile, pos, value = null, xx, yy;
|
||||||
for(t in this._tiles) {
|
for(t in this._tiles) {
|
||||||
tile = this._tiles[t];
|
tile = this._tiles[t];
|
||||||
@ -494,38 +408,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
|
|||||||
return sum;
|
return sum;
|
||||||
},
|
},
|
||||||
|
|
||||||
/** return the number of points for a step */
|
|
||||||
pointCount: function(step) {
|
|
||||||
var t, tile;
|
|
||||||
step = step === undefined ? this.key: step;
|
|
||||||
var c = 0;
|
|
||||||
for(t in this._tiles) {
|
|
||||||
tile = this._tiles[t];
|
|
||||||
if (tile) {
|
|
||||||
c += tile.timeCount[step];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
},
|
|
||||||
|
|
||||||
invalidate: function() {
|
invalidate: function() {
|
||||||
this.provider.reload();
|
this.provider.reload();
|
||||||
},
|
|
||||||
|
|
||||||
setStepsRange: function(start, end) {
|
|
||||||
this.animator.stepsRange(start, end);
|
|
||||||
},
|
|
||||||
|
|
||||||
removeStepsRange: function() {
|
|
||||||
this.animator.removeCustomStepsRange();
|
|
||||||
},
|
|
||||||
|
|
||||||
getStepsRange: function() {
|
|
||||||
return this.animator.stepsRange();
|
|
||||||
},
|
|
||||||
|
|
||||||
onRemove: function(map) {
|
|
||||||
L.CanvasLayer.prototype.onRemove.apply(this, arguments);
|
|
||||||
this.animator.stop();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,131 +0,0 @@
|
|||||||
require('./ol_tileloader_mixin');
|
|
||||||
|
|
||||||
ol.CanvasLayer = function(options) {
|
|
||||||
this.root_ = document.createElement('div');
|
|
||||||
this.root_.setAttribute('class', 'ol-heatmap-layer');
|
|
||||||
|
|
||||||
this.options = {
|
|
||||||
subdomains: 'abc',
|
|
||||||
errorTileUrl: '',
|
|
||||||
attribution: '',
|
|
||||||
opacity: 1,
|
|
||||||
tileLoader: false, // installs tile loading events
|
|
||||||
tileSize: 256
|
|
||||||
};
|
|
||||||
|
|
||||||
options = options || {};
|
|
||||||
torque.extend(this.options, options);
|
|
||||||
|
|
||||||
ol.TileLoader.call(this, this.options.tileSize, this.options.maxZoom);
|
|
||||||
|
|
||||||
this.render = this.render.bind(this);
|
|
||||||
this._canvas = this._createCanvas();
|
|
||||||
|
|
||||||
this.root_.appendChild(this._canvas);
|
|
||||||
|
|
||||||
this._ctx = this._canvas.getContext('2d');
|
|
||||||
this.currentAnimationFrame = -1;
|
|
||||||
this.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
|
|
||||||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {
|
|
||||||
return window.setTimeout(callback, 1000 / 60);
|
|
||||||
};
|
|
||||||
this.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame ||
|
|
||||||
window.webkitCancelAnimationFrame || window.msCancelAnimationFrame || function (id) {
|
|
||||||
clearTimeout(id);
|
|
||||||
};
|
|
||||||
|
|
||||||
if(options.map){
|
|
||||||
this.setMap(options.map);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.inherits(ol.CanvasLayer, ol.TileLoader);
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype.setMap = function(map){
|
|
||||||
if(this._map){
|
|
||||||
//remove
|
|
||||||
this._map.unByKey(this.pointdragKey_);
|
|
||||||
this._map.unByKey(this.sizeChangedKey_);
|
|
||||||
this._map.unByKey(this.moveendKey_);
|
|
||||||
this._map.getView().unByKey(this.centerChanged_);
|
|
||||||
}
|
|
||||||
this._map = map;
|
|
||||||
|
|
||||||
if(map){
|
|
||||||
var overlayContainer = this._map.getViewport().getElementsByClassName("ol-overlaycontainer")[0];
|
|
||||||
overlayContainer.appendChild(this.root_);
|
|
||||||
|
|
||||||
this.pointdragKey_ = map.on('pointerdrag', this._render, this);
|
|
||||||
this.moveendKey_ = map.on("moveend", this._render, this);
|
|
||||||
this.centerChanged_ = map.getView().on("change:center", this._render, this);
|
|
||||||
this.sizeChangedKey_ = map.on('change:size', this._reset, this);
|
|
||||||
|
|
||||||
if(this.options.tileLoader) {
|
|
||||||
ol.TileLoader.prototype._initTileLoader.call(this, map);
|
|
||||||
}
|
|
||||||
this._reset();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype._createCanvas = function() {
|
|
||||||
var canvas;
|
|
||||||
canvas = document.createElement('canvas');
|
|
||||||
canvas.style.position = 'absolute';
|
|
||||||
canvas.style.top = 0;
|
|
||||||
canvas.style.left = 0;
|
|
||||||
canvas.style.pointerEvents = "none";
|
|
||||||
canvas.style.zIndex = this.options.zIndex || 0;
|
|
||||||
return canvas;
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype._reset = function () {
|
|
||||||
this._resize();
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype._resize = function() {
|
|
||||||
var size = this._map.getSize();
|
|
||||||
var width = size[0];
|
|
||||||
var height = size[1];
|
|
||||||
var oldWidth = this._canvas.width;
|
|
||||||
var oldHeight = this._canvas.height;
|
|
||||||
|
|
||||||
// resizing may allocate a new back buffer, so do so conservatively
|
|
||||||
if (oldWidth !== width || oldHeight !== height) {
|
|
||||||
this._canvas.width = width;
|
|
||||||
this._canvas.height = height;
|
|
||||||
this._canvas.style.width = width + 'px';
|
|
||||||
this._canvas.style.height = height + 'px';
|
|
||||||
this.root_.style.width = width + 'px';
|
|
||||||
this.root_.style.height = height + 'px';
|
|
||||||
this._render();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype._render = function() {
|
|
||||||
if (this.currentAnimationFrame >= 0) {
|
|
||||||
this.cancelAnimationFrame.call(window, this.currentAnimationFrame);
|
|
||||||
}
|
|
||||||
this.currentAnimationFrame = this.requestAnimationFrame.call(window, this.render);
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype.getCanvas = function() {
|
|
||||||
return this._canvas;
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype.getAttribution = function() {
|
|
||||||
return this.options.attribution;
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype.draw = function() {
|
|
||||||
return this._render();
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.CanvasLayer.prototype.redraw = function(direct) {
|
|
||||||
if (direct) {
|
|
||||||
this.render();
|
|
||||||
} else {
|
|
||||||
this._render();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = ol.CanvasLayer;
|
|
@ -1,3 +0,0 @@
|
|||||||
if (typeof ol !== 'undefined') {
|
|
||||||
require('./torque');
|
|
||||||
}
|
|
@ -1,169 +0,0 @@
|
|||||||
ol.TileLoader = function(tileSize, maxZoom){
|
|
||||||
this._tileSize = tileSize;
|
|
||||||
this._tiles = {};
|
|
||||||
this._tilesLoading = {};
|
|
||||||
this._tilesToLoad = 0;
|
|
||||||
this._updateTiles = this._updateTiles.bind(this);
|
|
||||||
|
|
||||||
this._tileGrid = ol.tilegrid.createXYZ({
|
|
||||||
maxZoom: maxZoom,
|
|
||||||
tileSize: tileSize
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._initTileLoader = function(map) {
|
|
||||||
this._map = map;
|
|
||||||
this._view = map.getView();
|
|
||||||
this._centerChangedId = this._view.on("change:center", function(e){
|
|
||||||
this._updateTiles();
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this._postcomposeKey = undefined;
|
|
||||||
|
|
||||||
this._resolutionChangedId = this._view.on("change:resolution", function(evt){
|
|
||||||
this._currentResolution = this._view.getResolution();
|
|
||||||
if(this._postcomposeKey) return;
|
|
||||||
this.fire("mapZoomStart");
|
|
||||||
this._postcomposeKey = this._map.on("postcompose", function(evt) {
|
|
||||||
if(evt.frameState.viewState.resolution === this._currentResolution){
|
|
||||||
this._updateTiles();
|
|
||||||
this._map.unByKey(this._postcomposeKey);
|
|
||||||
this._postcomposeKey = undefined;
|
|
||||||
this.fire("mapZoomEnd");
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this._updateTiles();
|
|
||||||
};
|
|
||||||
ol.TileLoader.prototype._removeTileLoader = function() {
|
|
||||||
this._view.unByKey(this._centerChangedId);
|
|
||||||
this._view.unByKey(this._resolutionChangedId );
|
|
||||||
|
|
||||||
this._removeTiles();
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._removeTiles = function () {
|
|
||||||
for (var key in this._tiles) {
|
|
||||||
this._removeTile(key);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._reloadTiles = function() {
|
|
||||||
this._removeTiles();
|
|
||||||
this._updateTiles();
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._updateTiles = function () {
|
|
||||||
if (!this._map) { return; }
|
|
||||||
|
|
||||||
var zoom = this._tileGrid.getZForResolution(this._view.getResolution());
|
|
||||||
var extent = this._view.calculateExtent(this._map.getSize());
|
|
||||||
|
|
||||||
var tileRange = this._requestTilesForExtentAndZ(extent, zoom);
|
|
||||||
this._removeOtherTiles(tileRange);
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._removeOtherTiles = function(tileRange) {
|
|
||||||
var kArr, x, y, z, key;
|
|
||||||
|
|
||||||
var zoom = this._tileGrid.getZForResolution(this._view.getResolution());
|
|
||||||
|
|
||||||
for (key in this._tiles) {
|
|
||||||
if (this._tiles.hasOwnProperty(key)) {
|
|
||||||
kArr = key.split(':');
|
|
||||||
x = parseInt(kArr[0], 10);
|
|
||||||
y = parseInt(kArr[1], 10);
|
|
||||||
z = parseInt(kArr[2], 10);
|
|
||||||
|
|
||||||
// remove tile if it's out of bounds
|
|
||||||
if (z !== zoom || x < tileRange.minX || x > tileRange.maxX || ((-y-1) < tileRange.minY) || (-y-1) > tileRange.maxY) {
|
|
||||||
this._removeTile(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._removeTile = function (key) {
|
|
||||||
this.fire('tileRemoved', this._tiles[key]);
|
|
||||||
delete this._tiles[key];
|
|
||||||
delete this._tilesLoading[key];
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._tileKey = function(tilePoint) {
|
|
||||||
return tilePoint.x + ':' + tilePoint.y + ':' + tilePoint.zoom;
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._tileShouldBeLoaded = function (tilePoint) {
|
|
||||||
var k = this._tileKey(tilePoint);
|
|
||||||
return !(k in this._tiles) && !(k in this._tilesLoading);
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._removeFromTilesLoading = function(tilePoint){
|
|
||||||
this._tilesToLoad--;
|
|
||||||
var k = this._tileKey(tilePoint);
|
|
||||||
delete this._tilesLoading[k];
|
|
||||||
if(this._tilesToLoad === 0) {
|
|
||||||
this.fire("tilesLoaded");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._tileLoaded = function(tilePoint, tileData) {
|
|
||||||
var k = this._tileKey(tilePoint);
|
|
||||||
this._tiles[k] = tileData;
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype.getTilePos = function (tilePoint) {
|
|
||||||
var zoom = this._tileGrid.getZForResolution(this._view.getResolution());
|
|
||||||
var extent = this._tileGrid.getTileCoordExtent([zoom, tilePoint.x, -tilePoint.y-1]);
|
|
||||||
var topLeft = this._map.getPixelFromCoordinate([extent[0], extent[3]]);
|
|
||||||
|
|
||||||
return {
|
|
||||||
x: topLeft[0],
|
|
||||||
y: topLeft[1]
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TileLoader.prototype._requestTilesForExtentAndZ = function (extent, zoom) {
|
|
||||||
var queue = [];
|
|
||||||
var tileCoords = [];
|
|
||||||
|
|
||||||
this._tileGrid.forEachTileCoord(extent, zoom, function(coord){
|
|
||||||
tileCoords.push(coord);
|
|
||||||
var point = {
|
|
||||||
x: coord[1],
|
|
||||||
y: -coord[2] - 1,
|
|
||||||
zoom: coord[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this._tileShouldBeLoaded(point)) {
|
|
||||||
queue.push(point);
|
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
var tilesToLoad = queue.length;
|
|
||||||
if (tilesToLoad > 0) {
|
|
||||||
this._tilesToLoad += tilesToLoad;
|
|
||||||
|
|
||||||
for (var i = 0; i < tilesToLoad; i++) {
|
|
||||||
var t = queue[i];
|
|
||||||
var k = this._tileKey(t);
|
|
||||||
this._tilesLoading[k] = t;
|
|
||||||
// events
|
|
||||||
this.fire('tileAdded', t);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fire("tilesLoading");
|
|
||||||
}
|
|
||||||
|
|
||||||
var tileRange = {
|
|
||||||
minX : tileCoords[0][1],
|
|
||||||
maxX : tileCoords [tileCoords.length - 1][1],
|
|
||||||
minY : tileCoords[0][2],
|
|
||||||
maxY : tileCoords [tileCoords.length - 1] [2]
|
|
||||||
};
|
|
||||||
|
|
||||||
return tileRange;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = ol.TileLoader;
|
|
@ -1,443 +0,0 @@
|
|||||||
var carto = global.carto || require('carto');
|
|
||||||
var torque = require('../');
|
|
||||||
require('./canvas_layer');
|
|
||||||
|
|
||||||
ol.TorqueLayer = function(options){
|
|
||||||
var self = this;
|
|
||||||
if (!torque.isBrowserSupported()) {
|
|
||||||
throw new Error("browser is not supported by torque");
|
|
||||||
}
|
|
||||||
options.tileLoader = true;
|
|
||||||
this.keys = [0];
|
|
||||||
Object.defineProperty(this, 'key', {
|
|
||||||
get: function() {
|
|
||||||
return this.getKey();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.prevRenderedKey = 0;
|
|
||||||
if (options.cartocss) {
|
|
||||||
torque.extend(options, torque.common.TorqueLayer.optionsFromCartoCSS(options.cartocss));
|
|
||||||
}
|
|
||||||
|
|
||||||
options.resolution = options.resolution || 2;
|
|
||||||
options.steps = options.steps || 100;
|
|
||||||
options.visible = options.visible === undefined ? true: options.visible;
|
|
||||||
this.hidden = !options.visible;
|
|
||||||
|
|
||||||
this.animator = new torque.Animator(function(time) {
|
|
||||||
var k = time | 0;
|
|
||||||
if(self.getKey() !== k) {
|
|
||||||
self.setKey(k, { direct: true });
|
|
||||||
}
|
|
||||||
}, torque.extend(torque.clone(options), {
|
|
||||||
onPause: function() {
|
|
||||||
self.fire('pause');
|
|
||||||
},
|
|
||||||
onStop: function() {
|
|
||||||
self.fire('stop');
|
|
||||||
},
|
|
||||||
onStart: function() {
|
|
||||||
self.fire('play');
|
|
||||||
},
|
|
||||||
onStepsRange: function() {
|
|
||||||
self.fire('change:stepsRange', self.animator.stepsRange());
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
this.play = this.animator.start.bind(this.animator);
|
|
||||||
this.stop = this.animator.stop.bind(this.animator);
|
|
||||||
this.pause = this.animator.pause.bind(this.animator);
|
|
||||||
this.toggle = this.animator.toggle.bind(this.animator);
|
|
||||||
this.setDuration = this.animator.duration.bind(this.animator);
|
|
||||||
this.isRunning = this.animator.isRunning.bind(this.animator);
|
|
||||||
|
|
||||||
|
|
||||||
ol.CanvasLayer.call(this, options);
|
|
||||||
|
|
||||||
this.options.renderer = this.options.renderer || 'point';
|
|
||||||
this.options.provider = this.options.provider || 'windshaft';
|
|
||||||
|
|
||||||
if (this.options.tileJSON) this.options.provider = 'tileJSON';
|
|
||||||
|
|
||||||
this.provider = new this.providers[this.options.provider](options);
|
|
||||||
this.renderer = new this.renderers[this.options.renderer](this.getCanvas(), options);
|
|
||||||
|
|
||||||
options.ready = function() {
|
|
||||||
self.fire("change:bounds", {
|
|
||||||
bounds: self.provider.getBounds()
|
|
||||||
});
|
|
||||||
self.animator.steps(self.provider.getSteps());
|
|
||||||
self.animator.rescale();
|
|
||||||
self.fire('change:steps', {
|
|
||||||
steps: self.provider.getSteps()
|
|
||||||
});
|
|
||||||
self.setKeys(self.getKeys());
|
|
||||||
};
|
|
||||||
|
|
||||||
this.renderer.on("allIconsLoaded", this.render.bind(this));
|
|
||||||
|
|
||||||
|
|
||||||
// for each tile shown on the map request the data
|
|
||||||
this.on('tileAdded', function(t) {
|
|
||||||
var tileData = this.provider.getTileData(t, t.zoom, function(tileData) {
|
|
||||||
self._removeFromTilesLoading(t);
|
|
||||||
if (t.zoom !== self._tileGrid.getZForResolution(self._view.getResolution())) return;
|
|
||||||
self._tileLoaded(t, tileData);
|
|
||||||
self.fire('tileLoaded');
|
|
||||||
if (tileData) {
|
|
||||||
self.redraw();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this.on('mapZoomStart', function(){
|
|
||||||
this.getCanvas().style.display = "none";
|
|
||||||
this._pauseOnZoom();
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this.on('mapZoomEnd', function() {
|
|
||||||
this.getCanvas().style.display = "block";
|
|
||||||
this._resumeOnZoom();
|
|
||||||
}, this);
|
|
||||||
};
|
|
||||||
|
|
||||||
ol.TorqueLayer.prototype = torque.extend({},
|
|
||||||
ol.CanvasLayer.prototype,
|
|
||||||
torque.Event,
|
|
||||||
{
|
|
||||||
providers: {
|
|
||||||
'sql_api': torque.providers.json,
|
|
||||||
'url_template': torque.providers.JsonArray,
|
|
||||||
'windshaft': torque.providers.windshaft,
|
|
||||||
'tileJSON': torque.providers.tileJSON
|
|
||||||
},
|
|
||||||
|
|
||||||
renderers: {
|
|
||||||
'point': torque.renderer.Point,
|
|
||||||
'pixel': torque.renderer.Rectangle
|
|
||||||
},
|
|
||||||
|
|
||||||
onAdd: function(map){
|
|
||||||
ol.CanvasLayer.prototype.setMap.call(this, map);
|
|
||||||
},
|
|
||||||
|
|
||||||
onRemove: function(map) {
|
|
||||||
this.fire('remove');
|
|
||||||
this._removeTileLoader();
|
|
||||||
},
|
|
||||||
|
|
||||||
_pauseOnZoom: function() {
|
|
||||||
this.wasRunning = this.isRunning();
|
|
||||||
if (this.wasRunning) {
|
|
||||||
this.pause();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_resumeOnZoom: function() {
|
|
||||||
if (this.wasRunning) {
|
|
||||||
this.play();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
hide: function() {
|
|
||||||
if(this.hidden) return this;
|
|
||||||
this.pause();
|
|
||||||
this.clear();
|
|
||||||
this.hidden = true;
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
show: function() {
|
|
||||||
if(!this.hidden) return this;
|
|
||||||
this.hidden = false;
|
|
||||||
this.play();
|
|
||||||
if (this.options.steps === 1){
|
|
||||||
this.redraw();
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
setSQL: function(sql) {
|
|
||||||
if (this.provider.options.named_map) throw new Error("SQL queries on named maps are read-only");
|
|
||||||
if (!this.provider || !this.provider.setSQL) {
|
|
||||||
throw new Error("this provider does not support SQL");
|
|
||||||
}
|
|
||||||
this.provider.setSQL(sql);
|
|
||||||
this._reloadTiles();
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
setBlendMode: function(_) {
|
|
||||||
this.renderer.setBlendMode(_);
|
|
||||||
this.redraw();
|
|
||||||
},
|
|
||||||
|
|
||||||
setSteps: function(steps) {
|
|
||||||
this.provider.setSteps(steps);
|
|
||||||
this._reloadTiles();
|
|
||||||
},
|
|
||||||
|
|
||||||
setColumn: function(column, isTime) {
|
|
||||||
this.provider.setColumn(column, isTime);
|
|
||||||
this._reloadTiles();
|
|
||||||
},
|
|
||||||
|
|
||||||
getTimeBounds: function() {
|
|
||||||
return this.provider && this.provider.getKeySpan();
|
|
||||||
},
|
|
||||||
|
|
||||||
clear: function() {
|
|
||||||
var canvas = this.getCanvas();
|
|
||||||
canvas.width = canvas.width;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* render the selectef key
|
|
||||||
* don't call this function directly, it's called by
|
|
||||||
* requestAnimationFrame. Use redraw to refresh it
|
|
||||||
*/
|
|
||||||
render: function() {
|
|
||||||
if(this.hidden) return;
|
|
||||||
var t, tile, pos;
|
|
||||||
var canvas = this.getCanvas();
|
|
||||||
this.renderer.clearCanvas();
|
|
||||||
var ctx = canvas.getContext('2d');
|
|
||||||
|
|
||||||
// renders only a "frame"
|
|
||||||
for(t in this._tiles) {
|
|
||||||
tile = this._tiles[t];
|
|
||||||
if (tile) {
|
|
||||||
pos = this.getTilePos(tile.coord);
|
|
||||||
ctx.setTransform(1, 0, 0, 1, pos.x, pos.y);
|
|
||||||
this.renderer.renderTile(tile, this.keys);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.renderer.applyFilters();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set key to be shown. If it's a single value
|
|
||||||
* it renders directly, if it's an array it renders
|
|
||||||
* accumulated
|
|
||||||
*/
|
|
||||||
setKey: function(key, options) {
|
|
||||||
this.setKeys([key], options);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the array of keys being rendered
|
|
||||||
*/
|
|
||||||
getKeys: function() {
|
|
||||||
return this.keys;
|
|
||||||
},
|
|
||||||
|
|
||||||
setKeys: function(keys, options) {
|
|
||||||
this.keys = keys;
|
|
||||||
this.animator.step(this.getKey());
|
|
||||||
this.redraw(options && options.direct);
|
|
||||||
this.fire('change:time', {
|
|
||||||
time: this.getTime(),
|
|
||||||
step: this.getKey(),
|
|
||||||
start: this.getKey(),
|
|
||||||
end: this.getLastKey()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
getKey: function() {
|
|
||||||
return this.keys[0];
|
|
||||||
},
|
|
||||||
|
|
||||||
getLastKey: function() {
|
|
||||||
return this.keys[this.keys.length - 1];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* helper function, does the same than ``setKey`` but only
|
|
||||||
* accepts scalars.
|
|
||||||
*/
|
|
||||||
setStep: function(time) {
|
|
||||||
if(time === undefined || time.length !== undefined) {
|
|
||||||
throw new Error("setTime only accept scalars");
|
|
||||||
}
|
|
||||||
this.setKey(time);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderRange: function(start, end) {
|
|
||||||
this.pause();
|
|
||||||
var keys = [];
|
|
||||||
for (var i = start; i <= end; i++) {
|
|
||||||
keys.push(i);
|
|
||||||
}
|
|
||||||
this.setKeys(keys);
|
|
||||||
},
|
|
||||||
|
|
||||||
resetRenderRange: function() {
|
|
||||||
this.stop();
|
|
||||||
this.play();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* transform from animation step to Date object
|
|
||||||
* that contains the animation time
|
|
||||||
*
|
|
||||||
* ``step`` should be between 0 and ``steps - 1``
|
|
||||||
*/
|
|
||||||
stepToTime: function(step) {
|
|
||||||
var times = this.provider.getKeySpan();
|
|
||||||
var time = times.start + (times.end - times.start)*(step/this.provider.getSteps());
|
|
||||||
return new Date(time);
|
|
||||||
},
|
|
||||||
|
|
||||||
timeToStep: function(timestamp) {
|
|
||||||
if (typeof timestamp === "Date") timestamp = timestamp.getTime();
|
|
||||||
if (!this.provider) return 0;
|
|
||||||
var times = this.provider.getKeySpan();
|
|
||||||
var step = (this.provider.getSteps() * (timestamp - times.start)) / (times.end - times.start);
|
|
||||||
return step;
|
|
||||||
},
|
|
||||||
|
|
||||||
getStep: function() {
|
|
||||||
return this.getKey();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the animation time defined by the data
|
|
||||||
* in the defined column. Date object
|
|
||||||
*/
|
|
||||||
getTime: function() {
|
|
||||||
return this.stepToTime(this.getKey());
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns an object with the start and end times
|
|
||||||
*/
|
|
||||||
getTimeSpan: function() {
|
|
||||||
return this.provider.getKeySpan();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the cartocss for the current renderer
|
|
||||||
*/
|
|
||||||
setCartoCSS: function(cartocss) {
|
|
||||||
if (this.provider.options.named_map) throw new Error("CartoCSS style on named maps is read-only");
|
|
||||||
if (!this.renderer) throw new Error('renderer is not valid');
|
|
||||||
var shader = new carto.RendererJS().render(cartocss);
|
|
||||||
this.renderer.setShader(shader);
|
|
||||||
|
|
||||||
// provider options
|
|
||||||
var options = torque.common.TorqueLayer.optionsFromLayer(shader.findLayer({ name: 'Map' }));
|
|
||||||
this.provider.setCartoCSS && this.provider.setCartoCSS(cartocss);
|
|
||||||
if(this.provider.setOptions(options)) {
|
|
||||||
this._reloadTiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
torque.extend(this.options, options);
|
|
||||||
|
|
||||||
// animator options
|
|
||||||
if (options.animationDuration) {
|
|
||||||
this.animator.duration(options.animationDuration);
|
|
||||||
}
|
|
||||||
this.redraw();
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get active points for a step in active zoom
|
|
||||||
* returns a list of bounding boxes [[] , [], []]
|
|
||||||
* empty list if there is no active pixels
|
|
||||||
*/
|
|
||||||
getActivePointsBBox: function(step) {
|
|
||||||
var positions = [];
|
|
||||||
for(var t in this._tiles) {
|
|
||||||
var tile = this._tiles[t];
|
|
||||||
positions = positions.concat(this.renderer.getActivePointsBBox(tile, step));
|
|
||||||
}
|
|
||||||
return positions;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return an array with the values for all the pixels active for the step
|
|
||||||
*/
|
|
||||||
getValues: function(step) {
|
|
||||||
var values = [];
|
|
||||||
step = step === undefined ? this.getKey(): step;
|
|
||||||
var t, tile;
|
|
||||||
for(t in this._tiles) {
|
|
||||||
tile = this._tiles[t];
|
|
||||||
this.renderer.getValues(tile, step, values);
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return the value for position relative to map coordinates. null for no value
|
|
||||||
*/
|
|
||||||
getValueForPos: function(x, y, step) {
|
|
||||||
step = step === undefined ? this.getKey(): step;
|
|
||||||
var t, tile, pos, value = null, xx, yy;
|
|
||||||
for(t in this._tiles) {
|
|
||||||
tile = this._tiles[t];
|
|
||||||
pos = this.getTilePos(tile.coord);
|
|
||||||
xx = x - pos.x;
|
|
||||||
yy = y - pos.y;
|
|
||||||
if (xx >= 0 && yy >= 0 && xx < this.renderer.TILE_SIZE && yy <= this.renderer.TILE_SIZE) {
|
|
||||||
value = this.renderer.getValueFor(tile, step, xx, yy);
|
|
||||||
}
|
|
||||||
if (value !== null) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
|
|
||||||
getValueForBBox: function(x, y, w, h) {
|
|
||||||
var xf = x + w, yf = y + h, _x=x;
|
|
||||||
var sum = 0;
|
|
||||||
for(_y = y; _y<yf; _y+=this.options.resolution){
|
|
||||||
for(_x = x; _x<xf; _x+=this.options.resolution){
|
|
||||||
var thisValue = this.getValueForPos(_x,_y);
|
|
||||||
if (thisValue){
|
|
||||||
var bb = thisValue.bbox;
|
|
||||||
var xy = this._map.latLngToContainerPoint([bb[1].lat, bb[1].lon]);
|
|
||||||
if(xy.x < xf && xy.y < yf){
|
|
||||||
sum += thisValue.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
},
|
|
||||||
|
|
||||||
/** return the number of points for a step */
|
|
||||||
pointCount: function(step) {
|
|
||||||
var t, tile;
|
|
||||||
step = step === undefined ? this.key: step;
|
|
||||||
var c = 0;
|
|
||||||
for(t in this._tiles) {
|
|
||||||
tile = this._tiles[t];
|
|
||||||
if (tile) {
|
|
||||||
c += tile.timeCount[step];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
},
|
|
||||||
|
|
||||||
invalidate: function() {
|
|
||||||
this.provider.reload();
|
|
||||||
},
|
|
||||||
|
|
||||||
setStepsRange: function(start, end) {
|
|
||||||
this.animator.stepsRange(start, end);
|
|
||||||
},
|
|
||||||
|
|
||||||
removeStepsRange: function() {
|
|
||||||
this.animator.removeCustomStepsRange();
|
|
||||||
},
|
|
||||||
|
|
||||||
getStepsRange: function() {
|
|
||||||
return this.animator.stepsRange();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = ol.TorqueLayer;
|
|
@ -1,6 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
json: require('./json'),
|
json: require('./json'),
|
||||||
JsonArray: require('./jsonarray'),
|
JsonArray: require('./jsonarray'),
|
||||||
windshaft: require('./windshaft'),
|
windshaft: require('./windshaft')
|
||||||
tileJSON: require('./tilejson')
|
|
||||||
};
|
};
|
||||||
|
@ -1,339 +0,0 @@
|
|||||||
var torque = require('../');
|
|
||||||
|
|
||||||
var Uint8Array = torque.types.Uint8Array;
|
|
||||||
var Int32Array = torque.types.Int32Array;
|
|
||||||
var Uint32Array = torque.types.Uint32Array;
|
|
||||||
var Uint8ClampedArray = torque.types.Uint8ClampedArray;
|
|
||||||
|
|
||||||
// format('hello, {0}', 'rambo') -> "hello, rambo"
|
|
||||||
function format(str) {
|
|
||||||
for(var i = 1; i < arguments.length; ++i) {
|
|
||||||
var attrs = arguments[i];
|
|
||||||
for(var attr in attrs) {
|
|
||||||
str = str.replace(RegExp('\\{' + attr + '\\}', 'g'), attrs[attr]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
var tileJSON = function (options) {
|
|
||||||
this._ready = false;
|
|
||||||
this._tileQueue = [];
|
|
||||||
this.options = options;
|
|
||||||
|
|
||||||
this.options.coordinates_data_type = this.options.coordinates_data_type || Uint8Array;
|
|
||||||
|
|
||||||
if (this.options.data_aggregation) {
|
|
||||||
this.options.cumulative = this.options.data_aggregation === 'cumulative';
|
|
||||||
}
|
|
||||||
if (this.options.auth_token) {
|
|
||||||
var e = this.options.extra_params || (this.options.extra_params = {});
|
|
||||||
e.auth_token = this.options.auth_token;
|
|
||||||
}
|
|
||||||
if (!this.options.no_fetch_map) {
|
|
||||||
this._fetchMap();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
tileJSON.prototype = {
|
|
||||||
|
|
||||||
NAME: "tileJSON",
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return the torque tile encoded in an efficient javascript
|
|
||||||
* structure:
|
|
||||||
* {
|
|
||||||
* x:Uint8Array x coordinates in tile reference system, normally from 0-255
|
|
||||||
* y:Uint8Array y coordinates in tile reference system
|
|
||||||
* Index: Array index to the properties
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
proccessTile: function(rows, coord, zoom) {
|
|
||||||
var r;
|
|
||||||
var x = new this.options.coordinates_data_type(rows.length);
|
|
||||||
var y = new this.options.coordinates_data_type(rows.length);
|
|
||||||
|
|
||||||
// count number of dates
|
|
||||||
var dates = 0;
|
|
||||||
var maxDateSlots = -1;
|
|
||||||
for (r = 0; r < rows.length; ++r) {
|
|
||||||
var row = rows[r];
|
|
||||||
dates += row.dates__uint16.length;
|
|
||||||
for(var d = 0; d < row.dates__uint16.length; ++d) {
|
|
||||||
maxDateSlots = Math.max(maxDateSlots, row.dates__uint16[d]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.options.cumulative) {
|
|
||||||
dates = (1 + maxDateSlots) * rows.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
var type = this.options.cumulative ? Uint32Array: Uint8ClampedArray;
|
|
||||||
|
|
||||||
// reserve memory for all the dates
|
|
||||||
var timeIndex = new Int32Array(maxDateSlots + 1); //index-size
|
|
||||||
var timeCount = new Int32Array(maxDateSlots + 1);
|
|
||||||
var renderData = new (this.options.valueDataType || type)(dates);
|
|
||||||
var renderDataPos = new Uint32Array(dates);
|
|
||||||
|
|
||||||
var rowsPerSlot = {};
|
|
||||||
|
|
||||||
// precache pixel positions
|
|
||||||
for (var r = 0; r < rows.length; ++r) {
|
|
||||||
var row = rows[r];
|
|
||||||
x[r] = row.x__uint8 * this.options.resolution;
|
|
||||||
y[r] = row.y__uint8 * this.options.resolution;
|
|
||||||
|
|
||||||
var dates = row.dates__uint16;
|
|
||||||
var vals = row.vals__uint8;
|
|
||||||
if (!this.options.cumulative) {
|
|
||||||
for (var j = 0, len = dates.length; j < len; ++j) {
|
|
||||||
var rr = rowsPerSlot[dates[j]] || (rowsPerSlot[dates[j]] = []);
|
|
||||||
if(this.options.cumulative) {
|
|
||||||
vals[j] += prev_val;
|
|
||||||
}
|
|
||||||
prev_val = vals[j];
|
|
||||||
rr.push([r, vals[j]]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var valByDate = {}
|
|
||||||
for (var j = 0, len = dates.length; j < len; ++j) {
|
|
||||||
valByDate[dates[j]] = vals[j];
|
|
||||||
}
|
|
||||||
var accum = 0;
|
|
||||||
|
|
||||||
// extend the latest to the end
|
|
||||||
for (var j = dates[0]; j <= maxDateSlots; ++j) {
|
|
||||||
var rr = rowsPerSlot[j] || (rowsPerSlot[j] = []);
|
|
||||||
var v = valByDate[j];
|
|
||||||
if (v) {
|
|
||||||
accum += v;
|
|
||||||
}
|
|
||||||
rr.push([r, accum]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// for each timeslot search active buckets
|
|
||||||
var renderDataIndex = 0;
|
|
||||||
var timeSlotIndex = 0;
|
|
||||||
var i = 0;
|
|
||||||
for(var i = 0; i <= maxDateSlots; ++i) {
|
|
||||||
var c = 0;
|
|
||||||
var slotRows = rowsPerSlot[i]
|
|
||||||
if(slotRows) {
|
|
||||||
for (var r = 0; r < slotRows.length; ++r) {
|
|
||||||
var rr = slotRows[r];
|
|
||||||
++c;
|
|
||||||
renderDataPos[renderDataIndex] = rr[0]
|
|
||||||
renderData[renderDataIndex] = rr[1];
|
|
||||||
++renderDataIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
timeIndex[i] = timeSlotIndex;
|
|
||||||
timeCount[i] = c;
|
|
||||||
timeSlotIndex += c;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
x: x,
|
|
||||||
y: y,
|
|
||||||
z: zoom,
|
|
||||||
coord: {
|
|
||||||
x: coord.x,
|
|
||||||
y: coord.y,
|
|
||||||
z: zoom
|
|
||||||
},
|
|
||||||
timeCount: timeCount,
|
|
||||||
timeIndex: timeIndex,
|
|
||||||
renderDataPos: renderDataPos,
|
|
||||||
renderData: renderData,
|
|
||||||
maxDate: maxDateSlots
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
setSteps: function(steps, opt) {
|
|
||||||
opt = opt || {};
|
|
||||||
if (this.options.steps !== steps) {
|
|
||||||
this.options.steps = steps;
|
|
||||||
this.options.step = (this.options.end - this.options.start)/this.getSteps();
|
|
||||||
this.options.step = this.options.step || 1;
|
|
||||||
if (!opt.silent) this.reload();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
setOptions: function(opt) {
|
|
||||||
var refresh = false;
|
|
||||||
|
|
||||||
if(opt.resolution !== undefined && opt.resolution !== this.options.resolution) {
|
|
||||||
this.options.resolution = opt.resolution;
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(opt.steps !== undefined && opt.steps !== this.options.steps) {
|
|
||||||
this.setSteps(opt.steps, { silent: true });
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(opt.column !== undefined && opt.column !== this.options.column) {
|
|
||||||
this.options.column = opt.column;
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(opt.countby !== undefined && opt.countby !== this.options.countby) {
|
|
||||||
this.options.countby = opt.countby;
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(opt.data_aggregation !== undefined) {
|
|
||||||
var c = opt.data_aggregation === 'cumulative';
|
|
||||||
if (this.options.cumulative !== c) {
|
|
||||||
this.options.cumulative = c;
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (refresh) this.reload();
|
|
||||||
return refresh;
|
|
||||||
},
|
|
||||||
|
|
||||||
_extraParams: function(e) {
|
|
||||||
e = torque.extend(torque.extend({}, e), this.options.extra_params);
|
|
||||||
if (e) {
|
|
||||||
var p = [];
|
|
||||||
for(var k in e) {
|
|
||||||
var v = e[k];
|
|
||||||
if (v) {
|
|
||||||
if (torque.isArray(v)) {
|
|
||||||
for (var i = 0, len = v.length; i < len; i++) {
|
|
||||||
p.push(k + "[]=" + encodeURIComponent(v[i]));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
p.push(k + "=" + encodeURIComponent(v));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return p.join('&');
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
|
|
||||||
getTileData: function(coord, zoom, callback) {
|
|
||||||
if(!this._ready) {
|
|
||||||
this._tileQueue.push([coord, zoom, callback]);
|
|
||||||
} else {
|
|
||||||
this._getTileData(coord, zoom, callback);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_setReady: function(ready) {
|
|
||||||
this._ready = true;
|
|
||||||
this._processQueue();
|
|
||||||
this.options.ready && this.options.ready();
|
|
||||||
},
|
|
||||||
|
|
||||||
_processQueue: function() {
|
|
||||||
var item;
|
|
||||||
while (item = this._tileQueue.pop()) {
|
|
||||||
this._getTileData.apply(this, item);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* `coord` object like {x : tilex, y: tiley }
|
|
||||||
* `zoom` quadtree zoom level
|
|
||||||
*/
|
|
||||||
_getTileData: function(coord, zoom, callback) {
|
|
||||||
var self = this;
|
|
||||||
var subdomains = this.options.subdomains || '0123';
|
|
||||||
var limit_x = Math.pow(2, zoom);
|
|
||||||
var corrected_x = ((coord.x % limit_x) + limit_x) % limit_x;
|
|
||||||
var index = Math.abs(corrected_x + coord.y) % subdomains.length;
|
|
||||||
var extra = this._extraParams();
|
|
||||||
var url = this.templateUrl
|
|
||||||
.replace('{x}', corrected_x)
|
|
||||||
.replace('{y}', coord.y)
|
|
||||||
.replace('{z}', zoom)
|
|
||||||
.replace('{s}', subdomains[index])
|
|
||||||
url += extra;
|
|
||||||
torque.net.get( url , function (data) {
|
|
||||||
if (data && data.responseText) {
|
|
||||||
var rows = JSON.parse(data.responseText);
|
|
||||||
callback(self.proccessTile(rows, coord, zoom));
|
|
||||||
} else {
|
|
||||||
callback(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
getKeySpan: function() {
|
|
||||||
return {
|
|
||||||
start: this.options.start,
|
|
||||||
end: this.options.end,
|
|
||||||
step: this.options.step,
|
|
||||||
steps: this.options.steps,
|
|
||||||
columnType: this.options.column_type
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
setColumn: function(column, isTime) {
|
|
||||||
this.options.column = column;
|
|
||||||
this.options.is_time = isTime === undefined ? true: false;
|
|
||||||
this.reload();
|
|
||||||
},
|
|
||||||
|
|
||||||
reload: function() {
|
|
||||||
this._ready = false;
|
|
||||||
this._fetchMap();
|
|
||||||
},
|
|
||||||
|
|
||||||
getSteps: function() {
|
|
||||||
return Math.min(this.options.steps, this.options.data_steps);
|
|
||||||
},
|
|
||||||
|
|
||||||
getBounds: function() {
|
|
||||||
return this.options.bounds;
|
|
||||||
},
|
|
||||||
|
|
||||||
getSQL: function() {
|
|
||||||
return this.options.sql || "select * from " + this.options.table;
|
|
||||||
},
|
|
||||||
|
|
||||||
setSQL: function(sql) {
|
|
||||||
if (this.options.sql != sql) {
|
|
||||||
this.options.sql = sql;
|
|
||||||
this.reload();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_isUserTemplateUrl: function(t) {
|
|
||||||
return t && t.indexOf('{user}') !== -1;
|
|
||||||
},
|
|
||||||
|
|
||||||
isHttps: function() {
|
|
||||||
return this.options.maps_api_template.indexOf('https') === 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
_fetchMap: function(callback) {
|
|
||||||
var self = this;
|
|
||||||
torque.net.get(this.options.tileJSON, function (data) {
|
|
||||||
data = JSON.parse(data.response);
|
|
||||||
if (data) {
|
|
||||||
if (data.errors){
|
|
||||||
self.options.errorCallback && self.options.errorCallback(data.errors);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for(var k in data) {
|
|
||||||
self.options[k] = data[k];
|
|
||||||
}
|
|
||||||
self.templateUrl = data.tiles[0];
|
|
||||||
if (self.templateUrl.indexOf("http") !== 0){
|
|
||||||
self.templateUrl = self.options.tileJSON.substring(0, self.options.tileJSON.lastIndexOf("/") + 1) + self.templateUrl;
|
|
||||||
}
|
|
||||||
self._setReady(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = tileJSON;
|
|
@ -186,17 +186,6 @@
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
proccessTileError: function(error, coord, zoom) {
|
|
||||||
return {
|
|
||||||
error: error,
|
|
||||||
coord: {
|
|
||||||
x: coord.x,
|
|
||||||
y: coord.y,
|
|
||||||
z: zoom
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
/*setCartoCSS: function(c) {
|
/*setCartoCSS: function(c) {
|
||||||
this.options.cartocss = c;
|
this.options.cartocss = c;
|
||||||
},*/
|
},*/
|
||||||
@ -306,18 +295,11 @@
|
|||||||
.replace('{s}', subdomains[index])
|
.replace('{s}', subdomains[index])
|
||||||
|
|
||||||
var extra = this._extraParams();
|
var extra = this._extraParams();
|
||||||
torque.net.get( url + (extra ? "?" + extra: ''), function (response) {
|
torque.net.get( url + (extra ? "?" + extra: ''), function (data) {
|
||||||
prof_fetch_time.end();
|
prof_fetch_time.end();
|
||||||
if (response && response.responseText) {
|
if (data && data.responseText) {
|
||||||
var body = JSON.parse(response.responseText);
|
var rows = JSON.parse(data.responseText);
|
||||||
|
callback(self.proccessTile(rows, coord, zoom));
|
||||||
if (response.status === 429) {
|
|
||||||
var error = body.errors_with_context[0];
|
|
||||||
|
|
||||||
callback(self.proccessTileError(error, coord, zoom), error);
|
|
||||||
} else {
|
|
||||||
callback(self.proccessTile(body, coord, zoom));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Profiler.metric('torque.provider.windshaft.tile.error').inc();
|
Profiler.metric('torque.provider.windshaft.tile.error').inc();
|
||||||
callback(null);
|
callback(null);
|
||||||
|
@ -73,6 +73,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderText(ctx,st){
|
||||||
|
var width = st['marker-width']
|
||||||
|
|
||||||
|
var text = st['text-name']
|
||||||
|
var font = st['text-face-name'] ? st['text-face-name'] : 'Droid Sans Regular'
|
||||||
|
var textSize = st['text-size'] ? st['text-size'] : '10px'
|
||||||
|
var color = st['text-fill'] ? st['text-fill'] : 'white'
|
||||||
|
|
||||||
|
// ctx.font = textSize+"px "+font
|
||||||
|
ctx.fillStyle = color
|
||||||
|
ctx.font= textSize + " " + font
|
||||||
|
ctx.fillText(text, -width/2.0, width/2.0 )
|
||||||
|
}
|
||||||
|
|
||||||
function renderSprite(ctx, img, st) {
|
function renderSprite(ctx, img, st) {
|
||||||
|
|
||||||
if(img.complete){
|
if(img.complete){
|
||||||
@ -87,5 +101,6 @@ module.exports = {
|
|||||||
renderPoint: renderPoint,
|
renderPoint: renderPoint,
|
||||||
renderSprite: renderSprite,
|
renderSprite: renderSprite,
|
||||||
renderRectangle: renderRectangle,
|
renderRectangle: renderRectangle,
|
||||||
|
renderText: renderText,
|
||||||
MAX_SPRITE_RADIUS: MAX_SPRITE_RADIUS
|
MAX_SPRITE_RADIUS: MAX_SPRITE_RADIUS
|
||||||
};
|
};
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
var d3 = require('d3');
|
|
||||||
var jenks = require('turf-jenks');
|
|
||||||
|
|
||||||
function TorqueDataSource (tiles) {
|
|
||||||
this.tiles = tiles
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = TorqueDataSource
|
|
||||||
|
|
||||||
TorqueDataSource.prototype.getName = function () {
|
|
||||||
return 'TorqueDataSource'
|
|
||||||
}
|
|
||||||
|
|
||||||
TorqueDataSource.prototype.getRamp = function (column, bins, method, callback) {
|
|
||||||
var ramp = []
|
|
||||||
var error = null
|
|
||||||
var values = Object.keys(this.tiles).map(function (t) {
|
|
||||||
return this.tiles[t].renderData;
|
|
||||||
}.bind(this)).reduce(function (p,c,i) {
|
|
||||||
for(var i = 0; i<c.length; i++) {
|
|
||||||
p.push(c[i]);
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
},[]);
|
|
||||||
var extent = d3.extent(values);
|
|
||||||
if (!method || method === 'equal' || method === 'jenks') {
|
|
||||||
var scale = d3.scale.linear().domain([0, bins]).range(extent)
|
|
||||||
ramp = d3.range(bins).map(scale)
|
|
||||||
} else if (method === 'quantiles') {
|
|
||||||
ramp = d3.scale.quantile().range(d3.range(bins)).domain(values).quantiles()
|
|
||||||
} else if (method === 'headstails') {
|
|
||||||
var sortedValues = values.sort(function(a, b) {
|
|
||||||
return a - b;
|
|
||||||
});
|
|
||||||
if (sortedValues.length < bins) {
|
|
||||||
error = 'Number of bins should be lower than total number of rows'
|
|
||||||
} else if (sortedValues.length === bins) {
|
|
||||||
ramp = sortedValues;
|
|
||||||
} else {
|
|
||||||
var mean = d3.mean(sortedValues);
|
|
||||||
ramp.push(mean);
|
|
||||||
for (var i = 1; i < bins; i++) {
|
|
||||||
ramp.push(d3.mean(sortedValues.filter(function (v) {
|
|
||||||
return v > ramp[length - 1];
|
|
||||||
})));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error = new Error('Quantification method ' + method + ' is not supported')
|
|
||||||
}
|
|
||||||
callback(error, ramp)
|
|
||||||
}
|
|
@ -3,11 +3,8 @@ var cartocss = require('./cartocss_render');
|
|||||||
var Profiler = require('../profiler');
|
var Profiler = require('../profiler');
|
||||||
var carto = global.carto || require('carto');
|
var carto = global.carto || require('carto');
|
||||||
var Filters = require('./torque_filters');
|
var Filters = require('./torque_filters');
|
||||||
var turbocarto = require('turbo-carto');
|
|
||||||
var CartoDatasource = require('./datasource');
|
|
||||||
|
|
||||||
var ERROR_IMG_URL = 'http://s3.amazonaws.com/com.cartodb.assets.static/error.svg';
|
|
||||||
|
|
||||||
|
var TAU = Math.PI * 2;
|
||||||
var DEFAULT_CARTOCSS = [
|
var DEFAULT_CARTOCSS = [
|
||||||
'#layer {',
|
'#layer {',
|
||||||
' marker-fill: #662506;',
|
' marker-fill: #662506;',
|
||||||
@ -23,46 +20,24 @@ var CartoDatasource = require('./datasource');
|
|||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
var COMP_OP_TO_CANVAS = {
|
var COMP_OP_TO_CANVAS = {
|
||||||
"difference": "difference",
|
|
||||||
"src": 'source-over',
|
"src": 'source-over',
|
||||||
"exclusion": "exclusion",
|
|
||||||
"dst": "destination-in",
|
|
||||||
"multiply": "multiply",
|
|
||||||
"contrast": "contrast",
|
|
||||||
"src-over": 'source-over',
|
"src-over": 'source-over',
|
||||||
"screen": "screen",
|
|
||||||
"invert": "invert",
|
|
||||||
"dst-over": 'destination-over',
|
"dst-over": 'destination-over',
|
||||||
"overlay": "overlay",
|
|
||||||
"invert-rgb": "invert",
|
|
||||||
"src-in": 'source-in',
|
"src-in": 'source-in',
|
||||||
"darken": 'darken',
|
|
||||||
"dst-in": 'destination-in',
|
"dst-in": 'destination-in',
|
||||||
"lighten": 'lighten',
|
|
||||||
"src-out": 'source-out',
|
"src-out": 'source-out',
|
||||||
"color-dodge": "color-dodge",
|
|
||||||
"hue":"hue",
|
|
||||||
"dst-out": 'destination-out',
|
"dst-out": 'destination-out',
|
||||||
"color-burn":"color-burn",
|
|
||||||
"saturation":"saturation",
|
|
||||||
"src-atop": 'source-atop',
|
"src-atop": 'source-atop',
|
||||||
"hard-light":"hard-light",
|
|
||||||
"color":"color",
|
|
||||||
"dst-atop": 'destination-atop',
|
"dst-atop": 'destination-atop',
|
||||||
"soft-light":"soft-light",
|
"xor": 'xor',
|
||||||
"xor": 'xor'
|
"darken": 'darken',
|
||||||
|
"lighten": 'lighten'
|
||||||
}
|
}
|
||||||
|
|
||||||
function compop2canvas(compop) {
|
function compop2canvas(compop) {
|
||||||
return COMP_OP_TO_CANVAS[compop] || compop;
|
return COMP_OP_TO_CANVAS[compop] || compop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take an input cartocss that may contain comments and remove them
|
|
||||||
var COMMENTS_RE = /\/\*.*?\*\/\n?/mg;
|
|
||||||
function stripComments(cartocss) {
|
|
||||||
return cartocss.replace(COMMENTS_RE, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// this renderer just render points depending of the value
|
// this renderer just render points depending of the value
|
||||||
//
|
//
|
||||||
@ -71,7 +46,6 @@ var CartoDatasource = require('./datasource');
|
|||||||
throw new Error("canvas can't be undefined");
|
throw new Error("canvas can't be undefined");
|
||||||
}
|
}
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.layer = options.layer;
|
|
||||||
this._canvas = canvas;
|
this._canvas = canvas;
|
||||||
this._ctx = canvas.getContext('2d');
|
this._ctx = canvas.getContext('2d');
|
||||||
this._sprites = []; // sprites per layer
|
this._sprites = []; // sprites per layer
|
||||||
@ -90,24 +64,19 @@ var CartoDatasource = require('./datasource');
|
|||||||
torque.extend(PointRenderer.prototype, torque.Event, {
|
torque.extend(PointRenderer.prototype, torque.Event, {
|
||||||
|
|
||||||
clearCanvas: function() {
|
clearCanvas: function() {
|
||||||
if (this._Map) {
|
|
||||||
var canvas = this._canvas;
|
var canvas = this._canvas;
|
||||||
var color = this._Map['-torque-clear-color']
|
var color = this._Map['-torque-clear-color']
|
||||||
// shortcut for the default value
|
// shortcut for the default value
|
||||||
var ctx = this._ctx;
|
|
||||||
if (color === "rgba(255, 255, 255, 0)" || !color) {
|
if (color === "rgba(255, 255, 255, 0)" || !color) {
|
||||||
ctx.save();
|
this._canvas.width = this._canvas.width;
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
||||||
ctx.restore();
|
|
||||||
} else {
|
} else {
|
||||||
|
var ctx = this._ctx;
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
var compop = this._Map['comp-op']
|
var compop = this._Map['comp-op']
|
||||||
ctx.globalCompositeOperation = compop2canvas(compop) || compop;
|
ctx.globalCompositeOperation = compop2canvas(compop);
|
||||||
ctx.fillStyle = color;
|
ctx.fillStyle = color;
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setCanvas: function(canvas) {
|
setCanvas: function(canvas) {
|
||||||
@ -118,27 +87,9 @@ var CartoDatasource = require('./datasource');
|
|||||||
//
|
//
|
||||||
// sets the cartocss style to render stuff
|
// sets the cartocss style to render stuff
|
||||||
//
|
//
|
||||||
setCartoCSS: function(cartocss, callback) {
|
setCartoCSS: function(cartocss) {
|
||||||
var self = this;
|
// clean sprites
|
||||||
|
this.setShader(new carto.RendererJS().render(cartocss));
|
||||||
this.style = stripComments(cartocss);
|
|
||||||
|
|
||||||
if (PointRenderer.isTurboCarto(this.style) && self.layer) {
|
|
||||||
var datasource = new CartoDatasource(self.layer._tiles);
|
|
||||||
turbocarto(this.style, datasource, function (err, parsedCartoCSS) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.setShader(new carto.RendererJS().render(parsedCartoCSS));
|
|
||||||
self.layer.redraw();
|
|
||||||
self.layer.animator.start();
|
|
||||||
callback && callback();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
self.setShader(new carto.RendererJS().render(this.style));
|
|
||||||
callback && callback();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setShader: function(shader) {
|
setShader: function(shader) {
|
||||||
@ -147,10 +98,6 @@ var CartoDatasource = require('./datasource');
|
|||||||
this._shader = shader;
|
this._shader = shader;
|
||||||
this._Map = this._shader.getDefault().getStyle({}, { zoom: 0 });
|
this._Map = this._shader.getDefault().getStyle({}, { zoom: 0 });
|
||||||
var img_names = this._shader.getImageURLs();
|
var img_names = this._shader.getImageURLs();
|
||||||
if (this.layer && this.layer.showLimitErrors) {
|
|
||||||
img_names.push(ERROR_IMG_URL);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._preloadIcons(img_names);
|
this._preloadIcons(img_names);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -212,6 +159,12 @@ var CartoDatasource = require('./datasource');
|
|||||||
cartocss.renderPoint(ctx, st);
|
cartocss.renderPoint(ctx, st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(st['text-name']){
|
||||||
|
st['text-name'] = st['text-name'].replace("{{value}}",value)
|
||||||
|
cartocss.renderText(ctx,st)
|
||||||
|
}
|
||||||
|
|
||||||
prof.end(true);
|
prof.end(true);
|
||||||
if (torque.flags.sprites_to_images) {
|
if (torque.flags.sprites_to_images) {
|
||||||
var i = this._createImage();
|
var i = this._createImage();
|
||||||
@ -225,25 +178,13 @@ var CartoDatasource = require('./datasource');
|
|||||||
//
|
//
|
||||||
// renders all the layers (and frames for each layer) from cartocss
|
// renders all the layers (and frames for each layer) from cartocss
|
||||||
//
|
//
|
||||||
renderTile: function(tile, keys, callback) {
|
renderTile: function(tile, key, callback) {
|
||||||
if (tile && tile.error) {
|
|
||||||
this._renderErrorTile(tile);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._iconsToLoad > 0) {
|
if (this._iconsToLoad > 0) {
|
||||||
this.on('allIconsLoaded', function() {
|
this.on('allIconsLoaded', function() {
|
||||||
this.renderTile.apply(this, [tile, keys, callback]);
|
this.renderTile.apply(this, [tile, key, callback]);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert scalar key to keys array
|
|
||||||
if (typeof keys.length === 'undefined') {
|
|
||||||
keys = [keys];
|
|
||||||
}
|
|
||||||
|
|
||||||
var prof = Profiler.metric('torque.renderer.point.renderLayers').start();
|
var prof = Profiler.metric('torque.renderer.point.renderLayers').start();
|
||||||
var layers = this._shader.getLayers();
|
var layers = this._shader.getLayers();
|
||||||
for(var i = 0, n = layers.length; i < n; ++i ) {
|
for(var i = 0, n = layers.length; i < n; ++i ) {
|
||||||
@ -254,17 +195,7 @@ var CartoDatasource = require('./datasource');
|
|||||||
for(var fr = 0; fr < layer.frames().length; ++fr) {
|
for(var fr = 0; fr < layer.frames().length; ++fr) {
|
||||||
var frame = layer.frames()[fr];
|
var frame = layer.frames()[fr];
|
||||||
var fr_sprites = sprites[frame] || (sprites[frame] = []);
|
var fr_sprites = sprites[frame] || (sprites[frame] = []);
|
||||||
for (var k = 0, len = keys.length; k < len; k++) {
|
this._renderTile(tile, key - frame, frame, fr_sprites, layer);
|
||||||
try {
|
|
||||||
this._renderTile(tile, keys[k] - frame, frame, fr_sprites, layer);
|
|
||||||
} catch (error) {
|
|
||||||
if (callback) {
|
|
||||||
return callback(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,13 +242,6 @@ var CartoDatasource = require('./datasource');
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_renderErrorTile: function(tile) {
|
|
||||||
if(this.layer.showLimitErrors) {
|
|
||||||
var img = this._icons[ERROR_IMG_URL];
|
|
||||||
img && this._ctx.drawImage(img, 0, 0, this.TILE_SIZE, this.TILE_SIZE);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// renders a tile in the canvas for key defined in
|
// renders a tile in the canvas for key defined in
|
||||||
// the torque tile
|
// the torque tile
|
||||||
@ -395,23 +319,6 @@ var CartoDatasource = require('./datasource');
|
|||||||
return positions;
|
return positions;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* returns an array with all the values for the active pixels
|
|
||||||
* @tile tile object
|
|
||||||
* @step integer with the step
|
|
||||||
* @values (optional) an array where the values will be placed
|
|
||||||
*/
|
|
||||||
getValues: function(tile, step, values) {
|
|
||||||
values = values || [];
|
|
||||||
var activePixels = tile.timeCount[step];
|
|
||||||
var pixelIndex = tile.timeIndex[step];
|
|
||||||
for(var p = 0; p < activePixels; ++p) {
|
|
||||||
var posIdx = tile.renderDataPos[pixelIndex + p];
|
|
||||||
values.push(tile.renderData[pixelIndex + p]);
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
},
|
|
||||||
|
|
||||||
// return the value for x, y (tile coordinates)
|
// return the value for x, y (tile coordinates)
|
||||||
// null for no value
|
// null for no value
|
||||||
getValueFor: function(tile, step, px, py) {
|
getValueFor: function(tile, step, px, py) {
|
||||||
@ -539,18 +446,7 @@ var CartoDatasource = require('./datasource');
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
PointRenderer.isTurboCarto = function (cartocss) {
|
|
||||||
var reservedWords = ['ramp', 'colorbrewer', 'buckets']
|
|
||||||
var isTurbo = reservedWords
|
|
||||||
.map(function (w) {
|
|
||||||
return w + '('
|
|
||||||
})
|
|
||||||
.map(String.prototype.indexOf.bind(cartocss))
|
|
||||||
.every(function (f) { return f === -1 })
|
|
||||||
return !isTurbo
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// exports public api
|
// exports public api
|
||||||
|
@ -62,7 +62,7 @@ var torque = require('./core');
|
|||||||
function respond() {
|
function respond() {
|
||||||
var status = req.status, result;
|
var status = req.status, result;
|
||||||
var r = options.responseType === 'arraybuffer' ? req.response: req.responseText;
|
var r = options.responseType === 'arraybuffer' ? req.response: req.responseText;
|
||||||
if (!status && r || status >= 200 && status < 300 || status === 304 || status === 429) {
|
if (!status && r || status >= 200 && status < 300 || status === 304) {
|
||||||
callback(req);
|
callback(req);
|
||||||
} else {
|
} else {
|
||||||
callback(null);
|
callback(null);
|
||||||
|
3186
package-lock.json
generated
3186
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
53
package.json
53
package.json
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "torque.js",
|
"name": "torque.js",
|
||||||
"version": "3.1.2",
|
"version": "2.11.4",
|
||||||
"description": "Temporal mapping for CARTO",
|
"description": "Temporal mapping for CartoDB",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/CartoDB/torque.git"
|
"url": "git://github.com/CartoDB/torque.git"
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"name": "CARTO",
|
"name": "CartoDB",
|
||||||
"url": "http://carto.com/",
|
"url": "http://cartodb.com/",
|
||||||
"email": "wadus@carto.com"
|
"email": "wadus@cartodb.com"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Andrew Hill <andrew@vizzuality.com>",
|
"Andrew Hill <andrew@vizzuality.com>",
|
||||||
@ -19,38 +19,31 @@
|
|||||||
"Javier Santana <jsantana@vizzuality.com>",
|
"Javier Santana <jsantana@vizzuality.com>",
|
||||||
"Raúl Ochoa <rochoa@cartodb.com>",
|
"Raúl Ochoa <rochoa@cartodb.com>",
|
||||||
"Nicklas Gummesson <nicklas@cartodb.com>",
|
"Nicklas Gummesson <nicklas@cartodb.com>",
|
||||||
"Francisco Dans <francisco@cartodb.com>",
|
"Francisco Dans <francisco@cartodb.com>"
|
||||||
"Carlos Matallín <matallo@carto.com>",
|
],
|
||||||
"Rubén Moya <ruben@carto.com>",
|
"licenses": [{
|
||||||
"Daniel García Aubert <dgaubert@carto.com>"
|
"type": "BSD"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"license": "BSD-3-Clause",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"carto": "cartodb/carto#master",
|
"carto": "https://github.com/CartoDB/carto/archive/master.tar.gz"
|
||||||
"d3": "3.5.17",
|
|
||||||
"turbo-carto": "^0.21.1",
|
|
||||||
"turf-jenks": "~1.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@carto/mapnik": "^3.6.2-carto.11",
|
"browserify": "^7.0.0",
|
||||||
"browserify": "^16.2.3",
|
"canvas": "~1.2.1",
|
||||||
"canvas": "^2.4.1",
|
"leaflet": "0.7.3",
|
||||||
"leaflet": "1.0.3",
|
"mapnik": "https://github.com/CartoDB/node-mapnik/tarball/1.4.15-cdb1",
|
||||||
"node-qunit-phantomjs": "1.6.0",
|
"node-qunit-phantomjs": "^1.0.0",
|
||||||
"phantomjs-polyfill": "0.0.2",
|
"phantomjs-polyfill": "0.0.1",
|
||||||
"qunit": "~0.7.7",
|
"qunit": "~0.7.5",
|
||||||
"qunitjs": "1.x",
|
"qunitjs": "1.x",
|
||||||
"request": "^2.88.0",
|
"request": "^2.53.0",
|
||||||
"sinon": "~1.15.4",
|
"uglify-js": "1.3.3",
|
||||||
"uglify-js": "^3.4.9",
|
"underscore": "^1.6.0",
|
||||||
"underscore": "1.8.3"
|
"sinon": "^1.15.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "make test-all",
|
"test": "make test-all"
|
||||||
"bump": "npm version patch",
|
|
||||||
"bump:major": "npm version major",
|
|
||||||
"bump:minor": "npm version minor",
|
|
||||||
"postversion": "git push origin master --follow-tags"
|
|
||||||
},
|
},
|
||||||
"main": "./lib/torque/index.js"
|
"main": "./lib/torque/index.js"
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
const { createCanvas }= require('canvas');
|
var Canvas = require('canvas');
|
||||||
const image = require('../support/image');
|
var image = require('../support/image');
|
||||||
|
|
||||||
QUnit.module('example');
|
QUnit.module('example');
|
||||||
|
|
||||||
test('reference test with canvas', function() {
|
test('reference test with canvas', function() {
|
||||||
var circleRadius = 20;
|
var circleRadius = 20;
|
||||||
var canvasSize = circleRadius * 2 + 2;
|
var canvasSize = circleRadius * 2 + 2;
|
||||||
var canvas = createCanvas(canvasSize, canvasSize);
|
var canvas = new Canvas(canvasSize, canvasSize);
|
||||||
|
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
@ -19,3 +19,4 @@ test('reference test with canvas', function() {
|
|||||||
|
|
||||||
equal(imageDiff, 0);
|
equal(imageDiff, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,11 +5,6 @@ QUnit.module('renderer/point');
|
|||||||
|
|
||||||
var IMAGE_DIFF_TOLERANCE = 4 / 100;
|
var IMAGE_DIFF_TOLERANCE = 4 / 100;
|
||||||
|
|
||||||
// HOW TO debug image output
|
|
||||||
// -------------------------
|
|
||||||
// Once you have a valid canvas and no errors, it's possible to write to disk the canvas buffer as a png image with:
|
|
||||||
// require('fs').writeFileSync('/tmp/torque-acceptance-test-tile.png', canvas.toBuffer(), {encoding: null});
|
|
||||||
|
|
||||||
asyncTest('navy example', function(assert) {
|
asyncTest('navy example', function(assert) {
|
||||||
var cartocss = [
|
var cartocss = [
|
||||||
'Map {',
|
'Map {',
|
||||||
@ -69,43 +64,3 @@ asyncTest('basic heatmap', function(assert) {
|
|||||||
QUnit.start();
|
QUnit.start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('render multiple steps', function(assert) {
|
|
||||||
var CARTOCSS = [
|
|
||||||
'Map {',
|
|
||||||
' -torque-frame-count: 360;',
|
|
||||||
' -torque-animation-duration: 30;',
|
|
||||||
' -torque-time-attribute: "cartodb_id";',
|
|
||||||
' -torque-aggregation-function: "count(cartodb_id)";',
|
|
||||||
' -torque-resolution: 1;',
|
|
||||||
' -torque-data-aggregation: linear;',
|
|
||||||
'}',
|
|
||||||
'#generate_series {',
|
|
||||||
' comp-op: lighter;',
|
|
||||||
' marker-fill-opacity: 0.9;',
|
|
||||||
' marker-line-color: #FFF;',
|
|
||||||
' marker-line-width: 0;',
|
|
||||||
' marker-line-opacity: 1;',
|
|
||||||
' marker-type: rectable;',
|
|
||||||
' marker-width: 6;',
|
|
||||||
' marker-fill: #0F3B82;',
|
|
||||||
'}'
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
var steps = [];
|
|
||||||
for (var i = 20; i <= 50; i++) {
|
|
||||||
steps.push(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dataset can be regenerated with:
|
|
||||||
// SELECT
|
|
||||||
// s + 181 as cartodb_id,
|
|
||||||
// st_transform(ST_SetSRID (st_makepoint(s, 20 + 10*sin(s)), 4326), 3857) as the_geom_webmercator
|
|
||||||
// FROM generate_series(-180, 180, 1) as s
|
|
||||||
pointRenderer.getTile('generate_series_sin-2-0-1.torque.json', CARTOCSS, 2, 0, 1, steps, function(err, canvas) {
|
|
||||||
assert.ok(!err, 'no error while getting tile');
|
|
||||||
var imageDiff = image.compare(canvas.toBuffer(), 'generate_series_sin-2-0-1.png');
|
|
||||||
assert.ok(imageDiff < IMAGE_DIFF_TOLERANCE, 'image not matching, probably not rendering several steps');
|
|
||||||
QUnit.start();
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,34 +0,0 @@
|
|||||||
var AnimatorStepsRange = require('../lib/torque/animator-steps-range');
|
|
||||||
|
|
||||||
QUnit.module('animator-steps-range');
|
|
||||||
|
|
||||||
test('start and end props are available', function(assert) {
|
|
||||||
var stepsRange = validStepsRange();
|
|
||||||
assert.equal(stepsRange.start, 0);
|
|
||||||
assert.equal(stepsRange.end, 4);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('.lastStep returns true if given last step', function(assert) {
|
|
||||||
var stepsRange = validStepsRange();
|
|
||||||
assert.ok(stepsRange.isLast(stepsRange.end));
|
|
||||||
|
|
||||||
assert.notOk(stepsRange.isLast(3));
|
|
||||||
assert.notOk(stepsRange.isLast(42));
|
|
||||||
assert.notOk(stepsRange.isLast(true));
|
|
||||||
assert.notOk(stepsRange.isLast());
|
|
||||||
assert.notOk(stepsRange.isLast('whatever'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('.diff returns the steps between start and end', function(assert) {
|
|
||||||
var stepsRange = validStepsRange();
|
|
||||||
assert.equal(stepsRange.diff(), 4);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('throws error in inconsistent range', function(assert) {
|
|
||||||
assert.throws(function() { new AnimatorStepsRange(4, 3) });
|
|
||||||
assert.throws(function() { new AnimatorStepsRange(4, 4) });
|
|
||||||
});
|
|
||||||
|
|
||||||
function validStepsRange() {
|
|
||||||
return new AnimatorStepsRange(0, 4);
|
|
||||||
}
|
|
@ -10,9 +10,9 @@ test('time moves', function(assert) {
|
|||||||
animatora.start();
|
animatora.start();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
assert.notEqual(animatora._time, 0);
|
assert.notEqual(animatora._time, 0);
|
||||||
animatora.pause();
|
|
||||||
done();
|
done();
|
||||||
}, 20)
|
}, 20)
|
||||||
|
animatora.pause();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rescale should resume animation if previously playing", function(assert){
|
test("rescale should resume animation if previously playing", function(assert){
|
||||||
@ -39,66 +39,12 @@ test("onStart runs properly", function(assert){
|
|||||||
animator.stop();
|
animator.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
test(".stepsRange sets a custom range with valid input", function(assert){
|
test("stop should take the pointer to position zero", function(assert){
|
||||||
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
|
||||||
var customStepsRange = animator.stepsRange(101, 202);
|
|
||||||
assert.ok(customStepsRange);
|
|
||||||
assert.equal(customStepsRange.start, 101);
|
|
||||||
assert.equal(customStepsRange.end, 202);
|
|
||||||
|
|
||||||
var didCallOnStepsRange = false;
|
|
||||||
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2,
|
|
||||||
onStepsRange: function() {
|
|
||||||
didCallOnStepsRange = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
animator.stepsRange(101, 202);
|
|
||||||
assert.ok(didCallOnStepsRange);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(".stepsRange throws error if given range is outside default range", function(assert){
|
|
||||||
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
|
||||||
assert.throws(function() { animator.stepsRange(1, 501) });
|
|
||||||
assert.throws(function() { animator.stepsRange(-1, 500) });
|
|
||||||
assert.throws(function() { animator.stepsRange(-1, 9000) });
|
|
||||||
});
|
|
||||||
|
|
||||||
test(".removeCustomStepsRange should remove any custom steps range", function(assert){
|
|
||||||
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
|
||||||
animator.removeCustomStepsRange();
|
|
||||||
animator.stepsRange(101, 202);
|
|
||||||
var customStepsRange = animator.stepsRange();
|
|
||||||
animator.removeCustomStepsRange();
|
|
||||||
var defaultStepsRange = animator.stepsRange();
|
|
||||||
assert.ok(defaultStepsRange);
|
|
||||||
assert.notEqual(defaultStepsRange, customStepsRange);
|
|
||||||
assert.equal(defaultStepsRange.start, 0);
|
|
||||||
assert.equal(defaultStepsRange.end, 500);
|
|
||||||
|
|
||||||
var didCallOnStepsRange = false;
|
|
||||||
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2,
|
|
||||||
onStepsRange: function() {
|
|
||||||
didCallOnStepsRange = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
animator.stepsRange(101, 202);
|
|
||||||
animator.removeCustomStepsRange();
|
|
||||||
assert.ok(didCallOnStepsRange);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("stop should take the pointer to position zero by default", function(assert){
|
|
||||||
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
animator.stop()
|
animator.stop()
|
||||||
assert.equal(animator._time, 0);
|
assert.equal(animator._time, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("stop should take the pointer to start position for custom range", function(assert){
|
|
||||||
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
|
||||||
animator.stepsRange(42, 137);
|
|
||||||
animator.stop()
|
|
||||||
assert.equal(animator._time, 42);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("stop should call onStop", function(assert){
|
test("stop should call onStop", function(assert){
|
||||||
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
var animator = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
animator.options.onStop = function(){
|
animator.options.onStop = function(){
|
||||||
@ -115,29 +61,14 @@ test("altering steps should rescale", function(assert){
|
|||||||
assert.ok(animator.rescale.calledOnce);
|
assert.ok(animator.rescale.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("tick should set time to zero if steps are bigger than default range", function(assert){
|
test("tick should set time to zero if steps are bigger than range", function(assert){
|
||||||
var done = assert.async();
|
var done = assert.async();
|
||||||
var animatorb = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
var animatorb = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
||||||
animatorb.start();
|
animatorb.start();
|
||||||
animatorb.step(800);
|
animatorb.step(800);
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
console.log(animatorb.step());
|
console.log(animatorb.step());
|
||||||
assert.ok(animatorb.step() | 0 === 0);
|
assert.ok(animatorb.step() < 800);
|
||||||
done();
|
|
||||||
}, 20);
|
|
||||||
animatorb.pause();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("tick should set time to start step if steps are bigger than custom range", function(assert){
|
|
||||||
var done = assert.async();
|
|
||||||
var animatorb = new torque.Animator(function(){}, {steps: 500, animationDuration: 2});
|
|
||||||
animatorb.start();
|
|
||||||
animatorb.step(800);
|
|
||||||
animatorb.stepsRange(42, 137);
|
|
||||||
setTimeout(function(){
|
|
||||||
console.log(animatorb.step());
|
|
||||||
// round step to an integer
|
|
||||||
assert.ok(animatorb.step() | 0 === 42);
|
|
||||||
done();
|
done();
|
||||||
}, 20);
|
}, 20);
|
||||||
animatorb.pause();
|
animatorb.pause();
|
||||||
@ -149,4 +80,5 @@ test("tick should pause animation on end if loop is disabled", function(assert){
|
|||||||
animator.toggle();
|
animator.toggle();
|
||||||
animator.step(600);
|
animator.step(600);
|
||||||
assert.equal(animator._time,animator.options.animationDuration);
|
assert.equal(animator._time,animator.options.animationDuration);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
BIN
test/fixtures/image/generate_series_sin-2-0-1.png
vendored
BIN
test/fixtures/image/generate_series_sin-2-0-1.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 5.1 KiB |
File diff suppressed because one or more lines are too long
@ -1,9 +0,0 @@
|
|||||||
var torque = require('../../lib/torque/index');
|
|
||||||
|
|
||||||
QUnit.module('leaflet-torque-layer');
|
|
||||||
|
|
||||||
test('exposes key property', function(assert) {
|
|
||||||
var torqueLayer = new L.TorqueLayer({});
|
|
||||||
assert.equal(torqueLayer.key, 0);
|
|
||||||
assert.equal(torqueLayer.getKey(), torqueLayer.key);
|
|
||||||
});
|
|
@ -1,22 +1,8 @@
|
|||||||
var torque = require('../lib/torque');
|
var torque = require('../lib/torque');
|
||||||
var providers = torque.providers;
|
var providers = torque.providers;
|
||||||
|
|
||||||
var json, url, _XMLHttpRequest;
|
var json, url;
|
||||||
QUnit.module('provider.json');
|
QUnit.module('provider.json');
|
||||||
QUnit.moduleStart(function() {
|
|
||||||
_XMLHttpRequest = window.XMLHttpRequest;
|
|
||||||
window.XMLHttpRequest = function () {
|
|
||||||
return {
|
|
||||||
open: function () { },
|
|
||||||
send: function () { },
|
|
||||||
readyState: 4,
|
|
||||||
responseText: {}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
QUnit.moduleDone(function() {
|
|
||||||
window.XMLHttpRequest = _XMLHttpRequest;
|
|
||||||
});
|
|
||||||
QUnit.testStart(function() {
|
QUnit.testStart(function() {
|
||||||
json = new providers.json({
|
json = new providers.json({
|
||||||
table: 'test',
|
table: 'test',
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
var torque = require('../lib/torque/core');
|
|
||||||
|
|
||||||
var tilejsonprovider, url;
|
|
||||||
var lastCall;
|
|
||||||
var old_net;
|
|
||||||
QUnit.module('provider.tilejson', {
|
|
||||||
setup: function() {
|
|
||||||
old_net = torque.net.jsonp;
|
|
||||||
old_get = torque.net.get;
|
|
||||||
torque.net.jsonp = function(url, callback) {
|
|
||||||
lastCall = url;
|
|
||||||
callback({ layergroupid: 'testlg', metadata: { torque: { 0: { data_steps:10 }} } });
|
|
||||||
};
|
|
||||||
torque.net.get = function(url, callback) {
|
|
||||||
lastCall = url;
|
|
||||||
var tilejson = '{"tiles": ["./{z}/{x}/{y}.json.torque"], "end": 903000, "column_type": "number", "start": 1000, "data_steps": 1, "resolution": 32}';
|
|
||||||
callback({response: tilejson});
|
|
||||||
};
|
|
||||||
tilejsonprovider = new torque.providers.tileJSON({
|
|
||||||
tileJSON: 'http://what.ev.er/tilejson.json',
|
|
||||||
cartocss: '#test{}',
|
|
||||||
resolution: 1,
|
|
||||||
steps: 10
|
|
||||||
});
|
|
||||||
},
|
|
||||||
teardown: function() {
|
|
||||||
torque.net.jsonp = old_net;
|
|
||||||
torque.net.get = old_get;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("tile urls should be correctly formed for relative urls", function() {
|
|
||||||
tilejsonprovider._ready = true;
|
|
||||||
tilejsonprovider.getTileData({x: 0, y: 1, corrected: {x: 0, y: 1}}, 2, function() {});
|
|
||||||
equal(lastCall,"http://what.ev.er/./2/0/1.json.torque");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("tile urls should be correctly formed for absolute urls", function() {
|
|
||||||
torque.net.jsonp = function(url, callback) {
|
|
||||||
lastCall = url;
|
|
||||||
callback({ layergroupid: 'testlg', metadata: { torque: { 0: { data_steps:10 }} } });
|
|
||||||
};
|
|
||||||
torque.net.get = function(url, callback) {
|
|
||||||
lastCall = url;
|
|
||||||
var tilejson = '{"tiles": ["http://ca.ta.pam/{z}/{x}/{y}.json.torque"], "end": 903000, "column_type": "number", "start": 1000, "data_steps": 1, "resolution": 32}';
|
|
||||||
callback({response: tilejson});
|
|
||||||
};
|
|
||||||
tilejsonprovider = new torque.providers.tileJSON({
|
|
||||||
tileJSON: 'http://what.ev.er/tilejson.json',
|
|
||||||
cartocss: '#test{}',
|
|
||||||
resolution: 1,
|
|
||||||
steps: 10
|
|
||||||
});
|
|
||||||
tilejsonprovider._ready = true;
|
|
||||||
tilejsonprovider.getTileData({x: 0, y: 1, corrected: {x: 0, y: 1}}, 2, function() {});
|
|
||||||
equal(lastCall,"http://ca.ta.pam/2/0/1.json.torque");
|
|
||||||
});
|
|
@ -83,7 +83,7 @@ QUnit.module('provider.windshaft', {
|
|||||||
|
|
||||||
test("fetch tile", function() {
|
test("fetch tile", function() {
|
||||||
windshaft._ready = true;
|
windshaft._ready = true;
|
||||||
windshaft.getTileData({x: 0, y: 1, corrected: {x: 0, y: 1}}, 2, function() {}, function() {});
|
windshaft.getTileData({x: 0, y: 1, corrected: {x: 0, y: 1}}, 2, function() {});
|
||||||
equal(lastCall,"http://rambo.cartodb.com:80/api/v1/map/testlg/0/2/0/1.json.torque?testing=abcd%25");
|
equal(lastCall,"http://rambo.cartodb.com:80/api/v1/map/testlg/0/2/0/1.json.torque?testing=abcd%25");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -22,11 +22,7 @@ var DEFAULT_CARTOCSS = [
|
|||||||
var renderer = null;
|
var renderer = null;
|
||||||
QUnit.testStart(function() {
|
QUnit.testStart(function() {
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
renderer = new torque.renderer.Point(canvas, {
|
renderer = new torque.renderer.Point(canvas, {});
|
||||||
layer: {
|
|
||||||
showLimitErros: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('render shader layers', function() {
|
test('render shader layers', function() {
|
||||||
@ -119,56 +115,3 @@ test('get value for position', function() {
|
|||||||
v = renderer.getValueFor(tile, 0, 99, 255 - 3);
|
v = renderer.getValueFor(tile, 0, 99, 255 - 3);
|
||||||
equal(v, null);
|
equal(v, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('get values for tile', function() {
|
|
||||||
tile = {
|
|
||||||
timeCount: [2],
|
|
||||||
timeIndex: [0],
|
|
||||||
renderDataPos: [0, 0],
|
|
||||||
renderData: [5, 7],
|
|
||||||
x: [100],
|
|
||||||
y: [3],
|
|
||||||
coord: { x: 0, y: 0, z: 0 }
|
|
||||||
};
|
|
||||||
renderer.options = {
|
|
||||||
resolution: 1
|
|
||||||
};
|
|
||||||
v = renderer.getValues(tile, 0);
|
|
||||||
equal(v[0], 5);
|
|
||||||
equal(v[1], 7);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should deal with no layer and commented out cartocss', function() {
|
|
||||||
var css = [
|
|
||||||
'Map {',
|
|
||||||
' -torque-frame-count: 1;',
|
|
||||||
' -torque-animation-duration: 30;',
|
|
||||||
' -torque-time-attribute: "cartodb_id";',
|
|
||||||
' -torque-aggregation-function: "count(1)";',
|
|
||||||
' -torque-resolution: 4;',
|
|
||||||
' -torque-data-aggregation: linear;',
|
|
||||||
'}',
|
|
||||||
'#layer {',
|
|
||||||
' marker-width: 16.6;',
|
|
||||||
' /*marker-width: ramp([value], range(2, 40), jenks(6));*/',
|
|
||||||
' marker-fill-opacity: 1;',
|
|
||||||
' marker-file: url(http://cartodb-libs.global.ssl.fastly.net/cartodbui/assets/unversioned/images/alphamarker.png);',
|
|
||||||
' marker-allow-overlap: true;',
|
|
||||||
' marker-line-width: 1;',
|
|
||||||
' marker-line-color: #FFFFFF;',
|
|
||||||
' marker-line-opacity: 1;',
|
|
||||||
' marker-comp-op: darken;',
|
|
||||||
' image-filters: colorize-alpha(#4b2991,#872ca2,#c0369d,#ea4f88,#fa7876,#f6a97a,#edd9a3);',
|
|
||||||
'}'
|
|
||||||
].join('\n');
|
|
||||||
|
|
||||||
var canvas = document.createElement('canvas');
|
|
||||||
var myRenderer = new torque.renderer.Point(canvas, {
|
|
||||||
layer: undefined
|
|
||||||
});
|
|
||||||
|
|
||||||
myRenderer.setCartoCSS(css);
|
|
||||||
var shader = renderer._shader.getLayers()[0];
|
|
||||||
var sprite = myRenderer.generateSprite(shader, 0, { zoom: 0 });
|
|
||||||
notEqual(sprite, null);
|
|
||||||
});
|
|
||||||
|
25921
test/suite-bundle.js
25921
test/suite-bundle.js
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,6 @@
|
|||||||
<div id="qunit-fixture"></div>
|
<div id="qunit-fixture"></div>
|
||||||
|
|
||||||
<script src="../node_modules/leaflet/dist/leaflet.js"></script>
|
<script src="../node_modules/leaflet/dist/leaflet.js"></script>
|
||||||
<script src="./dist/suite-bundle.js"></script>
|
<script src="./suite-bundle.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
require('qunitjs');
|
require('qunitjs');
|
||||||
|
|
||||||
require('./core');
|
require('./core');
|
||||||
require('./leaflet/torque-layer');
|
|
||||||
require('./torque');
|
require('./torque');
|
||||||
require('./renderer/point');
|
require('./renderer/point');
|
||||||
require('./provider.jsonarray');
|
require('./provider.jsonarray');
|
||||||
require('./provider.tilejson');
|
|
||||||
require('./provider.windshaft.test');
|
require('./provider.windshaft.test');
|
||||||
require('./provider.json');
|
require('./provider.json');
|
||||||
require('./request');
|
require('./request');
|
||||||
require('./animator');
|
require('./animator');
|
||||||
require('./animator-steps-range');
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
var mapnik = require('@carto/mapnik');
|
var mapnik = require('mapnik');
|
||||||
|
|
||||||
function compare(buffer, fixtureRelPath) {
|
function compare(buffer, fixtureRelPath) {
|
||||||
save(__dirname + '/../results/' + fixtureRelPath, buffer);
|
save(__dirname + '/../results/' + fixtureRelPath, buffer);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const { createCanvas, Canvas, Image }= require('canvas');
|
var Canvas = require('canvas');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
@ -14,7 +14,7 @@ function getTile(jsonRelPath, cartocss, z, x, y, step, callback) {
|
|||||||
var provider = new torque.providers.windshaft(_.extend({ no_fetch_map: true }, cartoCssOptions));
|
var provider = new torque.providers.windshaft(_.extend({ no_fetch_map: true }, cartoCssOptions));
|
||||||
var rendererOptions = _.extend({cartocss: cartocss}, cartoCssOptions, {
|
var rendererOptions = _.extend({cartocss: cartocss}, cartoCssOptions, {
|
||||||
canvasClass: Canvas,
|
canvasClass: Canvas,
|
||||||
imageClass: Image,
|
imageClass: Canvas.Image,
|
||||||
setImageSrc: function(img, url, callback) {
|
setImageSrc: function(img, url, callback) {
|
||||||
var requestOpts = {
|
var requestOpts = {
|
||||||
url: url,
|
url: url,
|
||||||
@ -37,15 +37,12 @@ function getTile(jsonRelPath, cartocss, z, x, y, step, callback) {
|
|||||||
},
|
},
|
||||||
qualifyURL: function(url) {
|
qualifyURL: function(url) {
|
||||||
return url;
|
return url;
|
||||||
},
|
|
||||||
layer: {
|
|
||||||
showLimitErros: false
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var rows = JSON.parse(fs.readFileSync(__dirname + '/../fixtures/json/' + jsonRelPath));
|
var rows = JSON.parse(fs.readFileSync(__dirname + '/../fixtures/json/' + jsonRelPath));
|
||||||
|
|
||||||
var canvas = createCanvas(256, 256);
|
var canvas = new Canvas(256, 256);
|
||||||
var pointRenderer = new torque.renderer.Point(canvas, rendererOptions);
|
var pointRenderer = new torque.renderer.Point(canvas, rendererOptions);
|
||||||
|
|
||||||
pointRenderer.renderTile(provider.proccessTile(rows, {x: x, y: y}, z), step, function(err) {
|
pointRenderer.renderTile(provider.proccessTile(rows, {x: x, y: y}, z), step, function(err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user