0,0 → 1,132 |
if (typeof jsx == "undefined") |
{ |
/** |
* @namespace |
*/ |
var jsx = {}; |
} |
|
if (typeof jsx.dom == "undefined") |
{ |
/** |
* @namespace |
*/ |
jsx.dom = {}; |
} |
|
jsx.dom.geolocation = { |
TEXT_LATITUDE: "Latitude", |
TEXT_NORTH_ABBR: "N", |
TEXT_SOUTH_ABBR: "S", |
TEXT_LONGITUDE: "Longitude", |
TEXT_WEST_ABBR: "W", |
TEXT_EAST_ABBR: "E", |
TEXT_LAT_LNG_ACCURACY: "Lat/Lng Accuracy", |
TEXT_ALTITUDE: "Altitude", |
TEXT_ALT_ACCURACY: "Alt. Accuracy", |
TEXT_SPEED: "Speed", |
TEXT_HEADING: "Heading", |
TEXT_NOT_AVAILABLE: "N/A", |
|
getPosition: function () { |
return this._position; |
}, |
|
setPosition: function (value) { |
this._position = value; |
}, |
|
getLatitudeString: function (position) { |
if (!position) |
{ |
position = this.getPosition(); |
} |
|
var latitude = position.coords.latitude; |
return (latitude != null |
? Math.abs(latitude) + "°\xA0" |
+ (latitude < 0 ? this.TEXT_SOUTH_ABBR : this.TEXT_NORTH_ABBR) |
: this.TEXT_NOT_AVAILABLE); |
}, |
|
getLongitudeString: function (position) { |
if (!position) |
{ |
position = this.getPosition(); |
} |
|
var longitude = position.coords.longitude; |
return (longitude != null |
? Math.abs(longitude) + "°\xA0" |
+ (longitude < 0 ? this.TEXT_WEST_ABBR : this.TEXT_EAST_ABBR) |
: this.TEXT_NOT_AVAILABLE); |
}, |
|
getLatLngAccuracyString: function (position) { |
if (!position) |
{ |
position = this.getPosition(); |
} |
|
return position.coords.accuracy + "\xA0m"; |
}, |
|
getAltitudeString: function (position) { |
if (!position) |
{ |
position = this.getPosition(); |
} |
|
var altitude = position.coords.altitude; |
return (altitude != null |
? altitude + "\xA0m" |
: this.TEXT_NOT_AVAILABLE); |
}, |
|
getAltAccuracyString: function (pposition) { |
if (!position) |
{ |
position = this.getPosition(); |
} |
|
return (altitudeAccuracy != null |
? altitudeAccuracy + "\xA0m" |
: this.TEXT_NOT_AVAILABLE); |
}, |
|
getSpeedString: function (position) { |
if (!position) |
{ |
position = this.getPosition(); |
} |
|
var speed = position.coords.speed; |
return (speed != null && !isNaN(speed) |
? speed + " m/s" |
: this.TEXT_NOT_AVAILABLE); |
}, |
|
getHeadingString: function (position) { |
if (!position) |
{ |
position = this.getPosition(); |
} |
|
var heading = position.coords.heading; |
return (heading != null && !isNaN(heading) |
? heading + "°" |
: this.TEXT_NOT_AVAILABLE); |
}, |
|
getText: function (position) { |
return [ |
this.TEXT_LATITUDE + ": " + this.getLatitudeString(position), |
this.TEXT_LONGITUDE + ": " + this.getLongitudeString(position), |
this.TEXT_LAT_LNG_ACCURACY + ": " + this.getLatLngAccuracyString(position), |
this.TEXT_ALTITUDE + ": " + this.getAltitudeString(position), |
this.TEXT_ALT_ACCURACY + ": " + this.getAltAccuracyString(position), |
this.TEXT_SPEED + ": " + this.getSpeedString(position), |
this.TEXT_HEADING + ": " + this.getHeadingString(position) |
].join("\n"); |
} |
}; |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: trunk/lcars.js |
=================================================================== |
--- trunk/lcars.js (revision 456) |
+++ trunk/lcars.js (revision 457) |
@@ -302,6 +302,9 @@ |
MultiDisplay: (function lcars_MultiDisplay () { |
lcars_MultiDisplay._super.apply(this, arguments); |
}).extend(jsx.dom.widgets.Container, { |
+ TEXT_ACCURACY: "accuracy", |
+ TEXT_NOT_AVAILABLE: "N/A", |
+ |
/** |
* @memberOf lcars.MultiDisplay |
* @type jsx.dom.widgets.Container |
@@ -317,9 +320,22 @@ |
init: function () { |
this._title = new jsx.dom.widgets.Container(document.getElementById("title")); |
+ this._analysis = new jsx.dom.widgets.Container(document.getElementById("analysis")); |
this._content = new lcars.Content(); |
}, |
|
+ setTexts: function (texts) { |
+ var keys = jsx.object.getKeys(texts); |
+ for (var i = 0, len = keys.length; i < len; ++i) |
+ { |
+ var key = keys[i]; |
+ if (typeof this[key] == "string") |
+ { |
+ this[key] = texts[key]; |
+ } |
+ } |
+ }, |
+ |
/** |
* Sets the title of the multi-display |
* |
@@ -331,6 +347,29 @@ |
this._title.update(); |
}, |
|
+ setAnalysis: function (table) { |
+ var s = "<table>"; |
+ for (var i = 0, len = table.length; i < 3; ++i) |
+ { |
+ var item = table[i]; |
+ s += "<tr><th>" + item.title + ":</th>" |
+ + "<td>" + item.value.replace(/\xA0/g, " ") + "</td>"; |
+ var item2; |
+ if (len > 3 && (item2 = table[i + 3])) |
+ { |
+ s += "<th>" + item2.title + ":</th>" |
+ + "<td>" |
+ + item2.value.replace(/\xA0/g, " ").replace(/\//g, "∕") |
+ + "</td>"; |
+ } |
+ s += "</tr>"; |
+ } |
+ s += "</table>"; |
+ |
+ this._analysis.setInnerHTML(s); |
+ this._analysis.update(); |
+ }, |
+ |
geolocate: function (title, language) { |
this.setTitle(title); |
|
@@ -337,6 +376,41 @@ |
var me = this; |
navigator.geolocation.getCurrentPosition(function (position) { |
lcars.setPosition(position); |
+ var coords = position.coords; |
+ var altitudeAccuracy = coords.altitudeAccuracy; |
+ var _geolocation = jsx.dom.geolocation; |
+ _geolocation.setPosition(position); |
+ me.setAnalysis([ |
+ { |
+ title: "Latitude", |
+ value: _geolocation.getLatitudeString() |
+ }, |
+ { |
+ title: "Longitude", |
+ value: _geolocation.getLongitudeString() |
+ }, |
+ { |
+ title: "Lat/Lng Accuracy", |
+ value: _geolocation.getLatLngAccuracyString() |
+ }, |
+ { |
+ title: "Altitude", |
+ value: _geolocation.getAltitudeString() |
+ + (altitudeAccuracy != null |
+ ? " (" + _geolocation.getAltAccuracyString() |
+ + " " + this.TEXT_ACCURACY + ")" |
+ : "") |
+ }, |
+ { |
+ title: "Speed", |
+ value: _geolocation.getSpeedString() |
+ }, |
+ { |
+ title: "Heading", |
+ value: _geolocation.getHeadingString() |
+ } |
+ ]); |
+ |
me._content.showMap(language); |
me = null; |
}); |
@@ -349,8 +423,8 @@ |
//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, |
@@ -440,7 +514,7 @@ |
_position: null, |
|
/** |
- * @return {Geoposition} |
+ * @return {Position} |
*/ |
getPosition: function () { |
return this._position; |
@@ -447,7 +521,7 @@ |
}, |
|
/** |
- * @param {Geoposition} position |
+ * @param {Position} position |
*/ |
setPosition: function (position) { |
this._position = position; |