for (i = 0; i < datalen; i += 1) {
posVal = posFunc(data[i], i);
animationState.order[i] = {i: i, x: posVal.x, y: posVal.y};
}
animationState.order = animationState.order.sort(function (a, b) {
if (a.x !== b.x) { return b.x - a.x; }
if (a.y !== b.y) { return b.y - a.y; }
return b.i - a.i;
}).map(function (val) {
return val.i;
});
} else {
for (i = 0; i < datalen; i += 1) {
animationState.order[i] = i;
}
}
animationState.styleArrays = {
p: new Array(datalen),
radius: new Array(datalen),
fill: new Array(datalen),
fillColor: new Array(datalen),
fillOpacity: new Array(datalen),
stroke: new Array(datalen),
strokeColor: new Array(datalen),
strokeOpacity: new Array(datalen),
strokeWidth: new Array(datalen)
};
for (i = 0; i < datalen; i += 1) {
animationState.styleArrays.fillColor[i] = {r: 0, g: 0, b: 0};
animationState.styleArrays.strokeColor[i] = {r: 0, g: 0, b: 0};
}
}
animationState.mode = 'play';
animation_frame();
}
function animation_stop() {
if (animationState.mode && animationState.mode !== 'stop') {
if (animationState.raf) {
window.cancelAnimationFrame(animationState.raf);
animationState.raf = null;
}
reset_styles();
animationState.position = null;
animationState.mode = 'stop';
}
}
function reset_styles() {
pointFeature.style({
fill: true,
fillColor: { r: 1.0, g: 0.839, b: 0.439 },
fillOpacity: 0.8,
radius: 5.0,
stroke: true,
strokeColor: { r: 0.851, g: 0.604, b: 0.0 },
strokeWidth: 1.25,
strokeOpacity: 1.0
});
pointFeature.draw();
}
function show_framerate() {
if (timeRecords.frames.length < 2) {
return;
}
var timeSpan = 5000,
endPos = timeRecords.frames.length - 1,
endTime = timeRecords.frames[endPos],
startPos, startTime, fps, generate = 0, update = 0;
for (startPos = endPos; startPos > 0; startPos -= 1) {
if (endTime - timeRecords.frames[startPos] > timeSpan) {
break;
}
generate += timeRecords.generate[startPos];
update += timeRecords.update[startPos];
}
startTime = timeRecords.frames[startPos];
timeSpan = endTime - startTime;
fps = (endPos - startPos) * 1000 / timeSpan;
generate /= (endPos - startPos);
update /= (endPos - startPos);
$('#timing-framerate').text(fps.toFixed(1));
$('#timing-generate').text(generate.toFixed(1));
$('#timing-update').text(update.toFixed(1));
if (startPos > 1000) {
timeRecords.frames.splice(0, startPos);
timeRecords.generate.splice(0, startPos);
timeRecords.update.splice(0, startPos);
}
}
map.createLayer('osm');
layer = map.createLayer('feature', layerOptions);
pointFeature = layer.createFeature('point', {
primitiveShape: query.primitive ? query.primitive : geo.pointFeature.primitiveShapes.auto
})
.position(function (d) {
return {x: d[2], y: d[1]};
});
fetch_data();
$('#controls').on('change', change_controls);
$('button#play').on('click', animation_play);
$('button#pause').on('click', animation_pause);
$('button#stop').on('click', animation_stop);
});