]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * @private\r | |
3 | */\r | |
4 | Ext.define('Ext.device.geolocation.Abstract', {\r | |
5 | config: {\r | |
6 | /**\r | |
7 | * @cfg {Number} maximumAge\r | |
8 | * This option indicates that the application is willing to accept cached location information whose age\r | |
9 | * is no greater than the specified time in milliseconds. If maximumAge is set to 0, an attempt to retrieve\r | |
10 | * new location information is made immediately.\r | |
11 | */\r | |
12 | maximumAge: 0,\r | |
13 | \r | |
14 | /**\r | |
15 | * @cfg {Number} frequency The default frequency to get the current position when using {@link Ext.device.Geolocation#watchPosition}.\r | |
16 | */\r | |
17 | frequency: 10000,\r | |
18 | \r | |
19 | /**\r | |
20 | * @cfg {Boolean} allowHighAccuracy True to allow high accuracy when getting the current position.\r | |
21 | */\r | |
22 | allowHighAccuracy: false,\r | |
23 | \r | |
24 | /**\r | |
25 | * @cfg {Number} timeout\r | |
26 | * The maximum number of milliseconds allowed to elapse between a location update operation.\r | |
27 | */\r | |
28 | timeout: Infinity\r | |
29 | },\r | |
30 | \r | |
31 | /**\r | |
32 | * Attempts to get the current position of this device.\r | |
33 | *\r | |
34 | * Ext.device.Geolocation.getCurrentPosition({\r | |
35 | * success: function(position) {\r | |
36 | * console.log(position);\r | |
37 | * },\r | |
38 | * failure: function() {\r | |
39 | * Ext.Msg.alert('Geolocation', 'Something went wrong!');\r | |
40 | * }\r | |
41 | * });\r | |
42 | *\r | |
43 | * *Note:* If you want to watch the current position, you could use {@link Ext.device.Geolocation#watchPosition} instead.\r | |
44 | *\r | |
45 | * @param {Object} config An object which contains the following config options:\r | |
46 | *\r | |
47 | * @param {Function} config.success\r | |
48 | * The function to call when the location of the current device has been received.\r | |
49 | *\r | |
50 | * @param {Object} config.success.position\r | |
51 | *\r | |
52 | * @param {Function} config.failure\r | |
53 | * The function that is called when something goes wrong.\r | |
54 | *\r | |
55 | * @param {Object} config.scope\r | |
56 | * The scope of the `success` and `failure` functions.\r | |
57 | *\r | |
58 | * @param {Number} config.maximumAge\r | |
59 | * The maximum age of a cached location. If you do not enter a value for this, the value of {@link #maximumAge}\r | |
60 | * will be used.\r | |
61 | *\r | |
62 | * @param {Number} config.timeout\r | |
63 | * The timeout for this request. If you do not specify a value, it will default to {@link #timeout}.\r | |
64 | *\r | |
65 | * @param {Boolean} config.allowHighAccuracy\r | |
66 | * True to enable allow accuracy detection of the location of the current device. If you do not specify a value, it will\r | |
67 | * default to {@link #allowHighAccuracy}.\r | |
68 | */\r | |
69 | getCurrentPosition: function(config) {\r | |
70 | var defaultConfig = Ext.device.geolocation.Abstract.prototype.config;\r | |
71 | \r | |
72 | config = Ext.applyIf(config, {\r | |
73 | maximumAge: defaultConfig.maximumAge,\r | |
74 | frequency: defaultConfig.frequency,\r | |
75 | allowHighAccuracy: defaultConfig.allowHighAccuracy,\r | |
76 | timeout: defaultConfig.timeout\r | |
77 | });\r | |
78 | \r | |
79 | // <debug>\r | |
80 | if (!config.success) {\r | |
81 | Ext.Logger.warn('You need to specify a `success` function for #getCurrentPosition');\r | |
82 | }\r | |
83 | // </debug>\r | |
84 | \r | |
85 | return config;\r | |
86 | },\r | |
87 | \r | |
88 | /**\r | |
89 | * Watches for the current position and calls the callback when successful depending on the specified {@link #frequency}.\r | |
90 | *\r | |
91 | * Ext.device.Geolocation.watchPosition({\r | |
92 | * callback: function(position) {\r | |
93 | * console.log(position);\r | |
94 | * },\r | |
95 | * failure: function() {\r | |
96 | * Ext.Msg.alert('Geolocation', 'Something went wrong!');\r | |
97 | * }\r | |
98 | * });\r | |
99 | *\r | |
100 | * @param {Object} config An object which contains the following config options:\r | |
101 | *\r | |
102 | * @param {Function} config.callback\r | |
103 | * The function to be called when the position has been updated.\r | |
104 | *\r | |
105 | * @param {Function} config.failure\r | |
106 | * The function that is called when something goes wrong.\r | |
107 | *\r | |
108 | * @param {Object} config.scope\r | |
109 | * The scope of the `success` and `failure` functions.\r | |
110 | *\r | |
111 | * @param {Boolean} config.frequency\r | |
112 | * The frequency in which to call the supplied callback. Defaults to {@link #frequency} if you do not specify a value.\r | |
113 | *\r | |
114 | * @param {Boolean} config.allowHighAccuracy\r | |
115 | * True to enable allow accuracy detection of the location of the current device. If you do not specify a value, it will\r | |
116 | * default to {@link #allowHighAccuracy}.\r | |
117 | */\r | |
118 | watchPosition: function(config) {\r | |
119 | var defaultConfig = Ext.device.geolocation.Abstract.prototype.config;\r | |
120 | \r | |
121 | config = Ext.applyIf(config, {\r | |
122 | maximumAge: defaultConfig.maximumAge,\r | |
123 | frequency: defaultConfig.frequency,\r | |
124 | allowHighAccuracy: defaultConfig.allowHighAccuracy,\r | |
125 | timeout: defaultConfig.timeout\r | |
126 | });\r | |
127 | \r | |
128 | // <debug>\r | |
129 | if (!config.callback) {\r | |
130 | Ext.Logger.warn('You need to specify a `callback` function for #watchPosition');\r | |
131 | }\r | |
132 | // </debug>\r | |
133 | \r | |
134 | return config;\r | |
135 | },\r | |
136 | \r | |
137 | /**\r | |
138 | * If you are currently watching for the current position, this will stop that task.\r | |
139 | */\r | |
140 | clearWatch: function() {}\r | |
141 | });\r |