Built with blockbuilder.org
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src='https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.css' rel='stylesheet' />
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
#map {
position:absolute;
width: 100%;
height: 100%;
}
#date-changer {
position:absolute;
writing-mode: bt-lr;
-webkit-appearance: slider-vertical;
width: 8px;
height: 380px;
padding: 0 5px;
position: absolute;
top:70px;
left:15px;
}
#dateValue {
position:absolute;
writing-mode: bt-lr;
-webkit-appearance: slider-vertical;
width: 150px;
height: 380px;
padding: 0 5px;
position: absolute;
top:440px;
left:35px;
color: blue;
}
</style>
</head>
<body>
<div id="map">
</div>
<div>
<input type="range" value="0" min="0" max="296" orient="vertical" id="date-changer"/>
</div>
<div>
<label><span id="dateValue">dimanche 04/02/2018</span></label>
</div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiZW5qYWxvdCIsImEiOiJjaWhtdmxhNTIwb25zdHBsejk0NGdhODJhIn0.2-F2hS_oTZenAWc0BMf_uw'
//Setup Leaflet map using Mapbox.js
var map = L.mapbox.map('map', 'mapbox.pencil', {maxZoom: 18, minZoom: 12})
.setView([45.7531152, 4.827906], 12);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="https://mapbox.com">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(map);
// Setup our svg layer that we can manipulate with d3
var svg = d3.select(map.getPanes().overlayPane)
.append("svg");
var g = svg.append("g").attr("class", "leaflet-zoom-hide");
var hour = 10;
var minutes = 0;
d3.select("#date-changer").on("input", function() {
//console.log(data.values);
console.log(this.value);
var fileName = "file"+this.value+".json";
console.log(fileName);
/*minutes = minutes + this.value * 5;
if(minutes >= 60) {
hour = hour +1;
minutes = 0;
}
if(hour >= 24) {
hour = 0;
}
var dateExact = "dimanche 04/02/2018-"+hour+":"+minutes;
d3.select('#dateValue').html(dateExact);*/
mainCode(fileName);
});
d3.select("#date-changer").on("change", function() {
//console.log(data.values);
console.log(this.value);
var fileName = "file"+this.value+".json";
console.log(fileName);
/*minutes = minutes + this.value * 5;
if(minutes >= 60) {
hour = hour +1;
minutes = 0;
}
if(hour >= 24) {
hour = 0;
}
var dateExact = "dimanche 04/02/2018-"+hour+":"+minutes;
d3.select('#dateValue').html(dateExact);*/
mainCode(fileName);
//https://bl.ocks.org/nivas8292/bec8b161587cb62e9fda
});
function project(ll) {
// our data came from csv, make it Leaflet friendly
var a = [+ll.lat, +ll.lon];
//console.log(ll)
// convert it to pixel coordinates
var point = map.latLngToLayerPoint(L.latLng(ll))
return point;
}
function taille(ll) {
var a = [+ll.bike_stands];
return a;
}
function mainCode(fileName) {
d3.json(fileName, function(err, data) {
var dots = g.selectAll("circle.dot")
.data(data.values)
console.log(data.values)
dots.enter().append("circle").classed("dot", true)
.attr("r", 1)
.style({
fill: "#0082a3",
"fill-opacity": 0.6,
stroke: "#004d60",
"stroke-width": 1
})
.transition().duration(1000)
.attr("r",4)
function render() {
// We need to reposition our SVG and our containing group when the map
// repositions via zoom or pan
// https://github.com/zetter/voronoi-maps/blob/master/lib/voronoi_map.js
var bounds = map.getBounds();
var topLeft = map.latLngToLayerPoint(bounds.getNorthWest())
var bottomRight = map.latLngToLayerPoint(bounds.getSouthEast())
svg.style("width", map.getSize().x + "px")
.style("height", map.getSize().y + "px")
.style("left", topLeft.x + "px")
.style("top", topLeft.y + "px");
g.attr("transform", "translate(" + -topLeft.x + "," + -topLeft.y + ")");
// We reproject our data with the updated projection from leaflet
g.selectAll("circle.dot")
.attr({
cx: function(d) { return project(d).x},
cy: function(d) { return project(d).y},
r: function(d) {return taille(d)/5}
})
}
// re-render our visualization whenever the view changes
map.on("viewreset", function() {
render()
})
map.on("move", function() {
render()
})
// render our initial visualization
render()
})
}
</script>
</body>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js
https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.js