Subversion Repositories JSX

Compare Revisions

Last modification

Regard whitespace Rev 455 → Rev 456

/trunk/lcars.js
199,7 → 199,7
moveTo: function(x, y) {
this.x = x;
this.y = y;
if (dhtml.getStyle(this.obj, "display") == 'visible') this.repaint();
if (dhtml.getStyle(this.obj, "display") == 'visible'){this.repaint();}
}
};
 
206,13 → 206,14
/**
* Creates a new LCARS Timer widget.
*
* Takes up to three. The first two may define the relative position
* of the corresponding block element in CSS units of length, while
* the third one allows to initialize the timer in milliseconds.
* Takes up to three arguments. The first two may define the
* relative position of the corresponding block element in CSS
* units of length, while the third one allows to initialize
* the timer in milliseconds.
*
* @param [optional] {String} x
* @param [optional] {String} y
* @param [optional] {Number} nStart
* @param {String} x [optional]
* @param {String} y [optional]
* @param {Number} nStart [optional]
*/
function LCARSTimer(x, y, nStart)
{
227,4 → 228,230
{
this.value = 0;
}
};
};
 
if (jsx.object.getFeature(jsx, "dom", "widgets"))
{
/**
* @type lcars
* @memberOf __lcars
* @namespace
*/
var lcars = (/** @constructor */ function () {
"use strict";
 
return {
/**
* @type Content
* @memberOf lcars
* @extends jsx.dom.widgets.Container
*/
Content: (function lcars_Content () {
lcars_Content._super.apply(this, arguments);
}).extend(jsx.dom.widgets.Container, {
init: function () {
this._target = document.getElementById("content");
},
 
/**
* @param {String} title
* @param {String} language
*/
showMap: function (language) {
//document.getElementById("content").innerHTML = "<\?php echo tr('Your current coordinates on Terra'); ?>\n\n" + this.getText(position);
var content = document.getElementById("content");
 
var map = lcars._gmaps_map;
if (!map)
{
/* Disable transition while map is loading */
content.style.transition = "none";
content.className = "fixed";
this.setInnerHTML(
// '<select><option>Google Maps</option><option>OpenStreetMap</option></select>'
'<div id="map-canvas" style="position: absolute; width: 100%; height: 100%"></div>');
this.update();
}
 
var script = this._gmaps_script;
if (!script)
{
script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js"
+ "?key=AIzaSyCpW3bu57j4V7_vcK_cVpvFkXMmKkKgADI"
+ "&sensor=true&callback=lcars.multiDisplay.initGMap"
+ "&language=" + language;
document.body.appendChild(script);
if (script.parentNode == document.body)
{
this._gmaps_script = script;
}
}
else
{
lcars.multiDisplay.initGMap();
}
}
}),
 
/**
* @type MultiDisplay
* @extends jsx.dom.widgets.Container
*/
MultiDisplay: (function lcars_MultiDisplay () {
lcars_MultiDisplay._super.apply(this, arguments);
}).extend(jsx.dom.widgets.Container, {
/**
* @memberOf lcars.MultiDisplay
* @type jsx.dom.widgets.Container
* @protected
*/
_title: null,
 
/**
* @type jsx.dom.widgets.Container
* @protected
*/
_content: null,
 
init: function () {
this._title = new jsx.dom.widgets.Container(document.getElementById("title"));
this._content = new lcars.Content();
},
 
/**
* Sets the title of the multi-display
*
* @param {String} s
* New title
*/
setTitle: function (s) {
this._title.setText(s);
this._title.update();
},
 
geolocate: function (title, language) {
this.setTitle(title);
 
var me = this;
navigator.geolocation.getCurrentPosition(function (position) {
lcars.setPosition(position);
me._content.showMap(language);
me = null;
});
 
return false;
},
 
initGMap: function () {
var coords = lcars.getPosition().coords;
//var title = document.getElementById("title");
//title.firstChild.textContent = [coords.latitude.toFixed(), "° ", coords.longitude, "° (", coords.accuracy, "\xA0m)"].join("");
var center = new google.maps.LatLng(coords.latitude, coords.longitude);
var zoom = 9;
 
var zoomAccuracy = [
1e7, 5e6, 2e6, 2e6, 1e6, 5e5, 2e5, 1e5, 5e4,
2e4, 1e4, 5e3, 2000, 2000, 1000, 500, 200,
100, 50, 20
];
 
var accuracy = coords.accuracy;
if (!isNaN(accuracy))
{
for (var i = 0, len = zoomAccuracy.length; i < len; ++i)
{
if (accuracy > zoomAccuracy[i])
{
zoom = i;
break;
}
}
}
 
var map = lcars._gmaps_map;
if (!map)
{
var mapOptions = {
center: center,
zoom: zoom,
mapTypeId: google.maps.MapTypeId.HYBRID,
backgroundColor: "#000",
noClear: true,
scaleControl: true
};
 
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
lcars._gmaps_map = map;
}
else
{
map.setCenter(center);
map.setZoom(zoom);
}
 
var circle = this._gmaps_circle;
if (!circle)
{
if (!isNaN(coords.accuracy))
{
circle = new google.maps.Circle({
map: map,
center: center,
radius: coords.accuracy,
fillColor: "white",
fillOpacity: 0.125,
strokeColor: "white",
strokeOpacity: 0.5
});
 
circle.addListener("click", function () {
// TODO
// window.alert("<\?php echo tr('Your current coordinates on Terra'); ?>\n\n"
window.alert("Your current coordinates on Terra\n\n"
+ jsx.dom.geolocation.getText(lcars.getPosition()));
});
 
this._gmaps_circle = circle;
}
}
else
{
if (!isNaN(coords.accuracy))
{
circle.setCenter(center);
circle.setRadius(coords.accuracy);
}
else
{
circle.setMap(null);
}
}
 
/* Restore transition */
document.getElementById("content").style.transition = "";
}
}),
 
/**
* @protected
*/
_position: null,
 
/**
* @return {Geoposition}
*/
getPosition: function () {
return this._position;
},
 
/**
* @param {Geoposition} position
*/
setPosition: function (position) {
this._position = position;
}
};
}());
}