| author | ymh <ymh.work@gmail.com> |
| Thu, 02 Aug 2018 16:15:39 +0200 | |
| changeset 593 | f8310b7ddef0 |
| parent 146 | f912b591e1c1 |
| permissions | -rw-r--r-- |
|
146
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
1 |
/* enable zoom */ |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
2 |
import { eventEmitter } from '../utils' |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
3 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
4 |
class ZoomHandler { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
5 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
6 |
constructor (params) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
7 |
this.zoomFactor = 0.1 || params.zoomFactor; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
8 |
this.paper = params.paper; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
9 |
this.MIN_SIZE = 40; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
10 |
this.imageWidth = parseInt(this.paper.select(".main-image").attr("width")); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
11 |
this.imageHeight = parseInt(this.paper.select(".main-image").attr("height")); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
12 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
13 |
this.viewport = { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
14 |
width: parseInt(this.paper.attr("width")), |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
15 |
height: parseInt(this.paper.attr("height")) |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
16 |
}; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
17 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
18 |
this.scale = 1; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
19 |
this.paper.attr({stroke: 2, "fill": "blue" }); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
20 |
this.disableDrag = false; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
21 |
this.imgMinSize = Math.min(this.imageWidth, this.imageHeight); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
22 |
this.lastPosition = []; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
23 |
this.updateViewBox([0 , 0, this.imageWidth, this.imageHeight]); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
24 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
25 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
26 |
testShowCenter (cx, cy) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
27 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
28 |
if (this.center) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
29 |
this.center.remove(); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
30 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
31 |
this.center = this.paper.rect(cx - 3, cy - 3, 20, 20); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
32 |
this.center.attr({"fill" : "red"}); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
33 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
34 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
35 |
drawTestRectangle (cx, cy, w, h) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
36 |
var x = cx - w / 2; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
37 |
var y = cy - h / 2; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
38 |
this.paper.rect(x, y, w, h); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
39 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
40 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
41 |
zoomIn () { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
42 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
43 |
/* current center */ |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
44 |
if ( this.scale === 9) { this.scale--; return; } |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
45 |
var currentCenterX = this.currentViewBox[0] + (this.currentViewBox[2] / 2); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
46 |
var currentCenterY = this.currentViewBox[1] + (this.currentViewBox[3] / 2); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
47 |
var scaleFactor = this.zoomFactor * this.scale; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
48 |
var viewBoxW = this.imgMinSize - (this.imgMinSize * scaleFactor); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
49 |
var viewBoxH = viewBoxW; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
50 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
51 |
this.currentViewBox[0] = currentCenterX - viewBoxW / 2; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
52 |
this.currentViewBox[1] = currentCenterY - viewBoxH / 2; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
53 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
54 |
this.currentViewBox[2] = viewBoxW; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
55 |
this.currentViewBox[3] = viewBoxH; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
56 |
this.scale ++; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
57 |
this.updateViewBox(); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
58 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
59 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
60 |
updateViewBox (currentViewBox, notify) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
61 |
notify = (typeof notify === "boolean") ? notify : true; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
62 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
63 |
if (currentViewBox && currentViewBox.length != 4) { throw new Error("Provided currentViewBox is not valid!"); } |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
64 |
if (currentViewBox) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
65 |
this.currentViewBox = currentViewBox; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
66 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
67 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
68 |
this.paper.attr({"viewBox": this.currentViewBox}); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
69 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
70 |
if (!notify) { return false; } |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
71 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
72 |
var self = this; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
73 |
eventEmitter.emit("zoomChanged", { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
74 |
updateFunction: function (updatedViewBox) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
75 |
self.updateViewBox(updatedViewBox, false); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
76 |
}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
77 |
"zoomFactor": this.getZoomFactor(), |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
78 |
"viewport": this.viewport, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
79 |
"currentScale": this.scale, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
80 |
"imageSize": {width: this.imageWidth, height: this.imageHeight}, |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
81 |
"minSize": Math.min(this.imageWidth, this.imageHeight), |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
82 |
"currentViewBox": this.currentViewBox.slice() |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
83 |
}); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
84 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
85 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
86 |
getZoomFactor () { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
87 |
return { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
88 |
x: this.viewport.width / this.currentViewBox[2], |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
89 |
y: this.viewport.height / this.currentViewBox[3] |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
90 |
}; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
91 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
92 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
93 |
onStart (x, y, e) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
94 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
95 |
this.lastPosition[0] = this.currentViewBox[0]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
96 |
this.lastPosition[1] = this.currentViewBox[1]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
97 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
98 |
if (e.target.className.baseVal === "drawingHandler") { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
99 |
this.disableDrag = true; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
100 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
101 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
102 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
103 |
canDrag () { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
104 |
return !this.disableDrag; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
105 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
106 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
107 |
onStop () { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
108 |
this.disableDrag = false; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
109 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
110 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
111 |
onDrag (dx, dy, x, y, event) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
112 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
113 |
if (!this.canDrag()) { return true; } |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
114 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
115 |
var newX = this.lastPosition[0] - dx; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
116 |
var newY = this.lastPosition[1] - dy; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
117 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
118 |
/* maxX bound */ |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
119 |
if (newX + this.currentViewBox[2] >= this.viewport.width) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
120 |
newX = this.viewport.width - this.currentViewBox[2]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
121 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
122 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
123 |
/* maxY bound */ |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
124 |
if (newY + this.currentViewBox[3] >= this.viewport.height) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
125 |
newY = this.viewport.height - this.currentViewBox[3]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
126 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
127 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
128 |
if (newX <= 0) { newX = 0; } |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
129 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
130 |
if(newY <= 0) { newY = 0; } |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
131 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
132 |
this.currentViewBox[0] = newX; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
133 |
this.currentViewBox[1] = newY; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
134 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
135 |
this.updateViewBox(); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
136 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
137 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
138 |
reset () { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
139 |
this.scale = 1; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
140 |
this.currentViewBox = [0, 0, this.imageWidth, this.imageHeight]; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
141 |
this.updateViewBox(); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
142 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
143 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
144 |
zoomOut () { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
145 |
if (this.scale == 1) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
146 |
return false; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
147 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
148 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
149 |
var currentCenterX = this.currentViewBox[0] + (this.currentViewBox[2] / 2); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
150 |
var currentCenterY = this.currentViewBox[1] + (this.currentViewBox[3] / 2); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
151 |
var scaleFactor = this.zoomFactor * (this.scale - 1); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
152 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
153 |
var viewBoxW = this.imgMinSize - (this.imgMinSize * scaleFactor); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
154 |
var viewBoxH = viewBoxW; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
155 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
156 |
var topX = currentCenterX - viewBoxW / 2; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
157 |
var topY = currentCenterY - viewBoxH / 2; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
158 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
159 |
this.currentViewBox[0] = topX; //deal with X and Y |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
160 |
this.currentViewBox[1] = topY; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
161 |
this.currentViewBox[2] = viewBoxW; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
162 |
this.currentViewBox[3] = viewBoxH; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
163 |
this.updateViewBox(); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
164 |
this.scale--; |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
165 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
166 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
167 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
168 |
export default { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
169 |
|
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
170 |
enable_zoom: function (params) { |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
171 |
return new ZoomHandler(params); |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
172 |
} |
|
f912b591e1c1
new src_js folder
Harris Baptiste <harris.baptiste@iri.centrepompidou.fr>
parents:
diff
changeset
|
173 |
} |