// my personal token - please generate your own at https://www.mapbox.com/studio/
mapboxgl.accessToken = 'pk.eyJ1IjoibW91cm5lciIsImEiOiJWWnRiWG1VIn0.j6eccFHpE3Q04XPLI7JxbA';
// initialize a Mapbox map with the Basic style, centered in New York
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/cjf4m44iw0uza2spb3q0a7s41',
center: [-73.992, 40.734],
zoom: 12,
hash: true
});
map.addControl(new MapboxGeocoder({accessToken: mapboxgl.accessToken}), 'bottom-right');
map.addControl(new mapboxgl.NavigationControl(), 'top-left');
var h = 300; // size of the chart canvas
var r = h / 2; // radius of the polar histogram
var numBins = 64; // number of orientation bins spread around 360 deg.
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
canvas.style.width = canvas.style.height = h + 'px';
canvas.width = canvas.height = h;
if (window.devicePixelRatio > 1) {
canvas.width = canvas.height = h * 2;
ctx.scale(2, 2);
}
function updateOrientations() {
ctx.clearRect(0, 0, h, h);
var bearing = map.getBearing();
ctx.save();
ctx.translate(r, r);
ctx.rotate(-bearing * Math.PI / 180);
ctx.fillStyle = 'rgba(255,255,255,0.8)';
ctx.beginPath();
ctx.arc(0, 0, r, 0, 2 * Math.PI, false);
ctx.fill();
ctx.strokeStyle = 'rgba(0,0,0,0.15)';
ctx.beginPath();
ctx.moveTo(-r, 0);
ctx.lineTo(r, 0);
ctx.moveTo(0, -r);
ctx.lineTo(0, r);
ctx.stroke();
var features = map.queryRenderedFeatures({layers: ['road']});
if (features.length === 0) {
ctx.restore();
return;
}
var ruler = cheapRuler(map.getCenter().lat);
var bounds = map.getBounds();
var bbox = [bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth()];
var bins = new Float64Array(numBins);
for (var i = 0; i < features.length; i++) {
var geom = features[i].geometry;
var lines = geom.type === 'LineString' ?...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.