~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to lib/helioviewer/ViewportHandlers.js

  • Committer: V. Keith Hughitt
  • Date: 2008-11-18 17:48:06 UTC
  • Revision ID: hughitt1@kore-20081118174806-1e1a5j63rgwkfk71
nightly build 11-18-2008

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*global Class, Object, document, window, Event, $ */
2
2
var ViewportHandlers = Class.create({
3
 
        startingPosition: { x: 0, y: 0 },
 
3
        startingPosition:      { x: 0, y: 0 },
4
4
        mouseStartingPosition: { x: 0, y: 0 },
5
 
        mouseCurrentPosition: { x: 0, y: 0 },
6
 
        moveCounter: 0,
 
5
        mouseCurrentPosition:  { x: 0, y: 0 },
 
6
        moveCounter:  0,
7
7
        moveThrottle: 2,
 
8
        naturalZoomLevel:  10,
 
9
        naturalResolution: 2.63,
8
10
 
9
11
        initialize: function (viewport) {
10
12
                this.viewport = viewport;
67
69
        
68
70
        /**
69
71
         * @function
70
 
         * @description Get the mouse-coords relative to the center of the sun
 
72
         * @description Get the mouse-coords relative to top-left of the viewport frame
71
73
         * @param {Object}
72
74
         */
73
75
        getRelativeCoords: function (screenx, screeny) {
74
 
                var viewport = this.viewport;
 
76
                var vp = this.viewport;
75
77
                
76
78
                //Compute offset from top-left of browser viewport
77
 
                var xOffset = $('left-col').getDimensions().width + Math.round(0.03 * viewport.outerNode.getDimensions().width) + 2;
78
 
                var yOffset = $(viewport.headerId).getDimensions().height + Math.round(0.03 * viewport.outerNode.getDimensions().height) + 3;
 
79
                var xOffset = $('left-col').getDimensions().width   + Math.round(0.03 * vp.outerNode.getDimensions().width) + 2;
 
80
                var yOffset = $(vp.headerId).getDimensions().height + Math.round(0.03 * vp.outerNode.getDimensions().height) + 3;
79
81
 
80
82
                // Mouse-coordinates relative to the top-left of the viewport
81
83
                var mouseCoords = {
82
84
                        x: screenx - xOffset,
83
85
                        y: screeny - yOffset
84
86
                }
85
 
 
86
 
                // Coordinates of moving container relative to topleft corner
87
 
                var containerPos = viewport.getContainerPos();
88
 
                console.dir(containerPos);
89
87
                
90
 
                // Mouse-coordinates relative to the Heliocentric origin
91
 
                return {
92
 
                        x: mouseCoords.x - containerPos.x,
93
 
                        y: mouseCoords.y - containerPos.y
94
 
                }
 
88
                return mouseCoords;
95
89
        },
96
90
 
97
91
        /**
186
180
         */
187
181
        toggleMouseCoords: function () {
188
182
                this.viewport.displayMouseCoords = ! this.viewport.displayMouseCoords;
 
183
                $('mouse-coords').toggle();
189
184
                
190
185
                if (this.viewport.displayMouseCoords) {
191
186
                        var self = this;
 
187
                        var mouseCoordsX = $('mouse-coords-x');
 
188
                        var mouseCoordsY = $('mouse-coords-y');
192
189
                        Event.observe(this.viewport.movingContainer, "mousemove", function(e) {
193
190
                                self.moveCounter = (self.moveCounter + 1) % self.moveThrottle;
194
191
                                if (self.moveCounter !== 0) {
195
192
                                        return;
196
193
                                }
197
 
                                var pos = self.getRelativeCoords(e.pointerX(), e.pointerY());
198
 
                                console.log("x: " + pos.x + ",y: " + pos.y);
 
194
                                var VX = self.getRelativeCoords(e.pointerX(), e.pointerY());
 
195
                                var negSV = self.viewport.sandbox.positionedOffset();
 
196
                                var SV = {
 
197
                                        x: -negSV[0],
 
198
                                        y: -negSV[1]
 
199
                                }
 
200
                                var SM = this.positionedOffset();                               
 
201
                                var MX = {
 
202
                                        x: VX.x + (SV.x - SM[0]),
 
203
                                        y: VX.y + (SV.y - SM[1])
 
204
                                };
 
205
                                
 
206
                                //scale
 
207
                                var scale = self.naturalResolution * Math.pow(2, self.viewport.zoomLevel - self.naturalZoomLevel);
 
208
                                var x = Math.round((scale * MX.x)) + "";
 
209
                                var y = Math.round((scale * MX.y)) + "";
 
210
                                
 
211
                                mouseCoordsX.update("x: " + x + " ′′");
 
212
                                mouseCoordsY.update("y: " + y + " ′′");
199
213
                        });
200
214
                } else {
201
215
                        Event.stopObserving(this.viewport.movingContainer, "mousemove");