123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- addEvent("onload", init);
- addEvent("onresize", checkOrientation);
- var channelmonitoractive = false;
- var screenmode = 0;
- var label_start_monitor_label = "START";
- var label_stop_monitor_label = "STOP";
- var initial_value = "";
- function init(){
- try {
- document.getElementById("MonitorToggle").innerHTML = label_start_monitor_label;
- var myStyleTweaks = new StyleTweaker();
- myStyleTweaks.add("Series60/5.0", "styles/tweaks/S605th.css");
- myStyleTweaks.add("Series60/3.2", "styles/tweaks/S603rdFP2.css");
- myStyleTweaks.tweak();
-
- initSystemServices();
- }
-
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- function checkOrientation(){
- try {
- var width = parseInt(screen.width);
- var height = parseInt(screen.height);
-
- //var landscapeTweaker = new StyleTweaker();
- // Landscape tweaks for template styles not available in templates?
- //landscapeTweaker.add("Series60/5.0", "../resources/styles/tweaks/S605thLandscape.css");
-
- if (width > height) {
-
- // if already in landscape mode, return
- if (screenmode == 1)
- return;
- screenmode = 1;
- // landscapeTweaker.tweak();
- }
- else {
- // if already in portrait mode, return
- if (screenmode == 0)
- return;
- screenmode = 0;
- // landscapeTweaker.untweak();
- }
- }
-
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- /*
- Onclick handler for start/stop monitoring button
- Starts and stops position monitoring
- */
- function MonitorToggle_onclick(actionobj){
- try {
- if (channelmonitoractive) {
- actionobj.innerHTML = label_start_monitor_label;
- stopMonitoring();
- }
- else {
- actionobj.innerHTML = label_stop_monitor_label;
- startMonitoring();
- }
- channelmonitoractive = !channelmonitoractive;
- }
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- /*
- Displays position data in widget ui.
- result object is passed to display function in
- service platform asyncronous callback handlers. Schema:
- Position
- {
- "coords": Coordinates ,
- "timestamp": Date
- }
- Coordinates
- {
- "latitude": number,
- "longitude": number,
- "altitude": number,
- "accuracy": number, //currently Not Supported
- "altitudeAccuracy": number, //currently Not Supported
- "heading": number,
- "speed": number,
- }
- */
- function displayPositionData(result){
- try {
- document.getElementById("lat").innerHTML = round(result.coords.latitude) + " \u00B0";
- document.getElementById("lon").innerHTML = round(result.coords.longitude) + " \u00B0";
- if (result.coords.altitude != null && !isNaN(result.coords.altitude))
- document.getElementById("alt").innerHTML = Math.round(result.coords.altitude) + " m";
- if (result.coords.heading != null)
- document.getElementById("heading").innerHTML = result.coords.heading + " \u00B0";
- if (result.coords.speed != null)
- document.getElementById("speed").innerHTML = result.coords.speed + " m/s";
- if (result.timestamp != null)
- document.getElementById("time").innerHTML = formatDateTime(result.timestamp);
- }
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- /*
- This function puts initial label for all elements in UI
- */
- function UIReset(){
- try {
- document.getElementById("lat").innerHTML = initial_value;
- document.getElementById("lon").innerHTML = initial_value;
- document.getElementById("alt").innerHTML = initial_value;
- document.getElementById("heading").innerHTML = initial_value;
- document.getElementById("speed").innerHTML = initial_value;
- document.getElementById("time").innerHTML = initial_value;
- }
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- /*
- * Rounds number
- */
- function round(v){
- var a = 100000;
- return Math.round(v * a) / a;
- }
- /*
- * Formats JS Date object in form: 'dd/MM/yyyy hh:mm'
- * date - date object to be formated
- */
- function formatDateTime(date){
-
- if (typeof date == "string") {
- return date;
- }
- else {
- var separator = "/";
- return preformatNumber(date.getDate()) + separator + preformatNumber((date.getMonth() + 1)) + separator + date.getFullYear() + " " + preformatNumber(date.getHours()) + ":" + preformatNumber(date.getMinutes()) + ":" + preformatNumber(date.getSeconds());
- }
- }
- /*
- * Adds extra '0' in front of number if it is < 10
- */
- function preformatNumber(n){
- return n < 10 ? "0" + n : n;
- }
|