Last active
February 15, 2019 13:55
-
-
Save makella/32c8919acd357a23c078f88c3ad8ac7e to your computer and use it in GitHub Desktop.
CARTO Product Gathering 2/15
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>Product Gathering | CARTO</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta charset="UTF-8"> | |
<script src="https://libs.cartocdn.com/carto-vl/v1.1.1/carto-vl.min.js"></script> | |
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.js"></script> | |
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.css" rel="stylesheet" /> | |
<link href="https://carto.com/developers/carto-vl/v1.1.1/examples/maps/style.css" rel="stylesheet"> | |
</head> | |
<body> | |
<div id="map"></div> | |
<style> | |
html, | |
body { | |
margin: 0; | |
} | |
#map { | |
position: absolute; | |
width: 100%; | |
height: 100%; | |
} | |
</style> | |
<script> | |
const map = new mapboxgl.Map({ | |
container: 'map', | |
//style: 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json', | |
style: { | |
version: 8, | |
sources: {}, | |
layers: [ | |
{ | |
id: 'background', | |
type: 'background', | |
paint: { 'background-color': 'black' } | |
} | |
] | |
}, | |
center: [0, 0], | |
zoom: 1, | |
scrollZoom: true, | |
//set pitch and bearing | |
//pitch: 60, //map.getPitch() in degrees | |
//bearing: 0.03535930738712523, // map.getBearing() in degrees | |
}); | |
const nav = new mapboxgl.NavigationControl({ | |
showCompass: true | |
}); | |
map.addControl(nav, 'top-left'); | |
// Define user | |
carto.setDefaultAuth({ | |
username: 'cartovl', | |
apiKey: 'default_public' | |
}); | |
// Define layers | |
const citiesSource = new carto.source.SQL(` | |
SELECT * FROM pop_density_points | |
`); | |
const citiesViz = new carto.Viz(` | |
symbol: opacity(ramp(linear($dn),ag_sunset),1)*ramp(buckets(100*(0.5*now()%1 >0.5),[50]), [ | |
image('https://libs.cartocdn.com/goodbye-images/luis.svg'), | |
image('https://libs.cartocdn.com/goodbye-images/goodbye.svg') | |
]) | |
width: scaled(ramp($dn,[5,45]),1 ) | |
order: desc(width()) | |
filter: $dn>150 | |
`); | |
const citiesLayer = new carto.Layer('citiesLayer', citiesSource, citiesViz); | |
const countriesSource = new carto.source.SQL(` | |
SELECT * FROM bathy_points | |
`); | |
const countriesViz = new carto.Viz(` | |
width: scaled(sqrt(clusterAvg($dn))/4,1.5) | |
strokeWidth: 0 | |
symbol: opacity(ramp(linear(clusterAvg($dn)),[deeppink,hotpink,#2E2D88,#30d5c8,#b2efeb]),0.8)*image('https://libs.cartocdn.com/goodbye-images/peri-white.svg') | |
//symbol: opacity(ramp(linear(clusterAvg($dn),[darkblue,turquoise])),ramp(clusterAvg($dn),[0.3,0.9])*linear(clusterAvg($dn)))*image('../styling/peri-white.svg') | |
//symbol: opacity(turquoise,0.3+0.9*linear(clusterAvg($dn)))*image('../styling/peri-white.svg') | |
symbolPlacement: placement(cos(0.1*(clusterAvg($dn)/2)*now()) , sin(0.1*(clusterAvg($dn)/2)*now())) | |
resolution: 0.5 | |
`); | |
const countriesLayer = new carto.Layer('countriesLayer', countriesSource, countriesViz); | |
citiesLayer.addTo(map); | |
countriesLayer.addTo(map, 'citiesLayer'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment