forked from phonegap/phonegap-start
/
app.js
59 lines (56 loc) · 2.02 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// --- our app behavior logic ---
//
run(function () {
// immediately invoked on first run
var init = (function () {
navigator.network.isReachable("google.com", function(status) {
var connectivity = (status.internetConnectionStatus || status.code || status);
if (connectivity === NetworkStatus.NOT_REACHABLE) {
alert("No internet connection - we won't be able to show you any maps");
} else {
alert("We can reach Google - get ready for some awesome maps!");
}
});
})();
// a little inline controller
when('#welcome');
when('#settings', function() {
// load settings from store and make sure we persist radio buttons.
store.get('config', function(saved) {
if (saved) {
if (saved.map) {
x$('input[value=' + saved.map + ']').attr('checked',true);
}
if (saved.zoom) {
x$('input[name=zoom][value="' + saved.zoom + '"]').attr('checked',true);
}
}
});
});
when('#map', function () {
store.get('config', function (saved) {
// construct a gmap str
var map = saved ? saved.map || ui('map') : ui('map')
, zoom = saved ? saved.zoom || ui('zoom') : ui('zoom')
, path = "http://maps.google.com/maps/api/staticmap?center=";
navigator.geolocation.getCurrentPosition(function (position) {
var location = "" + position.coords.latitude + "," + position.coords.longitude;
path += location + "&zoom=" + zoom;
path += "&size=250x250&maptype=" + map + "&markers=color:red|label:P|";
path += location + "&sensor=false";
x$('img#static_map').attr('src', path);
}, function () {
x$('img#static_map').attr('src', "assets/img/gpsfailed.png");
});
});
});
when('#save', function () {
store.save({
key:'config',
map:ui('map'),
zoom:ui('zoom')
});
display('#welcome');
});
});