Skip to content

Instantly share code, notes, and snippets.

@mastersigat
Last active February 2, 2021 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mastersigat/f1a214028cb5b2dd6cb842db6be99846 to your computer and use it in GitHub Desktop.
Save mastersigat/f1a214028cb5b2dd6cb842db6be99846 to your computer and use it in GitHub Desktop.
# MapboxGL / Cluster
license: mit
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Create a heatmap layer</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.1.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>
mapboxgl.accessToken = 'pk.eyJ1IjoibmluYW5vdW4iLCJhIjoiY2pjdHBoZGlzMnV4dDJxcGc5azJkbWRiYSJ9.o4dZRrdHcgVEKCveOXG1YQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/dark-v10',
center: [2.33, 48.85],
zoom: 11
});
map.on('load', function() {
// Ajout du GeoJSON
map.addSource('horodateurs', {
type: 'geojson',
data: 'https://www.dl.dropboxusercontent.com/s/vv8liud5r50kqtu/horodateurs-mobiliers.geojson?dl=0',
cluster: true,
clusterMaxZoom: 15,
clusterRadius: 50
});
// Configuration des tailles et des couleurs
map.addLayer({
'id': 'horodateurs',
'type': 'circle',
'source': 'horodateurs',
filter: ['has', 'point_count'],
paint: {'circle-color': ['step',['get', 'point_count'],
'#51bbd6',50,
'#f1f075',500,
'#f28cb1'],
'circle-radius': ['step',
['get', 'point_count'],
20,100,30,500,50]}
});
// Configuration etiquette
map.addLayer({ id: 'cluster-count',
type: 'symbol',
source: 'horodateurs',
filter: ['has', 'point_count'],
layout: {
'text-field': '{point_count_abbreviated}',
'text-font': ['DIN Offc Pro Medium', 'Arial Unicode MS Bold'],
'text-size': 12
}
});
// COnfiguration symbologie des points non clusterises
map.addLayer({
id: 'unclustered-point',
type: 'circle',
source: 'horodateurs',
filter: ['!', ['has', 'point_count']],
paint: {
'circle-color': '#11b4da',
'circle-radius': 4,
'circle-stroke-width': 1,
'circle-stroke-color': '#fff'
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment