Last active
August 15, 2017 14:08
-
-
Save andrewbt/fe6dd7dddee99fecbb03b50d6823181a to your computer and use it in GitHub Desktop.
torque and raster layer together
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Named Maps Tutorial | CartoDB</title> | |
| <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
| <link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" /> | |
| <style> | |
| html, body, #map { | |
| height: 100%; | |
| padding: 0; | |
| margin: 0; | |
| } | |
| </style> | |
| <link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
| </head> | |
| <body> | |
| <div id="map"></div> | |
| <!-- include cartodb.js library --> | |
| <script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script> | |
| <!-- Drop your code between the script tags below! --> | |
| <script> | |
| function main() { | |
| // create leaflet map | |
| var map = L.map('map', { | |
| zoomControl: false, | |
| scrollWheelZoom: false, | |
| center: [0, 0], | |
| zoomControl: true, | |
| zoom: 3 | |
| }); | |
| // add a base layer | |
| L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', { | |
| attribution: 'Stamen' | |
| }).addTo(map); | |
| // add CARTO layer with one sublayer | |
| cartodb.createLayer(map, { | |
| user_name: 'athompson', | |
| type: 'namedmap', | |
| named_map: { | |
| name: "namedmap_tutorial_1", | |
| layers: [{ | |
| layer_name: "t", | |
| interactivity: "cartodb_id, name, pop_max" | |
| }] | |
| } | |
| }) | |
| .addTo(map) | |
| .done(function(layer) { | |
| layer.getSubLayer(0).setInteraction(true); | |
| // on mouseover | |
| layer.getSubLayer(0).on('featureOver', function(e, pos, pixel, data) { | |
| // print data to console log | |
| console.log("Event #" + data.cartodb_id + ", name " + data.name + ", max population: " + data.pop_max); | |
| }); | |
| // show infowindows on click | |
| cdb.vis.Vis.addInfowindow(map, layer.getSubLayer(0), ['cartodb_id','name', 'pop_max']); | |
| }); | |
| // add Torque layer | |
| cartodb.createLayer(map, { | |
| user_name: 'athompson', | |
| type: 'torque', | |
| order: 1, | |
| options: { | |
| query: "", | |
| table_name: "named_map_tutorial_table", | |
| user_name: "athompson", | |
| tile_style: "Map { -torque-frame-count: 1; -torque-animation-duration: 0; -torque-time-attribute: 'cartodb_id'; -torque-aggregation-function: 'count(1)'; -torque-resolution: 4; -torque-data-aggregation: linear; } #layer [zoom <= 4]{ marker-width: 5; marker-fill: #FFB927; marker-fill-opacity: 0.9; marker-line-width: 1; marker-line-color: #000000; marker-line-opacity: 1; comp-op: lighter; }" | |
| }, | |
| named_map: { | |
| name: "namedmap_tutorial_torque", | |
| layers: [{ | |
| layer_name: "t" | |
| }] | |
| } | |
| }, { time_slider: false}) | |
| .addTo(map) | |
| .done(function(layer) { | |
| layer.stop(); | |
| }); | |
| } | |
| window.onload = main; | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.0.1", | |
| "name": "namedmap_tutorial_1", | |
| "auth": { | |
| "method": "open" | |
| }, | |
| "layergroup": { | |
| "layers": [{ | |
| "type": "cartodb", | |
| "options": { | |
| "cartocss_version": "2.1.1", | |
| "cartocss": "#named_map_tutorial_table [zoom > 4]{ marker-fill-opacity: 0.5; marker-line-color: #FFF; marker-line-width: 0; marker-line-opacity: 1; marker-placement: point; marker-type: ellipse; marker-width: 10; marker-fill: #FFCC00; marker-allow-overlap: true; marker-comp-op: multiply; }", | |
| "sql": "SELECT * FROM named_map_tutorial_table", | |
| "interactivity": ["cartodb_id", "name", "pop_max"] | |
| } | |
| }] | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.0.1", | |
| "name": "namedmap_tutorial_torque", | |
| "auth": { | |
| "method": "open" | |
| }, | |
| "layergroup": { | |
| "layers": [{ | |
| "type": "torque", | |
| "options": { | |
| "sql": "SELECT * FROM named_map_tutorial_table", | |
| "cartocss": "Map { -torque-frame-count: 1; -torque-animation-duration: 0; -torque-time-attribute: 'cartodb_id'; -torque-aggregation-function: 'count(1)'; -torque-resolution: 4; -torque-data-aggregation: linear; } #layer [zoom <= 4]{ marker-width: 5; marker-fill: #FFB927; marker-fill-opacity: 0.9; marker-line-width: 1; marker-line-color: #000000; marker-line-opacity: 1; comp-op: lighter; }", | |
| "cartocss_version": "1.0.0", | |
| "geom_column": "the_geom_webmercator" | |
| } | |
| }] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment