Skip to content

Commit

Permalink
add Tween
Browse files Browse the repository at this point in the history
  • Loading branch information
hinikai committed Dec 15, 2016
1 parent df7f1ae commit 46cdd24
Show file tree
Hide file tree
Showing 17 changed files with 9,885 additions and 4,062 deletions.
8,342 changes: 4,470 additions & 3,872 deletions build/mapv.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/mapv.min.js

Large diffs are not rendered by default.

4,475 changes: 4,475 additions & 0 deletions build/release/mapv.v2.0.3.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build/release/mapv.v2.0.3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export var version = "2.0.2";
export var version = "2.0.3";
7 changes: 5 additions & 2 deletions examples/baidu-map-forceEdgeBundling.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,12 @@
size: 1.5,
animation: {
type: 'time',
steps: 100,
stepsRange: {
start: 0,
end: 100
},
trails: 1,
duration: 5
duration: 5,
},
draw: 'simple'
}
Expand Down
2 changes: 1 addition & 1 deletion examples/baidu-map-point-heatmap-time.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
end: 100
},
trails: 10,
duration: 5,
duration: 4,
},
draw: 'heatmap'
}
Expand Down
11 changes: 7 additions & 4 deletions examples/baidu-map-polyline-time.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@

rs = rs.split("\n");
console.log(rs.length);
var maxLength = 0;
for (var i = 0; i < rs.length; i++) {
var item = rs[i].split(',');
var coordinates = [];
if (item.length > maxLength) {
maxLength = item.length;
}
for (j = 0; j < item.length; j += 2) {
coordinates.push([item[j], item[j + 1]]);
timeData.push({
Expand All @@ -202,8 +206,7 @@
geometry: {
type: 'LineString',
coordinates: coordinates
},
count: 30 * Math.random()
}
});

}
Expand Down Expand Up @@ -233,9 +236,9 @@
animation: {
stepsRange: {
start: 0,
end: 100
end: 100
},
trails: 1,
trails: 3,
duration: 5,
},
draw: 'simple'
Expand Down
2 changes: 1 addition & 1 deletion examples/qianxi.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
end: 50
},
trails: 10,
duration: 3,
duration: 2,
},
draw: 'simple'
}
Expand Down
Binary file modified nodeCanvasExamples/line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion nodeCanvasExamples/showLineCsvData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var fs = require("fs");
var width = 1300;
var height = 800;
var center = [121.489723, 31.248408];
var zoom = 10;
var zoom = 8;
//var center = [118.489723, 31.248408];

var Canvas = require('canvas')
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mapv",
"version": "2.0.2",
"version": "2.0.3",
"description": "a library of geography visualization",
"main": "build/mapv.js",
"scripts": {
Expand Down Expand Up @@ -36,5 +36,6 @@
"rollup": "^0.25.8",
"rollup-plugin-babel": "^2.4.0",
"uglify-js": "^2.6.2"
}
},
"dependencies": {}
}
8 changes: 4 additions & 4 deletions src/canvas/draw/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ function draw(context, dataSet, options) {
var data = dataSet.get();

context.save();
console.time('drawGray')
//console.time('drawGray')
drawGray(context, data, options);
console.timeEnd('drawGray');
//console.timeEnd('drawGray');
// return false;
if (!options.absolute) {
console.time('changeColor');
//console.time('changeColor');
var colored = context.getImageData(0, 0, context.canvas.width, context.canvas.height);
colorize(colored.data, utilsColorPalette.getImageData({
defaultGradient: options.gradient || {
Expand All @@ -134,7 +134,7 @@ function draw(context, dataSet, options) {
1.0: "rgba(255, 0, 0, 1)"
}
}), options);
console.timeEnd('changeColor');
//console.timeEnd('changeColor');
context.putImageData(colored, 0, 0);

context.restore();
Expand Down
52 changes: 37 additions & 15 deletions src/map/baidu-map/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ import Intensity from "../../utils/data-range/Intensity";
import Category from "../../utils/data-range/Category";
import Choropleth from "../../utils/data-range/Choropleth";
import Animator from "../../utils/animation/Animator";
import TWEEN from "../../utils/animation/Tween";
import pathSimple from "../../canvas/path/simple";

if (typeof window !== 'undefined') {
requestAnimationFrame(animate);
}

function animate(time) {
requestAnimationFrame(animate);
TWEEN.update(time);
}

function Layer(map, dataSet, options) {
if (!(dataSet instanceof DataSet)) {
dataSet = new DataSet(dataSet);
Expand All @@ -28,11 +38,11 @@ function Layer(map, dataSet, options) {
var data = null;
options = options || {};

self.map = map;

self.init(options);
self.argCheck(options);

self.map = map;

var canvasLayer = this.canvasLayer = new CanvasLayer({
map: map,
paneName: options.paneName,
Expand Down Expand Up @@ -90,6 +100,7 @@ Layer.prototype._canvasUpdate = function(time) {

if (self.isEnabledTime()) {
if (time === undefined) {
clear(context);
return;
}
context.save();
Expand Down Expand Up @@ -287,30 +298,41 @@ Layer.prototype.init = function(options) {
var animationOptions = self.options.animation;

if (self.options.draw == 'time' || self.isEnabledTime()) {
if (!self.animator) {
self.animator = new Animator(function(time) {
self._canvasUpdate(time);
}, {
steps: animationOptions.steps || 100,
stepsRange: animationOptions.stepsRange || 100,
animationDuration: animationOptions.duration || 10
});
//if (!self.animator) {
if (!animationOptions.stepsRange) {
animationOptions.stepsRange = {
start: this.dataSet.getMin('time') || 0,
end: this.dataSet.getMax('time') || 0
}
}

var steps = { step: animationOptions.stepsRange.start };
self.animator = new TWEEN.Tween(steps)
.onUpdate(function() {
self._canvasUpdate(this.step);
})
.repeat(Infinity);

map.addEventListener('movestart', function() {
self.map.addEventListener('movestart', function() {
if (self.isEnabledTime() && self.animator) {
self.animator.pause();
self.animator.stop();
}
});

map.addEventListener('moveend', function() {
self.map.addEventListener('moveend', function() {
if (self.isEnabledTime() && self.animator) {
self.animator.start();
}
});
}
//}

var duration = animationOptions.duration * 1000 || 5000;

self.animator.to({ step: animationOptions.stepsRange.end }, duration);
self.animator.start();

} else {
self.animator && self.animator.pause();
self.animator && self.animator.stop();
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/map/baidu-map/Layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,8 @@ dataSet中添加字段
### mapvLayer.update({
options: {} // 修改配置
});
### mapvLayer.setOptions({
size: 1
}); // 重新设置配置
### mapvLayer.show(); // 显示图层
### mapvLayer.hide(); // 删除图层
Loading

0 comments on commit 46cdd24

Please sign in to comment.