Created
September 11, 2020 07:46
-
-
Save padawannn/414ead35dd0a4ff94d1ea925b4de43b9 to your computer and use it in GitHub Desktop.
deckgl-example-with-basemap-using-mapbox-custom-layers
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
<html> | |
<head> | |
<!-- deck.gl standalone bundle --> | |
<script src="https://unpkg.com/deck.gl@^8.2.8/dist.min.js"></script> | |
<!-- Mapbox dependencies --> | |
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.0/mapbox-gl.js"></script> | |
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.0/mapbox-gl.css" rel="stylesheet" /> | |
<style type="text/css"> | |
body {margin: 0; padding: 0;} | |
#map {width: 100vw; height: 100vh;} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
</body> | |
<script type="text/javascript"> | |
const {MapboxLayer} = deck; | |
const map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json', | |
center: [-73.9936065, 40.7368521], | |
zoom: 8 | |
}); | |
const COLORS = { | |
ONE_MILLION: [207, 89, 126], | |
HUNDRED_THOUSAND: [232, 133, 113], | |
TEN_THOUSAND: [238, 180, 121], | |
THOUSAND: [233, 226, 156], | |
HUNDRED: [156, 203, 134], | |
TEN: [57, 177, 133], | |
OTHER: [0, 147, 146] | |
}; | |
const myDeckLayer = new MapboxLayer({ | |
id: 'taxi-points', | |
type: deck.MVTLayer, | |
data: [ | |
'https://bq1.cartocdn.com/tile?y={y}&x={x}&z={z}&p=0_16_19257_19396_24574_24697_4000_1&t=cartobq.maps.nyc_taxi_points_demo_id', | |
'https://bq2.cartocdn.com/tile?y={y}&x={x}&z={z}&p=0_16_19257_19396_24574_24697_4000_1&t=cartobq.maps.nyc_taxi_points_demo_id', | |
'https://bq3.cartocdn.com/tile?y={y}&x={x}&z={z}&p=0_16_19257_19396_24574_24697_4000_1&t=cartobq.maps.nyc_taxi_points_demo_id', | |
'https://bq4.cartocdn.com/tile?y={y}&x={x}&z={z}&p=0_16_19257_19396_24574_24697_4000_1&t=cartobq.maps.nyc_taxi_points_demo_id' | |
], | |
getFillColor: object => { | |
if (object.properties.aggregated_total > 1000000) { | |
return COLORS.ONE_MILLION; | |
} else if (object.properties.aggregated_total > 100000) { | |
return COLORS.HUNDRED_THOUSAND; | |
} else if (object.properties.aggregated_total > 10000) { | |
return COLORS.TEN_THOUSAND; | |
} else if (object.properties.aggregated_total > 1000) { | |
return COLORS.THOUSAND; | |
} else if (object.properties.aggregated_total > 100) { | |
return COLORS.HUNDRED; | |
} else if (object.properties.aggregated_total > 10) { | |
return COLORS.TEN; | |
} else { | |
return COLORS.OTHER; | |
} | |
}, | |
pointRadiusMinPixels: 2, | |
stroked: false | |
}); | |
map.on('load', () => { | |
map.addLayer(myDeckLayer); | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment