Last active
February 1, 2019 17:33
-
-
Save rochoa/c38c19c16c8ff2eb7505d3092a252d8c to your computer and use it in GitHub Desktop.
Manhattan buildings by number of floors over the years | CARTO VL
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>Manhattan buildings by number of floors over the years | CARTO VL</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta charset="UTF-8"> | |
<!-- Include CARTO VL JS --> | |
<script src="https://libs.cartocdn.com/carto-vl/v0.4.0/carto-vl.js"></script> | |
<!-- Include Mapbox GL JS --> | |
<script src="https://libs.cartocdn.com/mapbox-gl/v0.45.0-carto1/mapbox-gl.js"></script> | |
<!-- Include Mapbox GL CSS --> | |
<link href="https://libs.cartocdn.com/mapbox-gl/v0.45.0-carto1/mapbox-gl.css" rel="stylesheet" /> | |
<style> | |
body { | |
margin: 0; | |
padding: 0; | |
} | |
#map { | |
position: absolute; | |
height: 100%; | |
width: 100%; | |
} | |
#year { | |
position: fixed; | |
left: 48px; | |
top: 48px; | |
color: white; | |
font-size: 42px; | |
font-family: sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<div id="year"> | |
1785 | |
</div> | |
<script> | |
const s = carto.expressions; | |
const map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json', | |
center: [-73.97536949793329, 40.75490160473558], | |
zoom: 12, | |
dragRotate: false | |
}); | |
carto.setDefaultAuth({ | |
user: 'cartovl', | |
apiKey: 'default_public' | |
}); | |
const source = new carto.source.Dataset('mnmappluto'); | |
const NO_FADE_OUT = Number.MAX_SAFE_INTEGER; | |
const viz = new carto.Viz(` | |
color: ramp(linear(log($numfloors), 1, 4), SunsetDark) | |
strokeWidth: 0 | |
filter: $numfloors != 0 and torque(linear($yearbuilt, 1765, 2018), 30, fade(0.5, ${NO_FADE_OUT})) | |
`); | |
const torque = viz.filter.b; | |
const layer = new carto.Layer('layer', source, viz); | |
layer.addTo(map, 'watername_ocean'); | |
const year = document.querySelector('#year'); | |
setInterval(() => { | |
year.innerText = Math.floor(torque.getSimTime()); | |
}, 250); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment