Skip to content

Instantly share code, notes, and snippets.

@mikeomeara1
Created December 7, 2018 23:51
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 mikeomeara1/683be7893d5790fe090da2995722071c to your computer and use it in GitHub Desktop.
Save mikeomeara1/683be7893d5790fe090da2995722071c to your computer and use it in GitHub Desktop.
mapboxgl.accessToken = "your_access_token" ;
/** Create Map */
var map = new mapboxgl.Map({container: "map",
style: 'mapbox://styles/mapbox/streets-v9',
center: [-98, 38.88],
zoom: 3});
/** Init Client */
var mapboxClient = mapboxSdk({ accessToken: mapboxgl.accessToken });
map.on("load", () => {
/** Call Isochrone API */
mapboxClient.isochrone.getContours({
coordinates: [-118.22258,33.99038],
minutes: [5,10,15],
profile: "driving",
colors: ['6706ce','04e813','4286f4'],
polygons: true
})
.send()
.then(response => {
/** Log Response */
console.log(response);
/** Add Layer to Map */
map.addLayer({
'id': 'isochrone',
'type': 'fill',
'source': {
'type': 'geojson',
'data': response.body
},
'layout': {},
'paint': {
'fill-color': ['get', 'color'],
'fill-opacity': 0.8
}
});
/** Zoom to Shape */
var coordinates = response.body.features[0].geometry.coordinates[0];
var bounds = coordinates.reduce(function(bounds, coord) {
return bounds.extend(coord);
}, new mapboxgl.LngLatBounds(coordinates[0], coordinates[0]));
map.fitBounds(bounds, {
padding: 20
});
}, error => {console.error(error)});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment