fixed bug with date order

getbounds now work
This commit is contained in:
Dani Carrion 2015-07-10 19:24:21 +02:00
parent 2c604a8279
commit 521ae23609
2 changed files with 97 additions and 10 deletions

View File

@ -9,11 +9,72 @@
padding: 0;
margin: 0;
}
#control {
display:none;
z-index: 10;
position: absolute;
left: 10px;
bottom: 10px;
background: #fff;
border-radius: 4px;
box-shadow: 0 0 4px rgba(0, 0, 0, .2);
padding: 8px;
margin: 0;
cursor: pointer;
}
#control:hover {
background: #f5f5f5;
}
#control span {
display: block;
width: 12px;
height: 12px;
vertical-align: middle;
position:relative
}
#control span.play:before {
content:"";
position: absolute;
display: block;
height: 10px;
width: 3px;
background: #666;
left: 2px;
top: 1px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
#control span.play:after {
content:"";
position: absolute;
display: block;
height: 10px;
width: 3px;
background: #666;
right: 1px;
top: 1px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
#control span.pause:before {
content:"";
position: absolute;
display: block;
height: 0px;
width: 0px;
border: 6px solid transparent;
border-left: 8px solid #666;
left: 3px;
}
</style>
</head>
<body>
<input type="file" id="files" name="files" />
<div id="map"></div>
<div id="map"><div id="control"><span class="play"></span></div></div>
<script src="vendor/leaflet.js"></script>
<script src="vendor/papaparse.min.js"></script>
@ -23,8 +84,8 @@
<script>
var map = new L.Map('map', {
zoomControl: true,
center: [40, -100],
zoom: 5
center: [40, 0],
zoom: 6
});
L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
@ -101,11 +162,11 @@
'}'
].join('\n');
var pointsToLoad = 1000;
var pointsToLoad = 50000;
var animationDuration = 60;
var steps = pointsToLoad;
var cumulative = true;
var steps = 2048;
var cumulative = false;
var loop = true;
var cartocss = CARTOCSS_NORMAL;
@ -127,14 +188,25 @@
complete: function (results) {
for (var i = 1; i <= pointsToLoad && i < results.data.length; i++) {
var point = results.data[i];
torqueLayer.provider.addPoint(point[1], point[0], point[3], point[2]);
torqueLayer.provider.addPoint(point[2], point[1], point[0], point[3]);
}
torqueLayer.provider.setReady();
document.getElementById('control').style.visibility = "visible";
torqueLayer.play();
}
});
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
function handlePlayPause(evt) {
if (torqueLayer.isRunning()) {
torqueLayer.pause();
} else {
torqueLayer.play();
}
}
document.getElementById('control').addEventListener('click', handlePlayPause, false);
</script>
</body>
</html>

View File

@ -18,6 +18,11 @@ var internal = function (options) {
}
this.points = [];
this._tileQueue = [];
this.options.bounds = [
[Number.MAX_VALUE, Number.MAX_VALUE],
[Number.MIN_VALUE, Number.MIN_VALUE]
];
};
@ -46,9 +51,13 @@ internal.prototype = {
this.points.sort(function (point1, point2) {
if (self.timestampType == "number") {
return point1.value - point2.value;
return point1.time - point2.time;
} else {
return new Date(point1.value) - new Date(point2.value);
if (typeof(point1.time) == "string") {
return new Date(point1.time) - new Date(point2.time);
} else {
return point1.time - point2.time;
}
}
});
@ -103,6 +112,13 @@ internal.prototype = {
maxLon: maxs[0]
};
/* Update total bounds */
if (tile.latLonBounds.maxLat > this.options.bounds[1][0]) this.options.bounds[1][0] = tile.latLonBounds.maxLat;
if (tile.latLonBounds.minLat < this.options.bounds[0][0]) this.options.bounds[0][0] = tile.latLonBounds.minLat;
if (tile.latLonBounds.maxLon > this.options.bounds[1][1]) this.options.bounds[1][1] = tile.latLonBounds.maxLon;
if (tile.latLonBounds.minLon < this.options.bounds[0][1]) this.options.bounds[0][1] = tile.latLonBounds.minLon;
/* Function to find out if a point falls into this tile */
tile.contains = function (point) {
return point.lat < tile.latLonBounds.maxLat && point.lat > tile.latLonBounds.minLat && point.lon < tile.latLonBounds.maxLon && point.lon > tile.latLonBounds.minLon;
@ -170,7 +186,6 @@ internal.prototype = {
var pointsInTileForFutureTimestamp = pointsInThisTileByTimestamp[futureTimestamps] || (pointsInThisTileByTimestamp[futureTimestamps] = []);
pointsInTileForFutureTimestamp.push({idx: pointIdx, value: point.value});
}
console.log(pointsInThisTileByTimestamp.length);
} else {
var pointsInTileForThisTimestamp = pointsInThisTileByTimestamp[pointTimestamp] || (pointsInThisTileByTimestamp[pointTimestamp] = []);
pointsInTileForThisTimestamp.push({idx: pointIdx, value: point.value});