2019-07-05 00:40:53 +08:00
|
|
|
import * as matrix from 'zrender/src/core/matrix';
|
|
|
|
|
2019-07-07 22:56:09 +08:00
|
|
|
function createTransform(zoom) {
|
2019-07-05 00:40:53 +08:00
|
|
|
let transform = matrix.create();
|
2019-07-10 12:02:02 +08:00
|
|
|
transform = matrix.scale(matrix.create(), transform, [zoom.scaleRate, zoom.scaleRate]);
|
|
|
|
transform = matrix.translate(matrix.create(), transform, [-zoom.offsetX, -zoom.offsetY]);
|
2019-07-05 00:40:53 +08:00
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
2019-07-09 09:24:54 +08:00
|
|
|
function createBoundingRect(view) {
|
2019-07-07 22:56:09 +08:00
|
|
|
let rect = view.getBoundingRect();
|
|
|
|
let scale = view.scale[0];
|
|
|
|
let offsetX = view.position[0];
|
|
|
|
let offsetY = view.position[1];
|
|
|
|
rect.width = rect.width * scale;
|
|
|
|
rect.height = rect.height * scale;
|
|
|
|
rect.x = rect.x * scale + offsetX;
|
|
|
|
rect.y = rect.y * scale + offsetY;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2019-07-09 19:04:45 +08:00
|
|
|
class ZoomHandle {
|
2019-07-10 13:17:12 +08:00
|
|
|
constructor(painter, zr) {
|
|
|
|
this.$painter = painter;
|
|
|
|
this.$zr = zr;
|
2019-07-05 00:40:53 +08:00
|
|
|
|
2019-07-10 13:17:12 +08:00
|
|
|
this.rect = { x: 0, y: 0, width: this.$zr.getWidth(), height: this.$zr.getHeight() };
|
2019-07-09 09:24:54 +08:00
|
|
|
this.transform = createTransform({ scale: 1, offsetX: 0, offsetY: 0 });
|
|
|
|
}
|
|
|
|
|
2019-07-05 00:40:53 +08:00
|
|
|
checkVisible(view) {
|
2019-07-09 09:24:54 +08:00
|
|
|
return createBoundingRect(view).intersect(this.rect);
|
2019-07-05 00:40:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
revisibleView(view) {
|
2019-07-09 09:24:54 +08:00
|
|
|
if (this.checkVisible(view)) {
|
|
|
|
view.show();
|
|
|
|
} else {
|
|
|
|
view.hide();
|
2019-07-05 00:40:53 +08:00
|
|
|
}
|
2019-07-09 09:24:54 +08:00
|
|
|
|
|
|
|
view.dirty();
|
2019-07-05 00:40:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
transformView(view) {
|
2019-07-09 09:24:54 +08:00
|
|
|
if (view) {
|
|
|
|
view.transform = this.transform;
|
|
|
|
view.decomposeTransform();
|
|
|
|
this.revisibleView(view);
|
2019-07-05 00:40:53 +08:00
|
|
|
}
|
2019-07-09 09:24:54 +08:00
|
|
|
|
2019-07-05 00:40:53 +08:00
|
|
|
return view;
|
2019-07-09 09:24:54 +08:00
|
|
|
}
|
2019-07-05 00:40:53 +08:00
|
|
|
|
2019-07-09 09:24:54 +08:00
|
|
|
transformAll() {
|
2019-07-10 13:17:12 +08:00
|
|
|
let parentLevel = this.$painter.getParentLevel();
|
2019-07-10 12:02:02 +08:00
|
|
|
if (parentLevel) {
|
|
|
|
parentLevel.eachChild((level) => {
|
|
|
|
level.eachChild((view) => {
|
|
|
|
this.transformView(view);
|
|
|
|
});
|
2019-07-09 09:24:54 +08:00
|
|
|
});
|
2019-07-10 12:02:02 +08:00
|
|
|
}
|
2019-07-05 00:40:53 +08:00
|
|
|
}
|
2019-07-09 09:24:54 +08:00
|
|
|
|
2019-07-05 00:40:53 +08:00
|
|
|
revisibleAll() {
|
2019-07-10 13:17:12 +08:00
|
|
|
let parentLevel = this.$painter.getParentLevel();
|
2019-07-10 12:02:02 +08:00
|
|
|
if (parentLevel) {
|
|
|
|
parentLevel.eachChild((level) => {
|
|
|
|
level.eachChild((view) => {
|
|
|
|
this.revisibleView(view);
|
|
|
|
});
|
2019-07-09 09:24:54 +08:00
|
|
|
});
|
2019-07-10 12:02:02 +08:00
|
|
|
}
|
2019-07-05 00:40:53 +08:00
|
|
|
}
|
2019-07-09 09:24:54 +08:00
|
|
|
|
2019-07-05 00:40:53 +08:00
|
|
|
updateTransform(zoom) {
|
2019-07-07 22:56:09 +08:00
|
|
|
this.transform = createTransform(zoom);
|
2019-07-05 00:40:53 +08:00
|
|
|
this.transformAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 19:04:45 +08:00
|
|
|
export default ZoomHandle;
|