Last active
April 12, 2016 12:53
-
-
Save ramiroaznar/387975119b32ad7dc20a to your computer and use it in GitHub Desktop.
How to connect points with great circles with CartoDB.js
This file contains 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>How to connect points with great circles with CartoDB.js</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" /> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
<style> | |
html, body,#map { | |
width:100%; | |
height:100%; | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script type="text/SQL" id="sql_template"> | |
SELECT | |
ST_Transform( | |
ST_Segmentize( | |
ST_Makeline( | |
a.the_geom, | |
b.the_geom | |
)::geography, | |
100000 | |
)::geometry, | |
3857 | |
) as the_geom_webmercator | |
FROM ramirocartodb.cbd_offices_locations a, ramirocartodb.cbd_offices_locations b | |
WHERE a.cartodb_id<>b.cartodb_id | |
</script> | |
<script type="text/javascript"> | |
function main() { | |
var query = $('#sql_template').text(); // get query | |
console.log(query); | |
var map = new L.Map('map', { | |
zoomControl: false, | |
center: [43, -30], | |
zoom: 3 | |
}); | |
cartodb.createLayer(map, { | |
user_name: 'ramirocartodb', | |
type: 'cartodb', | |
sublayers: [ | |
{ | |
type: "http", // add basemap without labels | |
urlTemplate: "http://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png", | |
subdomains: [ "a", "b", "c" ] | |
}, | |
{ | |
type: "mapnik", // add lines | |
sql: query, | |
cartocss: "#cbd_offices_locations{line-color: #5CA2D1;line-width: 2;line-opacity: 0.7;}" | |
}, | |
{ | |
type: "mapnik", // add points | |
sql: 'SELECT * FROM cbd_offices_locations', | |
cartocss: "#cbd_offices_locations{marker-fill-opacity: 0.9;marker-line-color: #000000;marker-line-width: 1;marker-line-opacity: 1;marker-placement: point;marker-type: ellipse;marker-width: 10;marker-fill: #2E5387;marker-allow-overlap: true;}#cbd_offices_locations::labels {text-name: [city];text-face-name: 'DejaVu Sans Book';text-size: 10;text-label-position-tolerance: 10;text-fill: #FFFFFF;text-halo-fill: #FFF;text-halo-radius: 0;text-dy: -10;text-allow-overlap: true;text-placement: point;text-placement-type: simple}" | |
} | |
] | |
}) | |
.addTo(map); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment