2
* @author Patrick Schmiedel patrick.schmiedel@gmx.net
6
* @classDescription A user interface element that shows the latitude/longitude value of the location under the mouse cursor.
8
var SunCoordsDisplay = Class.create();
10
SunCoordsDisplay.prototype = Object.extend(new SunViewerWidget(), {
17
* @param {Sring} elementId The ID of the SunCoordsDisplay HTML element.
18
* @param {TileLayerProvider} layerProvider The corresponding TileLayerProvider.
19
* @param {Hash} options Available options: decimals
21
initialize: function(elementId, layerProvider, options) {
22
this.domNode = $(elementId);
23
this.layerProvider = layerProvider;
25
Object.extend(this, this.defaultOptions);
26
Object.extend(this, options);
28
this.createElements();
30
Event.observe(this.layerProvider.tileContainer.viewport.domNode, 'mousemove', this.updateCoords.bindAsEventListener(this));
34
* @method createElements Creates the user interface HTML elements.
36
createElements: function() {
37
var table = document.createElement('table');
38
table.className = 'sunCoordsDisplay';
40
var tr = document.createElement('tr')
41
this.latText = document.createElement('td');
42
this.latText.width = 15;
43
this.latValue = document.createElement('td');
44
this.latValue.width = 25;
45
this.lonText = document.createElement('td');
46
this.lonText.width = 15;
47
this.lonValue = document.createElement('td');
48
this.lonValue.width = 25;
49
tr.appendChild(this.latText);
50
tr.appendChild(this.latValue);
51
tr.appendChild(this.lonText);
52
tr.appendChild(this.lonValue);
53
table.appendChild(tr);
54
this.domNode.appendChild(table);
58
* TODO: Move to LatLon.fromXY()
59
* @method XYToRad Converts (x,y) pixel coordinates in the viewport to latitude/longitude sun coordinates.
60
* @param {Number} x The x coordinate in the viewport in pixels.
61
* @param {Number} y The y coordinate in the viewport in pixels.
62
* @return {Hash} The latitude/longitude coordinates or null if out of bounds.
64
XYToRad: function (x, y) {
65
if (!this.layerProvider.sunImage) return null;
66
var sunRadius = this.layerProvider.sunImage.sunRadius * this.layerProvider.getFullSize();
67
var viewerPosition = this.layerProvider.tileContainer.viewport.position;
68
var y1 = (y - viewerPosition.y) / sunRadius;
69
if (-1 <= y1 && y1 <= 1) {
70
var latitudeRad = Math.asin(y1);
72
var x1 = (x - viewerPosition.x) / sunRadius;
73
var x2 = x1 / Math.cos(latitudeRad);
74
if (-1 <= x2 && x2 <= 1) {
75
var longitudeRad = Math.asin(x2);
77
return { latitude: latitudeRad, longitude: longitudeRad };
84
* @method displayCoords Shows the latitude/longitude values in the user interface element.
85
* @param {Number} latitude The latitude value.
86
* @param {Number} longitude The longitude value.
88
displayCoords: function(latitude, longitude) {
89
var showCoords = (latitude != null && longitude != null);
90
this.latValue.innerHTML = showCoords ? Math.abs(latitude.toFixed(this.decimals)) : '';
91
this.latText.innerHTML = showCoords ? (latitude < 0 ? 'N' : 'S') : '';
92
this.lonValue.innerHTML = showCoords ? Math.abs(longitude.toFixed(this.decimals)) : '';
93
this.lonText.innerHTML = showCoords ? (longitude < 0 ? 'E' : 'W') : '';
97
* @method updateCoords Calculates the sun coordinates and shows them in the user interface.
98
* @param {DOM MouseEvent} e The DOM MouseEvent.
100
updateCoords: function(e) {
101
if (this.layerProvider.tileContainer.viewport.surface.moving) return;
102
var viewportOffset = this.layerProvider.tileContainer.viewport.offset;
104
x: Event.pointerX(e) - viewportOffset[0],
105
y: Event.pointerY(e) - viewportOffset[1]
107
var screenSunCoords = this.XYToRad(screenCoords.x, screenCoords.y);
108
if (screenSunCoords == null) {
109
this.displayCoords();
111
var realSunCoordsDeg = {
112
latitude: screenSunCoords.latitude + this.layerProvider.sunImage.date.getObliquity(),
113
longitude: screenSunCoords.longitude
115
this.displayCoords(realSunCoordsDeg.latitude.toDeg(), realSunCoordsDeg.longitude.toDeg());
b'\\ No newline at end of file'