lib.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. /*
  2. Copyright (c) 2013 Mapo developers and contributors <mapo.tizen@gmail.com>
  3. This file is part of Mapo.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /*
  16. * Application Global variables
  17. */
  18. var web = "http://notabug.org/tizen/mapo";
  19. // The map of the application
  20. var map = null;
  21. // The boolean which provide the connection state of the application
  22. var isReady = true;
  23. var isLog = false;
  24. var isOnline = navigator.onLine;
  25. var isLoaded = false;
  26. var isDownloaded = false;
  27. /*
  28. * Recording Global Variable
  29. */
  30. // Directory where the recording document is placed
  31. var docDir;
  32. // Name of the recording document
  33. var doc;
  34. // The file where the records are placed
  35. var file;
  36. // Boolean which provide the information if a file has been recorded
  37. var fileRecorded = false;
  38. var url_openlayers = "http://openlayers.org/api/OpenLayers.js";
  39. var url_gmaps = "http://maps.google.com/maps/api/js?v=3.2&sensor=false";
  40. var url_gmaps = 'http://maps.googleapis.com/maps/api/js?v=3.2&signed_in=true&callback=handleLoadedGmaps';
  41. /*
  42. * General Manager
  43. */
  44. /**
  45. * Quit the application
  46. */
  47. function exit() {
  48. tizen.application.getCurrentApplication().exit();
  49. }
  50. /**
  51. * Show a message
  52. *
  53. * @param message
  54. */
  55. function log(message) {
  56. if (isLog) {
  57. console.log("# " + message);
  58. var element = document.getElementById("console");
  59. element.innerHTML += "<pre>" + message + "</pre>";
  60. }
  61. }
  62. // upstream: https://gist.github.com/kamranzafar/3136584#comment-1244934
  63. function toast(message) {
  64. var $toast = $('<div class="ui-loader ui-overlay-shadow ui-body-e ui-corner-all"><h3>'
  65. + message + '</h3></div>');
  66. $toast.css({
  67. display : 'block',
  68. background : '#fff',
  69. opacity : 0.90,
  70. position : 'fixed',
  71. padding : '7px',
  72. 'text-align' : 'center',
  73. width : '270px',
  74. left : ($(window).width() - 284) / 2,
  75. top : $(window).height() / 2 - 20
  76. });
  77. var removeToast = function() {
  78. $(this).remove();
  79. };
  80. $toast.click(removeToast);
  81. $toast.appendTo($.mobile.pageContainer).delay(2000);
  82. $toast.fadeOut(400, removeToast);
  83. }
  84. function handleError(message) {
  85. message = "error: " + message;
  86. log(message);
  87. toast(message);
  88. return message;
  89. }
  90. function handleException(e) {
  91. return handleError(e.name);
  92. }
  93. function handleSuccess() {
  94. return log("success: ");
  95. }
  96. /*
  97. * Storage Manager
  98. */
  99. /**
  100. * Store the coordinates values in the local storage
  101. */
  102. function storeData() {
  103. localStorage.setItem('lat', $('#lat').val());
  104. localStorage.setItem('lon', $('#lon').val());
  105. localStorage.setItem('dms', $('#dms').val());
  106. }
  107. /**
  108. * Store the settings values in the local storage
  109. */
  110. function storeSettings() {
  111. log("#{ storeSettings: " + isOnline);
  112. localStorage.setItem('connection', $('#switchOnline').val());
  113. localStorage.setItem('energySaving', $('#switchEnergy').val());
  114. localStorage.setItem('timeout', $('#selectorTimeout').val());
  115. localStorage.setItem('downloaded', isDownloaded);
  116. log("#} storeSettings: " + isOnline);
  117. }
  118. function store() {
  119. var i = 0;
  120. var r = $.Deferred();
  121. storeData();
  122. storeSettings();
  123. for (i = 0; i < localStorage.length; i++) {
  124. log(i + " -- " + localStorage.key(i) + " : "
  125. + localStorage.getItem(localStorage.key(i)));
  126. }
  127. r.resolve();
  128. return r;
  129. }
  130. /**
  131. * Store the data before quitting the application
  132. */
  133. function quit() {
  134. log("#{ exit");
  135. store().done(exit);
  136. log("#} exit");
  137. }
  138. /*
  139. * Set Manager
  140. */
  141. /**
  142. * Modify the latitude value
  143. *
  144. * @param lat :
  145. * new latitude value
  146. */
  147. function setLat(lat) {
  148. if (document.getElementById("lat").value !== lat) {
  149. document.getElementById("lat").value = lat;
  150. }
  151. }
  152. /**
  153. * Modify the longitude value
  154. *
  155. * @param lon :
  156. * new longitude value
  157. */
  158. function setLon(lon) {
  159. if (document.getElementById("lon").value !== lon) {
  160. document.getElementById("lon").value = lon;
  161. }
  162. }
  163. /*
  164. * Link Manager
  165. */
  166. /**
  167. * Get the OpenStreetMap link with the corresponding latitude and longitude
  168. *
  169. * @returns url
  170. */
  171. function getLink(provider) {
  172. var lat = $("#lat").val();
  173. var lon = $("#lon").val();
  174. var url;
  175. switch (provider) {
  176. case 'OSM':
  177. url = "http://www.openstreetmap.org/?&zoom=10&layers=mapnik&lat=${lat}&lon=${lon}";
  178. break;
  179. case 'GM':
  180. url = "http://maps.google.com/maps?&z=10&ll=${lat},${lon}";
  181. break;
  182. case 'HERE':
  183. url = "http://maps.nokia.com/${lat},${lon},16,0,0,normal.day";
  184. break;
  185. case 'bing':
  186. url = "http://www.bing.com/maps/?v=2&style=r&lvl=13&cp=48.11~${lat}~${lon}&style=r&lvl=4";
  187. break;
  188. case 'wigle':
  189. url = "https://wigle.net/map?maplat=${lat}&maplon=${lon}&mapzoom=12&startTransID=20010000-00000&endTransID=20170000-00000";
  190. break;
  191. default:
  192. url = "http://www.openstreetmap.org/?&zoom=10&layers=mapnik&lat=${lat}&lon=${lon}";
  193. break;
  194. }
  195. url = url.replace("${lon}", lon);
  196. url = url.replace("${lat}", lat);
  197. return url;
  198. }
  199. /**
  200. * Use the Internet Application Control to go to OSM link with the browser
  201. */
  202. function goToURL(provider) {
  203. var i = 0;
  204. var j = 0;
  205. if (isOnline) {
  206. var appControl = new tizen.ApplicationControl(
  207. "http://tizen.org/appcontrol/operation/view",
  208. getLink(provider), null);
  209. var appControlReplyCallback = {
  210. onsuccess : function(data) {
  211. for (i = 0; i < data.length; i++) {
  212. log("#" + i + " key:" + data[i].key);
  213. for (j = 0; j < data[i].value.length; j++) {
  214. log(" value#" + j + ":" + data[i].value[j]);
  215. }
  216. }
  217. },
  218. onfailure : function() {
  219. log('The launch application control failed');
  220. }
  221. }
  222. tizen.application.launchAppControl(appControl, null, function() {
  223. log("launch internet application control succeed");
  224. }, function(e) {
  225. log("launch internet application control failed. reason: "
  226. + e.message);
  227. }, appControlReplyCallback);
  228. } else {
  229. handleError("Please connect your application online in the settings"
  230. + " if you want to open a browser")
  231. }
  232. }
  233. /**
  234. * update links TODO: check if needed ?
  235. */
  236. // function updateLinks() {
  237. // $('#OSMLink').attr('href', getOSMLink());
  238. // }
  239. /*
  240. * Map Manager
  241. */
  242. /**
  243. * get the size of the map (width, height) according to the dimension of the
  244. * screen
  245. *
  246. * @returns [ width, height ]
  247. */
  248. function getMapSize() {
  249. var viewHeight = $(window).height();
  250. var viewWidth = $(window).width();
  251. var header = $("div[data-role='header']:visible:visible");
  252. var footer = $("div[data-role='footer']:visible:visible");
  253. var navbar = $("div[data-role='navbar']:visible:visible");
  254. var content = $("div[data-role='content']:visible:visible");
  255. var contentHeight = viewHeight - header.outerHeight()
  256. - navbar.outerHeight() - footer.outerHeight();
  257. var contentWidth = viewWidth - 30;
  258. return [ contentWidth, contentHeight ];
  259. }
  260. /**
  261. * Modify the dimension of the map according to getMapSize()
  262. */
  263. function setMapSize(size) {
  264. size = getMapSize();
  265. $('#myMap').css("width", size[0]);
  266. $('#myMap').css("height", size[1]);
  267. }
  268. function initIcon() {
  269. var size = new OpenLayers.Size(21, 25);
  270. var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
  271. return new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',
  272. size, offset);
  273. }
  274. function loadTrace(data) {
  275. var i = 0;
  276. log("loadTrace data : " + data['dates'][0]);
  277. var icon = initIcon();
  278. log("tab lons = " + data['lons']);
  279. log("tab lats = " + data['lats']);
  280. log("tab dates = " + data['dates']);
  281. for (i = 0; i < data['dates'].length; i++) {
  282. var lon = parseFloat(data['lons'][i]);
  283. var lat = parseFloat(data['lats'][i]);
  284. var date = data['dates'][i];
  285. log("data['dates'][" + i + "] = " + date);
  286. log("data['lons'][" + i + "] = " + lon);
  287. log("data['lat'][" + i + "] = " + lat);
  288. log("lat before : " + lat);
  289. log("lon before : " + lon);
  290. var lonlat = new OpenLayers.LonLat(lon, lat).transform('EPSG:4326',
  291. 'EPSG:3857');
  292. var mark = new OpenLayers.Marker(lonlat, icon);
  293. trace.addMarker(mark);
  294. }
  295. map.addLayer(trace);
  296. }
  297. /**
  298. * Load the OpenLayers map with different OpenStreetMap and Google maps' layers
  299. * TODO: check if needed ?
  300. */
  301. function loadMap() {
  302. log("#{ loadMap: " + OpenLayers);
  303. if (OpenLayers === null) {
  304. log("error: OpenLayers " + isDownloaded);
  305. return;
  306. }
  307. var latCenter = $("#lat").val();
  308. var lonCenter = $("#lon").val();
  309. var zoom = $("#zoom").val();
  310. var layers = [ new OpenLayers.Layer.OSM("OpenStreetMap") ];
  311. log("# is gmaps available ? " + gmaps + "/" + gmaps);
  312. if (gmaps !== null) {
  313. var array = [ new OpenLayers.Layer.Google("Google Satellite", {
  314. type : google.maps.MapTypeId.SATELLITE,
  315. numZoomLevels : 22,
  316. })
  317. , new OpenLayers.Layer.Google("Google Physical", {
  318. type : google.maps.MapTypeId.TERRAIN
  319. }), new OpenLayers.Layer.Google("Google Hybrid", {
  320. type : google.maps.MapTypeId.HYBRID,
  321. numZoomLevels : 20
  322. }),
  323. new OpenLayers.Layer.Google("Google Streets", {
  324. numZoomLevels : 20
  325. }) ];
  326. // layers = array.concat(layers);
  327. layers = layers.concat(array);
  328. }
  329. log("# add ui " + layers);
  330. map = new OpenLayers.Map('myMap', {
  331. projection : 'EPSG:3857',
  332. layers : layers,
  333. center : new OpenLayers.LonLat(lonCenter, latCenter).transform(
  334. 'EPSG:4326', 'EPSG:3857'),
  335. zoom : zoom,
  336. });
  337. map.addControl(new OpenLayers.Control.LayerSwitcher());
  338. if (fileRecorded) { // TODO : Data vide : data([0])?.length!=0 or
  339. // fileRecorded
  340. // var trace = new OpenLayers.Layer.Markers( "Latest recorded trace"
  341. // );
  342. // map.removeLayer(trace);
  343. var markers = map.getLayersByName("Last recorded trace");
  344. if (markers.length != 0) {
  345. var previousTrace = markers[0];
  346. log("trace = " + previousTrace.name);
  347. previousTrace.destroy();
  348. }
  349. trace = new OpenLayers.Layer.Markers("Last recorded trace");
  350. // readFile().done(loadTrace);
  351. readFile();
  352. // setTimeout(
  353. // // log("result 0 : "+result[0]);
  354. // // log("result 1 : "+result[1]);
  355. // loadTrace
  356. // , 5000);
  357. }
  358. log("#} loadMap: " + OpenLayers);
  359. }
  360. /*
  361. * Refresh Manager
  362. */
  363. /**
  364. * Refresh all the application according to the coordinates and the settings
  365. */
  366. function refresh() {
  367. log("#{ refresh: " + OpenLayers);
  368. if (isOnline) {
  369. isReady = (OpenLayers !== null);
  370. } else {
  371. isReady = false;
  372. }
  373. log("isReady=" + isReady);
  374. if (isReady) {
  375. $('#myMap').empty();
  376. setMapSize();
  377. loadMap();
  378. } else {
  379. // isOnline = navigator.onLine;
  380. // $('#switchOnline').val(isOnline ? 'online' : 'offline');
  381. $('#myMap').empty();
  382. $('#myMap')
  383. .html(
  384. "<p align='center'>"
  385. + "Please connect your application online in the settings"
  386. + " if you want to load the map</p>");
  387. }
  388. // isOffline $('#switchOffline').val() // TODO
  389. log("#} refresh: " + isReady);
  390. }
  391. /*
  392. * Initialization Manager
  393. */
  394. /**
  395. * Recover in the local storage the coordinates values from the preceding use
  396. */
  397. function initData() {
  398. log("#{ initData");
  399. if (localStorage.getItem('lat') !== null) {
  400. $('#lat').val(localStorage.getItem('lat'));
  401. }
  402. if (localStorage.getItem('lon') !== null) {
  403. $('#lon').val(localStorage.getItem('lon'));
  404. }
  405. if (localStorage.getItem('dms') !== null) {
  406. $('#dms').val(localStorage.getItem('dms'));
  407. }
  408. storeData();
  409. log("#} initData");
  410. }
  411. /**
  412. * Recover in the local storage the setting values from the preceding use
  413. */
  414. function initSettings() {
  415. log("#{ initSettings: " + isOnline);
  416. if (null !== localStorage.getItem('connection')) {
  417. isOnline = (localStorage.getItem('connection') == 'online');
  418. }
  419. $('#switchOnline').val(isOnline ? 'online' : 'offline');
  420. if (localStorage.getItem('energySaving') !== null) {
  421. $('#switchEnergy').val(localStorage.getItem('energySaving'));
  422. }
  423. if (localStorage.getItem('timeout') !== null) {
  424. $('#selectorTimeout').attr('value', localStorage.getItem('timeout'));
  425. }
  426. if (localStorage.getItem('downloaded') !== null) {
  427. isDownloaded = localStorage.getItem('downloaded');
  428. }
  429. storeSettings();
  430. log("#} initSettings: " + isReady);
  431. }
  432. /*
  433. * Coordinates transformation Manager
  434. */
  435. /**
  436. * Transform the latitude/longitude into DMS coordinate
  437. *
  438. * @param lat :
  439. * latitude
  440. * @param lon :
  441. * longitude
  442. * @returns dms : DMS coordinate
  443. */
  444. function fromLatLonToDMS(lat, lon) {
  445. var latitude = lat;
  446. var longitude = lon;
  447. var dms = "";
  448. var NS = "";
  449. if (latitude >= 0) {
  450. NS += "N";
  451. } else {
  452. latitude = -latitude;
  453. NS += "S";
  454. }
  455. var dLat = parseInt(latitude, 10);
  456. var mLat = parseInt((latitude - dLat) * 60, 10);
  457. var sLat = parseInt((latitude - dLat) * 60 * 60 - 60 * mLat, 10);
  458. dms += NS + " " + dLat + "° " + mLat + "' " + sLat + "\" ";
  459. var EW = "";
  460. if (longitude >= 0) {
  461. EW += "E";
  462. } else {
  463. EW += "W";
  464. longitude = -longitude;
  465. }
  466. var dLon = parseInt(longitude, 10);
  467. var mLon = parseInt((longitude - dLon) * 60, 10);
  468. var sLon = parseInt((longitude - dLon) * 60 * 60 - 60 * mLon, 10);
  469. dms += EW + " " + dLon + "° " + mLon + "' " + sLon + "\"";
  470. // text = NS+" "+d+"° "+m+"' "+s+"\" "+EW+" "+d+"° "+m+"' "+s+"\"";
  471. return dms;
  472. }
  473. /**
  474. * Transform the DMS into latitude/longitude coordinates
  475. *
  476. * @param dms :
  477. * DMS coordinate
  478. * @returns [ lat, lon ] : latitude and longitude coordinates
  479. */
  480. function fromDMSToLatLon(dms) {
  481. var re = /^([NS])\s*([0-9.\-]+)\s*°\s*([0-9.\-]+)\s*\'\s*([0-9.\-]+)\s*\"\s*([EW])\s*([0-9.\-]+)\s*°\s*([0-9.\-]+)\s*\'\s*([0-9.\-]+)\s*\"\s*$/;
  482. if (re.test(dms)) {
  483. var lat = (parseFloat(RegExp.$2) + parseFloat(RegExp.$3) / 60 + parseFloat(RegExp.$4)
  484. / (60 * 60)).toFixed(6);
  485. if (RegExp.$1 == 'S') {
  486. lat = -lat;
  487. }
  488. lat = lat.toString();
  489. setLat(lat);
  490. var lon = (parseFloat(RegExp.$6) + parseFloat(RegExp.$7) / 60 + parseFloat(RegExp.$8)
  491. / (60 * 60)).toFixed(6);
  492. if (RegExp.$5 == 'W') {
  493. lon = -lon;
  494. }
  495. lon = lon.toString();
  496. setLon(lon);
  497. }
  498. }
  499. /*
  500. * Coordinates Manager
  501. */
  502. /**
  503. * Modify the DMS value using the transformation's function fromLatLonToDMS
  504. */
  505. function setDMS() {
  506. $('#dms').val(fromLatLonToDMS($("#lat").val(), $("#lon").val()));
  507. }
  508. /**
  509. * Modify the latitude and longitude values using the transformation's function
  510. * fromDMSToLatLon
  511. */
  512. function setLatLon() {
  513. var coordinates = fromDMSToLatLon($('#dms').val());
  514. }
  515. /**
  516. * Validate or not the DMS coordinate according to the form of the regular
  517. * expression
  518. *
  519. * @param dms :
  520. * DMS coordinates
  521. * @returns Validation
  522. */
  523. function validateDMS(dms) {
  524. var re = /^([NS])\s*([0-9.\-]+)\s*°\s*([0-9.\-]+)\s*\'\s*([0-9.\-]+)\s*\"\s*([EW])\s*([0-9.\-]+)\s*°\s*([0-9.\-]+)\s*\'\s*([0-9.\-]+)\s*\"\s*$/;
  525. if (re.test(dms)) {
  526. return true;
  527. } else {
  528. return false;
  529. }
  530. }
  531. /**
  532. * Validate or not the latitudes and longitudes coordinates according to the
  533. * form of the regular expression
  534. *
  535. * @param latOrLon
  536. * @returns Validation
  537. */
  538. function validateLatOrLon(latOrLon) {
  539. if (/^[0-9.\-]+$/.test(latOrLon)) {
  540. return true;
  541. } else {
  542. return false;
  543. }
  544. }
  545. /**
  546. * Function called when the latitude value changes Calculate the new DMS
  547. * coordinate
  548. */
  549. function changeLat() {
  550. var lat = $('#lat').val();
  551. if (validateLatOrLon(lat)) {
  552. $('#lat').val(parseFloat($('#lat').val()).toFixed(6).toString());
  553. setDMS();
  554. storeData();
  555. } else {
  556. handleError("Latitude coordinate invalid : " + lat);
  557. initData();
  558. }
  559. }
  560. /**
  561. * Function called when the longitude value changes Calculate the new DMS
  562. * coordinate
  563. */
  564. function changeLon() {
  565. var lon = $('#lon').val();
  566. if (validateLatOrLon(lon)) {
  567. $('#lon').val(parseFloat($('#lon').val()).toFixed(6).toString());
  568. setDMS();
  569. storeData();
  570. } else {
  571. handleError("Lontitude coordinate invalid : " + lon);
  572. initData();
  573. }
  574. }
  575. /**
  576. * Function called when the DMS value changes Calculate the new latitude and
  577. * longitude coordinates
  578. */
  579. function changeDMS() {
  580. var dms = $('#dms').val();
  581. if (validateDMS(dms)) {
  582. setLatLon();
  583. storeData();
  584. } else {
  585. alert("DMS coordinate invalid : " + dms);
  586. initData();
  587. }
  588. }
  589. /*
  590. * Location Manager
  591. */
  592. /**
  593. * Function called when the getCurrentPosition succeded Refresh the application
  594. */
  595. function handleShowLocation(position) {
  596. var lat = position.coords.latitude.toFixed(6).toString();
  597. var lon = position.coords.longitude.toFixed(6).toString();
  598. setLat(lat);
  599. setLon(lon);
  600. refresh();
  601. }
  602. /**
  603. * Function called when the getCurrentPosition failed Show the error
  604. *
  605. * @param error
  606. */
  607. function handleErrorLocation(error) {
  608. var errorInfo = document.getElementById("locationInfo");
  609. switch (error.code) {
  610. case error.PERMISSION_DENIED:
  611. errorInfo.innerHTML = "User denied the request for Geolocation.";
  612. break;
  613. case error.POSITION_UNAVAILABLE:
  614. errorInfo.innerHTML = "Location information is unavailable.";
  615. break;
  616. case error.TIMEOUT:
  617. errorInfo.innerHTML = "The request to get user location timed out.";
  618. break;
  619. case error.UNKNOWN_ERROR:
  620. errorInfo.innerHTML = "An unknown error occurred.";
  621. break;
  622. }
  623. }
  624. /**
  625. * Get the current position according to the GPS' device
  626. */
  627. function getLocation() {
  628. if (navigator.geolocation) {
  629. navigator.geolocation.getCurrentPosition(handleShowLocation,
  630. handleErrorLocation, {
  631. enableHighAccuracy : $('#switchEnergy').val() == 'off'
  632. });
  633. } else {
  634. document.getElementById("locationInfo").innerHTML = "Geolocation is not supported by this browser.";
  635. }
  636. }
  637. /*
  638. * Recording manager
  639. */
  640. /**
  641. * Function called when the file resolution succeded Create the recording file
  642. * in the corresponding directory
  643. *
  644. * @param dir :
  645. * directory where the file is placed
  646. */
  647. function handleResolveSuccess(dir) {
  648. docDir = dir;
  649. var date = new Date();
  650. var dateFile = "" + date.getFullYear().toString() + "-"
  651. + date.getMonth().toString() + "-" + date.getDate().toString()
  652. + "-" + date.getHours().toString() + "-"
  653. + date.getMinutes().toString() + "-" + date.getSeconds().toString();
  654. dateFile = (new Date).getTime();
  655. // log(dateFile);
  656. doc = 'mapo-' + dateFile + ".csv.txt";
  657. docDir.createFile(doc);
  658. $('#locationInfo').html("Track recording in file:<br/>" + doc);
  659. }
  660. /**
  661. * Function called when the file resolution failed Show the error
  662. *
  663. * @param e :
  664. * error
  665. */
  666. function handleResolveError(e) {
  667. handleError('resolve: ' + e.message);
  668. }
  669. /**
  670. * Resolve the file
  671. */
  672. function resolveFile() {
  673. try {
  674. file = docDir.resolve(doc);
  675. } catch (exc) {
  676. log('Could not resolve file: ' + exc.message);
  677. // Stop in case of any errors
  678. return;
  679. }
  680. }
  681. /**
  682. * Function called when the record failed, writing or reading Show the error
  683. *
  684. * @param e :
  685. * error
  686. */
  687. function handleRecordError(e) {
  688. var msg = '';
  689. switch (e.code) {
  690. case FileError.QUOTA_EXCEEDED_ERR:
  691. msg = 'QUOTA_EXCEEDED_ERR';
  692. break;
  693. case FileError.NOT_FOUND_ERR:
  694. msg = 'NOT_FOUND_ERR';
  695. break;
  696. case FileError.SECURITY_ERR:
  697. msg = 'SECURITY_ERR';
  698. break;
  699. case FileError.INVALID_MODIFICATION_ERR:
  700. msg = 'INVALID_MODIFICATION_ERR';
  701. break;
  702. case FileError.INVALID_STATE_ERR:
  703. msg = 'INVALID_STATE_ERR';
  704. break;
  705. default:
  706. msg = 'Unknown Error';
  707. break;
  708. }
  709. handleError(msg);
  710. }
  711. /**
  712. * Function called when the writing succeeded Add the position at the end of the
  713. * file
  714. *
  715. * @param fileStream :
  716. * Stream to write
  717. */
  718. function writeToStream(fileStream) {
  719. try {
  720. var date = (new Date).getTime();
  721. var lat = $("#lat").val();
  722. var lon = $("#lon").val();
  723. var line = "" + date + ";" + lat + ";" + lon + "\n";
  724. fileStream.write(line);
  725. fileStream.close();
  726. } catch (exc) {
  727. handleError('io: could not write to file: ' + exc.message);
  728. }
  729. }
  730. /**
  731. * Try to write the record into the file
  732. */
  733. function writeRecord() {
  734. try {
  735. file.openStream(
  736. // open for appending
  737. 'a',
  738. // success callback - add textarea's contents
  739. writeToStream,
  740. // error callback
  741. handleRecordError);
  742. } catch (exc) {
  743. handleError('io: could not write to file: ' + exc.message);
  744. }
  745. }
  746. /**
  747. * Function called when the reading succeded
  748. *
  749. * @param fileStream :
  750. * Stream to read
  751. */
  752. function readFromStream(fileStream) {
  753. try {
  754. log('File size: ' + file.fileSize);
  755. var contents = fileStream.read(fileStream.bytesAvailable);
  756. fileStream.close();
  757. log('file contents: ' + contents);
  758. } catch (exc) {
  759. handleError('io: Could not read from file: ' + exc.message);
  760. }
  761. }
  762. /**
  763. * Try to read the file
  764. */
  765. function readRecord() {
  766. try {
  767. file.openStream(
  768. // open for reading
  769. 'r',
  770. // success callback - add textarea's contents
  771. readFromStream,
  772. // error callback
  773. handleRecordError);
  774. } catch (exc) {
  775. handleError('io: Could not write to file: ' + exc.message);
  776. }
  777. }
  778. /**
  779. * Function called when getPosition got successfully the position Resolve the
  780. * file, write and read the records
  781. *
  782. * @param position
  783. */
  784. function handleRecordPosition(position) {
  785. if ($('#switchRecord').val() == "start") {
  786. handleShowLocation(position);
  787. resolveFile();
  788. writeRecord();
  789. readRecord();
  790. }
  791. }
  792. /**
  793. * Function called when getPosition failed to get the position Show the error
  794. *
  795. * @param error
  796. */
  797. function handleErrorPosition(error) {
  798. $('#switchRecord').val('stop').slider('refresh');
  799. var errorInfo = document.getElementById("locationInfo");
  800. switch (error.code) {
  801. case error.PERMISSION_DENIED:
  802. errorInfo.innerHTML = "User denied the request for Geolocation.";
  803. break;
  804. case error.POSITION_UNAVAILABLE:
  805. errorInfo.innerHTML = "Location information is unavailable.";
  806. break;
  807. case error.TIMEOUT:
  808. errorInfo.innerHTML = "The request to get user location timed out.";
  809. break;
  810. case error.UNKNOWN_ERROR:
  811. errorInfo.innerHTML = "An unknown error occurred.";
  812. break;
  813. }
  814. }
  815. /**
  816. * Get the recording position
  817. */
  818. function getPosition() {
  819. navigator.geolocation.getCurrentPosition(handleRecordPosition,
  820. handleErrorPosition, {
  821. enableHighAccuracy : $('#switchEnergy').val() == 'off'
  822. });
  823. }
  824. /**
  825. * Function called when the record of a trace has been launched Record the
  826. * position whith a timeout predefined in the settings
  827. */
  828. function record() {
  829. if (navigator.geolocation) {
  830. var intervalID;
  831. if ($('#switchRecord').val() == "start") {
  832. tizen.filesystem.resolve('documents', handleResolveSuccess,
  833. handleResolveError, 'rw');
  834. getPosition();
  835. intervalID = setInterval(getPosition,
  836. $('#selectorTimeout').val() * 1000);
  837. } else {
  838. clearInterval(intervalID);
  839. $('#locationInfo').html("Trace recorded in the file:<br/>" + doc);
  840. fileRecorded = true;
  841. }
  842. } else {
  843. document.getElementById("locationInfo").innerHTML = "Geolocation is not supported.";
  844. }
  845. }
  846. /**
  847. * Extract from a file composed by the last recorded trace all the dates,
  848. * latitudes and lontitudes and place its in data TODO: test if parse CSV as
  849. * "date,la,lo\n"
  850. */
  851. function readFile() {
  852. // var deferred = $.Deferred();
  853. try {
  854. file = docDir.resolve(doc);
  855. log('File size: ' + file.fileSize);
  856. } catch (exceptionResolve) {
  857. log('error: Could not resolve file: ' + exceptionResolve.message);
  858. // Stop in case of any errors
  859. return;
  860. }
  861. try {
  862. file.readAsText(
  863. // success callback - display the contents of the file
  864. function(contents) {
  865. // log('File contents:' + contents);
  866. var lines = contents.split("\n");
  867. var re = /^([0-9.:\-]+),([0-9.\-]+),([0-9.\-]+)$/;
  868. var data = [];
  869. var dates = [];
  870. var lats = [];
  871. var lons = [];
  872. var iData = 0;
  873. for (var iLines = 0; iLines < lines.length; iLines++) {
  874. if (re.test(lines[iLines])) {
  875. log("line " + iLines + ": " + lines[iLines]);
  876. var parts = lines[iLines].split(";");
  877. for (var iParts = 0; iParts < parts.length; iParts++) {
  878. log(" part " + iParts + ": " + parts[iParts]);
  879. if ((iParts % 3) == 0) {
  880. dates[iData] = parts[iParts];
  881. log(" date " + iData + ": " + dates[iData]);
  882. } else if ((iParts % 3) == 1) {
  883. lats[iData] = parts[iParts];
  884. log(" lat " + iData + ": " + lats[iData]);
  885. } else {
  886. lons[iData] = parts[iParts];
  887. log(" lon " + iData + ": " + lons[iData]);
  888. }
  889. }
  890. iData++;
  891. }
  892. }
  893. data['dates'] = dates;
  894. data['lats'] = lats;
  895. data['lons'] = lons;
  896. log("readfile data" + data['dates'][0]);
  897. loadTrace(data);
  898. },
  899. // error callback
  900. handleRecordError);
  901. } catch (exceptionRead) {
  902. handleError("io: readAsText() exception:" + exceptionRead.message);
  903. }
  904. // deferred.resolve();
  905. // return deferred; // [data, referred]
  906. }
  907. /*
  908. * Social Manager
  909. */
  910. /**
  911. * Use the Email Application Control to share a position by Email
  912. */
  913. function sendEmail() {
  914. if (isOnline) {
  915. var message = "This is the position I want to show you from Mapo:"
  916. + "\nLatitude=" + $("#lat").val() + "\nLongitude = "
  917. + $("#lon").val() + "\nIf you prefer in DMS, here it is: "
  918. + $('#dms').val()
  919. + "\nYou can see this position on OpenStreetMap: "
  920. + getLink('OSM') + "\nConnect you on Mapo for more details!";
  921. var appControl = new tizen.ApplicationControl(
  922. "http://tizen.org/appcontrol/operation/compose", null, null,
  923. null, [
  924. new tizen.ApplicationControlData(
  925. "http://tizen.org/appcontrol/data/subject",
  926. [ "Mapo" ]),
  927. new tizen.ApplicationControlData(
  928. "http://tizen.org/appcontrol/data/text",
  929. [ "mapo.tizen@gmail.com" ]),
  930. new tizen.ApplicationControlData(
  931. "http://tizen.org/appcontrol/data/text",
  932. [ message ]) ]);
  933. tizen.application.launchAppControl(appControl, "tizen.email",
  934. function() {
  935. log("launch service succeeded");
  936. }, function(e) {
  937. handleError("launch service failed. Reason: " + e.name);
  938. })
  939. } else {
  940. alert("Please connect your application online in the settings"
  941. + " if you want to send an email");
  942. }
  943. }
  944. // TODO: check
  945. // var appControl = new tizen.ApplicationControl(
  946. // "http://tizen.org/appcontrol/operation/send", // compose or send
  947. // "mailto:", null, null,
  948. // [
  949. // new tizen.ApplicationControlData(
  950. // "http://tizen.org/appcontrol/data/subject", [ "Mapo" ]),
  951. // new tizen.ApplicationControlData(
  952. // "http://tizen.org/appcontrol/data/text", [ message ]),
  953. // new tizen.ApplicationControlData(
  954. // "http://tizen.org/appcontrol/data/to",
  955. // [ "mapo.tizen@gmail.com" ])
  956. //
  957. // // TODO tizen.mapo@spamgourmet.com
  958. // // new tizen.ApplicationControlData(
  959. // // "http://tizen.org/appcontrol/data/path",
  960. // // ["images/image1.jpg"])
  961. // ]);
  962. // tizen.application.launchAppControl(appControl, null,
  963. // function() {log("launch service succeeded");},
  964. // function(e) {
  965. // log("launch service failed. Reason: " + e.name);});
  966. // TODO: check
  967. function sendBluetooth() {
  968. var appControl = new tizen.ApplicationControl(
  969. "http://tizen.org/appcontrol/operation/bluetooth/pick", null,
  970. "image/jpeg", // "image/jpeg"
  971. null, []);
  972. tizen.application.launchAppControl(appControl, "tizen.bluetooth",
  973. function() {
  974. log("launch service succeeded");
  975. }, function(e) {
  976. handleError("launch service failed. Reason: " + e.name);
  977. });
  978. // var appControlReplyCallback = {
  979. // // callee sent a reply
  980. // onsuccess: function(data) {
  981. // for (var i = 0; i < data.length; i++) {
  982. // if (data[i].key == "http://tizen.org/appcontrol/data/selected") {
  983. // log('Selected image is ' + data[i].value[0]);
  984. // }
  985. // }
  986. // },
  987. // // callee returned failure
  988. // onfailure: function() {
  989. // log('The launch application control failed');
  990. // }
  991. // }
  992. //
  993. // tizen.application.launchAppControl(
  994. // appControl,
  995. // null,
  996. // function() {log("launch application control succeed"); },
  997. // function(e) {log("launch application control failed. reason:
  998. // "+e.message); },
  999. // appControlReplyCallback );
  1000. // tizen.application.launch("tizen.bluetooth",
  1001. // function(){log("launch service succeeded");},
  1002. // function(e){log("launch service failed. Reason: " + e.name);});
  1003. // var appControl = new
  1004. // tizen.ApplicationControl("http://tizen.org/appcontrol/operation/bluetooth/pick",
  1005. // "Phone/Images/image16.jpg");
  1006. // tizen.application.launchAppControl(appControl, null,
  1007. // function(){log("launch service succeeded");},
  1008. // function(e){log("launch service failed. Reason: " + e.name);});
  1009. }
  1010. function sendMessage() {
  1011. var message = "This is the position I want to show you from Mapo:"
  1012. + "\nLatitude=" + $("#lat").val() + "\nLongitude = "
  1013. + $("#lon").val() + "\nIf you prefer in DMS, here it is: "
  1014. + $('#dms').val()
  1015. + "\nYou can see this position on OpenStreetMap: " + getLink('OSM')
  1016. + "\n" + "\n\nURL: " + web;
  1017. var appControl = new tizen.ApplicationControl(
  1018. "http://tizen.org/appcontrol/operation/compose", null, null, null,
  1019. [
  1020. new tizen.ApplicationControlData(
  1021. "http://tizen.org/appcontrol/data/messagetype",
  1022. [ "sms" ]),
  1023. new tizen.ApplicationControlData(
  1024. "http://tizen.org/appcontrol/data/text",
  1025. [ message ]) ]);
  1026. tizen.application.launchAppControl(appControl, "tizen.messages",
  1027. function() {
  1028. log("launch service succeeded");
  1029. }, function(e) {
  1030. handleError("launch service failed. Reason: " + e);
  1031. });
  1032. }
  1033. /*
  1034. * Settings Manager
  1035. */
  1036. function settings() {
  1037. var url = "http://tizen.org/appcontrol/operation/setting";
  1038. var id = "com.samsung.setting";
  1039. var appControl = new tizen.ApplicationControl(url);
  1040. tizen.application.launchAppControl(appControl, id, handleSuccess,
  1041. handleException);
  1042. }
  1043. function settingsLocation() {
  1044. var url = "http://tizen.org/appcontrol/operation/setting/location";
  1045. var id = "org.tizen.setting-location";
  1046. var appControl = new tizen.ApplicationControl(url);
  1047. tizen.application.launchAppControl(appControl, id, handleSuccess,
  1048. handleException);
  1049. }
  1050. /*
  1051. * Caller Manager : may not be needed
  1052. */
  1053. function call() {
  1054. var appControl = new tizen.ApplicationControl(
  1055. "http://tizen.org/appcontrol/operation/dial", null, null);
  1056. tizen.application.launchAppControl(appControl, "tizen.phone", function() {
  1057. log("launch appControl succeeded");
  1058. }, function(e) {
  1059. log("error: launch appControl failed. Reason: " + e.name);
  1060. }, null);
  1061. }
  1062. // TODO:
  1063. // function caller(){
  1064. // var appControl = new tizen.ApplicationControl(
  1065. // "http://tizen.org/appcontrol/operation/call",
  1066. // null,
  1067. // null,
  1068. // null,
  1069. // [
  1070. // new
  1071. // tizen.ApplicationControlData("http://tizen.org/appcontrol/data/call/type",[
  1072. // "voice" ])
  1073. // ]
  1074. // );
  1075. // tizen.application.launchAppControl(appControl,"tizen.call",
  1076. // function(){log("launch appControl succeeded");},
  1077. // function(e){log("launch appControl failed. Reason: " + e.name);},
  1078. // null);
  1079. // }
  1080. /*
  1081. * Contact Manager
  1082. */
  1083. /**
  1084. * Use the Contact Application Control to add a contact with the corresponding
  1085. * position
  1086. */
  1087. function createContact() {
  1088. log("#{ createContact");
  1089. var addressbook = tizen.contact.getDefaultAddressBook();
  1090. var groups = addressbook.getGroups();
  1091. var idMapo = "-1";
  1092. for (var i = 0; i < groups.length; i++) {
  1093. log(groups[i].name);
  1094. if (groups[i].name == 'Mapo') {
  1095. idMapo = groups[i].id;
  1096. }
  1097. }
  1098. var group;
  1099. if (idMapo != "-1") {
  1100. group = addressbook.getGroup(idMapo);
  1101. log('Group already exists ' + group.id);
  1102. } else {
  1103. group = new tizen.ContactGroup('Mapo');
  1104. addressbook.addGroup(group);
  1105. log('Group added with id ' + group.id);
  1106. }
  1107. // TODO: edit contact is present
  1108. var contact = new tizen.Contact({
  1109. emails : [ new tizen.ContactEmailAddress("mapo.tizen@gmail.com") ],
  1110. urls : [ new tizen.ContactWebSite(getLink('OSM'), 'HOMEPAGE') ],
  1111. notes : [ 'Position: lat=' + $("#lat").val() + ' lon='
  1112. + $("#lon").val() ],
  1113. organizations : [ new tizen.ContactOrganization({
  1114. name : "Mapo"
  1115. }) ],
  1116. groupIds : [ group.id ]
  1117. });
  1118. addressbook.add(contact);
  1119. var appControl = new tizen.ApplicationControl(
  1120. "http://tizen.org/appcontrol/operation/social/edit",
  1121. null,
  1122. "vnd.tizen.item.type/vnd.tizen.contact",
  1123. null,
  1124. [
  1125. new tizen.ApplicationControlData(
  1126. "http://tizen.org/appcontrol/data/social/item_type",
  1127. [ "person" ]),
  1128. new tizen.ApplicationControlData(
  1129. "http://tizen.org/appcontrol/data/social/item_id",
  1130. [ contact.personId ]) ]);
  1131. tizen.application.launchAppControl(appControl, null, function() {
  1132. log("contact: launch service succeeded");
  1133. }, function(e) {
  1134. handleError("contact: launch service failed. Reason: " + e);
  1135. });
  1136. log("#} createContact");
  1137. }
  1138. /*
  1139. * Calendar Manager
  1140. */
  1141. /**
  1142. * Use the Contact Application Control to add an event in the calendar with the
  1143. * corresponding date
  1144. */
  1145. function createCalendarEvent() {
  1146. var calendar = tizen.calendar.getDefaultCalendar("EVENT");
  1147. var date = new Date();
  1148. var event = new tizen.CalendarEvent({
  1149. description : "Mapo Event",
  1150. summary : "Mapo",
  1151. startDate : new tizen.TZDate(date.getFullYear().toString(), date
  1152. .getMonth().toString(), date.getDate().toString(), date
  1153. .getHours().toString(), date.getSeconds().toString()),
  1154. duration : new tizen.TimeDuration(1, "HOURS"),
  1155. location : 'Position: lat=' + $("#lat").val() + ' lon='
  1156. + $("#lon").val()
  1157. });
  1158. calendar.add(event);
  1159. var url = "http://tizen.org/appcontrol/operation/social/edit";
  1160. var appControl = new tizen.ApplicationControl(url, null, null, null, [
  1161. new tizen.ApplicationControlData(
  1162. "http://tizen.org/appcontrol/data/social/item_type",
  1163. [ "event" ]),
  1164. new tizen.ApplicationControlData(
  1165. "http://tizen.org/appcontrol/data/social/item_id",
  1166. [ event.id.uid ]) ]);
  1167. tizen.application.launchAppControl(appControl, "tizen.calendar",
  1168. function() {
  1169. log("success: " + url);
  1170. }, function(e) {
  1171. handleError("launch service failed. Reason: " + e);
  1172. });
  1173. }
  1174. /*
  1175. * Settings Manager
  1176. */
  1177. /**
  1178. * Function called when the online swith is activated or desactived Verify if
  1179. * the the device has a connection before connecting the application
  1180. */
  1181. function switchOnline() {
  1182. log("#{ switchOnline: " + isOnline);
  1183. log($('#switchOnline').val());
  1184. isOnline = ("online" === $('#switchOnline').val());
  1185. if (isOnline && !navigator.onLine)
  1186. log("connect system's wifi before");
  1187. if (isOnline) {
  1188. isReady = (null === OpenLayers);
  1189. if (!isReady || (null === gmaps)) {
  1190. download();
  1191. }
  1192. } else {
  1193. isReady = false;
  1194. }
  1195. refresh();
  1196. log("#} switchOnline: " + isOnline);
  1197. }
  1198. function switchDeveloper() {
  1199. isLog = ("on" === $('#switchDeveloper').val());
  1200. var attribute = (isLog) ? "visible" : "hidden";
  1201. $("#logView").css("visibility", attribute);
  1202. $("#recordView").css("visibility", attribute);
  1203. }
  1204. /**
  1205. * Use the tactil swipe to change between every pages TODO : blink ?
  1206. */
  1207. function swipePage() {
  1208. $('div.ui-page').live("swipeleft", function() {
  1209. var nextpage = $(this).next('div[data-role="page"]');
  1210. // swipe using id of next page if exists
  1211. if (nextpage.length > 0) {
  1212. $.mobile.changePage(nextpage, {
  1213. transition : "slide",
  1214. reverse : false
  1215. });
  1216. }
  1217. });
  1218. $('div.ui-page').live("swiperight", function() {
  1219. var prevpage = $(this).prev('div[data-role="page"]');
  1220. // swipe using id of next page if exists
  1221. if (prevpage.length > 0) {
  1222. $.mobile.changePage(prevpage, {
  1223. transition : "slide",
  1224. reverse : true
  1225. });
  1226. }
  1227. });
  1228. }
  1229. function handleLoadedGmaps() {
  1230. log("#{ handleLoadedGmaps: + " + google);
  1231. gmaps = google;
  1232. isDownloaded = true;
  1233. refresh();
  1234. log("#} handleLoadedGmaps: + " + isDownloaded);
  1235. }
  1236. function downloadScriptsBody() {
  1237. log("#{ downloadScriptsBody: " + OpenLayers);
  1238. {
  1239. var element = document.createElement("script");
  1240. element.type = 'text/javascript';
  1241. element.src = url_openlayers;
  1242. document.body.appendChild(element);
  1243. }
  1244. {
  1245. var element = document.createElement("script");
  1246. element.type = 'text/javascript';
  1247. element.src = url_gmaps;
  1248. document.body.appendChild(element);
  1249. }
  1250. log("#} downloadScriptsBody: " + OpenLayers);
  1251. }
  1252. function download() {
  1253. log("#{ download: " + OpenLayers);
  1254. if (null == OpenLayers) {
  1255. $.getScript(url_openlayers, function() {
  1256. log("download:" + OpenLayers);
  1257. refresh();
  1258. $.getScript(url_gmaps, function() {
  1259. handleLoadedGmaps();
  1260. });
  1261. });
  1262. } else if (null == google) {
  1263. $.getScript(url_gmaps, function() {
  1264. handleLoadedGmaps();
  1265. });
  1266. } else {
  1267. handleLoadedGmaps();
  1268. }
  1269. // isLoaded = true; // TODO?
  1270. log("#} download: " + OpenLayers);
  1271. }
  1272. function initScripts() {
  1273. log("#{ initScripts: " + OpenLayers);
  1274. log("# isDownloaded=" + isDownloaded);
  1275. if (false === isDownloaded) {
  1276. download();
  1277. } else {
  1278. download();
  1279. refresh();
  1280. }
  1281. log("#} initScripts: " + OpenLayers);
  1282. }
  1283. /**
  1284. * Initialize the data from the preceding use
  1285. */
  1286. function start() {
  1287. log("#{ start: " + OpenLayers);
  1288. initData();
  1289. initSettings();
  1290. initScripts();
  1291. // refresh();
  1292. if (false) { // TODO: buggy flash screen
  1293. swipePage();
  1294. }
  1295. // refresh();
  1296. log("#} start: " + OpenLayers);
  1297. }