Skip to content

Instantly share code, notes, and snippets.

@ingenieroariel
Forked from Lenninlasd/README
Last active October 31, 2017 21:42
Show Gist options
  • Save ingenieroariel/312c02240c8f9590d445fff3f110a361 to your computer and use it in GitHub Desktop.
Save ingenieroariel/312c02240c8f9590d445fff3f110a361 to your computer and use it in GitHub Desktop.
Heatmap
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.41.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.41.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
var file = (location.search.split('&')[0].split('=')[1] || 'places') + '.geojson';
var line_file = (location.search.split('&')[0].split('=')[1] || 'lines') + '.geojson';
mapboxgl.accessToken = 'pk.eyJ1IjoiaW5nZW5pZXJvYXJpZWwiLCJhIjoibXhDZ3pIMCJ9.qTmPYCbnUKtaNFkvKKysAQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/dark-v9',
center: [38, 11],
zoom: 6
});
map.on('load', function() {
//Add a geojson point source.
//Heatmap layers also work with a vector tile source.
map.addSource('jda', {
"type": "geojson",
"data": file
});
map.addSource('power', {
"type": "geojson",
"data": line_file
});
map.addLayer({
"id": "jda-heat",
"type": "heatmap",
"source": "jda",
"maxzoom": 15,
"paint": {
//Color ramp for heatmap. Domain is 0 (low) to 1 (high).
//Begin color ramp at 0-stop with a 0-transparancy color
//to create a blur-like effect.
//.RdYlGn .q0-6{fill:rgb(215,48,39)} .RdYlGn .q1-6{fill:rgb(252,141,89)} .RdYlGn .q2-6{fill:rgb(254,224,139)} .RdYlGn .q3-6{fill:rgb(217,239,139)} .RdYlGn .q4-6{fill:rgb(145,207,96)} .RdYlGn .q5-6{fill:rgb(26,152,80)}
// ['rgb(254,229,217)','rgb(252,187,161)','rgb(252,146,114)','rgb(251,106,74)','rgb(222,45,38)','rgb(165,15,21)']
"heatmap-color": {
"stops": [
[0, "rgba(254,229,217,0.0)"],
[0.2, "rgba(252,187,161, 0.2)"],
[0.4, "rgba(252,146,114, 0.5)"],
[0.6, "rgba(251,106,74, 0.7)"],
[0.8, "rgba(222,45,38,1)"],
[1, "rgba(165,15,21,1)"]
]
},
//Adjust the heatmap radius by zoom level
"heatmap-radius": {
"stops": [
[0, 1],
[6, 1.5],
[7, 3],
[8, 4],
[9, 5],
[10, 10],
[12, 20],
[20, 30]
]
},
//Transition from heatmap to circle layer by zoom level
"heatmap-opacity": {
"default": 1,
"stops": [
[12, 1],
[13, 1],
[19, 0.5],
[20, 0.5],
[24, 0]
]
},
}
}, 'waterway-label');
map.addLayer({
"id": "jda-point",
"type": "symbol",
"source": "jda",
"minzoom": 12,
"layout": {
"text-field": "{LO_NAME}",
"text-size": 24
},
"paint": {
"text-color": "rgba(250,250,250,0.8)",
"text-halo-color": "rgba(250, 250, 250, 1)"
}
}, 'waterway-label');
map.addLayer({
"id": "power-line",
"type": "line",
"source": "power",
"layout": {
"line-join": "round",
"line-cap": "round"
},
"paint": {
"line-color": "rgba(255,255,153, 1)",
"line-width": 3
}
}, 'waterway-label');
});
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment