Advertisement
Guest User

Untitled

a guest
Apr 24th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1. // This file contains some delegate classes for you to extend.
  2.  
  3. function NewRoutePageControllerDelegate()
  4. {
  5. // Save 'this' so we can refer to public attributes and methods.
  6. var self = this;
  7.  
  8. // The MapPageController class controls the 'New Route' page.
  9. // This class provides a couple of useful methods:
  10. // displayMessage(message):
  11. // Causes a short message string to be displayed on the
  12. // page for a brief period. Useful for showing quick
  13. // notifications to the user.
  14. // panToLocation(latitude, longitude):
  15. // Pans the map to the given latitude and longitude.
  16. // repaintOverlay():
  17. // Causes the map overlay to be redrawn, triggering a
  18. // call to our mapPageDrawOverlay() method. You might
  19. // wish to call this when you update information that
  20. // is displayed on the canvas overlay.
  21. // canvasPointFromLocation(latitude, longitude):
  22. // Given a latitude and longitude, returns the
  23. // corresponding point on the canvas overlay.
  24. // The return value is an object with an 'x' and a 'y'
  25. // property.
  26. var newRoutePageController = null;
  27.  
  28. // NOTE: You should not remove any of the five public methods below.
  29.  
  30. // This method is called by the MapPageController when the user
  31. // has switched to the page and it has been intialised.
  32.  
  33.  
  34.  
  35. this.mapPageInitialisedWithOptions = function(controller, options)
  36. {
  37. console.log("Record Route - mapPageInitialisedWithOptions");
  38.  
  39. newRoutePageController = controller;
  40.  
  41. var map = this
  42.  
  43.  
  44. if ("geolocation" in navigator) {
  45.  
  46.  
  47. console.log("you have it")
  48.  
  49. }
  50.  
  51.  
  52. controller.repaintOverlay()
  53.  
  54.  
  55. map.options = {
  56. enableHighAccuracy: true,
  57. timeout: 6000,
  58. maximumAge: 0,
  59. }
  60.  
  61. map.position= function(position) {
  62.  
  63. controller.panToLocation(position.coords.latitude, position.coords.longitude);
  64.  
  65.  
  66. controller.displayMessage("Accuracy = "+" "+position.coords.accuracy)
  67.  
  68. controller.canvasPointFromLocation(position.coords.latitude,position.coords.longitude)
  69.  
  70.  
  71. }
  72.  
  73.  
  74.  
  75. map.error = function(err) {
  76.  
  77. console.warn('ERROR(' + err.code + '): ' + err.message);
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. var navgeo = navigator.geolocation
  88.  
  89. navgeo.watchPosition(map.position,map.error,map.options);
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. }
  97.  
  98.  
  99.  
  100. // The MapPageController calls this when loading its page.
  101. // You should return an array of objects specifying buttons you
  102. // would like to display at the bottom of the map, e.g.,
  103. // {
  104. // title: "Start",
  105. // id: "startButton", (optional)
  106. // }
  107. // Note: This doesn't support an "onClick" property like in
  108. // Assignment 1.
  109. this.mapPageButtonControls = function()
  110. {
  111. console.log("Record Route - mapPageButtonControls");
  112. return [];
  113. }
  114.  
  115. // The MapPageController calls this when user taps on a button
  116. // specified by mapPageButtonControls(). The buttonIndex will
  117. // be the index of the button in the aray you returned.
  118. this.mapPageButtonTapped = function(buttonIndex)
  119. {
  120. console.log("Record Route - mapPageButtonTapped(" + buttonIndex + ")");
  121. }
  122.  
  123. // The MapPageController calls this when the canvas needs to be
  124. // redrawn, such as due to the user panning or zooming the map.
  125. // It clears the canvas before calling this method.
  126. // 'context' is an HTML canvas element context. This is a
  127. // transparent layer that sits above the map and is redrawn
  128. // whenever the map is panned or zoomed. It can be used to
  129. // draw annotations on the map or display other information.
  130. this.mapPageDrawOverlay = function(context)
  131. {
  132. console.log("Record Route - mapPageDrawOverlay");
  133. }
  134.  
  135. // The MapPageController calls this to ask if it should return
  136. // back to the start screen of the app when the user taps the
  137. // done button. If you are not letting the user return, you
  138. // should probably call displayMessage() to inform them why.
  139. this.mapPageShouldReturnFromDoneButtonTap = function()
  140. {
  141. console.log("Record Route - mapPageShouldReturnFromDoneButtonTap");
  142. // Let the user return.
  143. return true;
  144. }
  145. }
  146.  
  147.  
  148. function ViewRoutePageControllerDelegate()
  149. {
  150. // Save 'this' so we can refer to public attributes and methods.
  151. var self = this;
  152.  
  153. // The MapPageController class controls the 'View Route' page.
  154. // This class provides a couple of useful methods:
  155. // displayMessage(message):
  156. // Causes a short message string to be displayed on the
  157. // page for a brief period. Useful for showing quick
  158. // notifications to the user.
  159. // panToLocation(latitude, longitude):
  160. // Pans the map to the given latitude and longitude.
  161. // repaintOverlay():
  162. // Causes the map overlay to be redrawn, triggering a
  163. // call to our mapPageDrawOverlay() method. You might
  164. // wish to call this when you update information that
  165. // is displayed on the canvas overlay.
  166. // canvasPointFromLocation(latitude, longitude):
  167. // Given a latitude and longitude, returns the
  168. // corresponding point on the canvas overlay.
  169. // The return value is an object with an 'x' and a 'y'
  170. // property.
  171. var viewRoutePageController = null;
  172.  
  173. // The originally recorded route being displayed by the viewRoute page.
  174. var originalRoute;
  175.  
  176. // NOTE: You should not remove any of the five public methods below.
  177.  
  178. // This method is called by the MapPageController when the user
  179. // has switched to the page and it has been intialised. If the
  180. // MapPageController is displaying an existing route, then options
  181. // will contain a 'routeIndex' property which gives the index of
  182. // the selected route in the Routes array.
  183. this.mapPageInitialisedWithOptions = function(controller, options)
  184. {
  185. console.log("View Route - mapPageInitialisedWithOptions");
  186. viewRoutePageController = controller;
  187. originalRoute = Routes[options.routeIndex];
  188. }
  189.  
  190. // The MapPageController calls this when loading its page.
  191. // You should return an array of objects specifying buttons you
  192. // would like to display at the bottom of the map, e.g.,
  193. // {
  194. // title: "Start",
  195. // id: "startButton", (optional)
  196. // }
  197. // Note: This doesn't support an "onClick" property like in
  198. // Assignment 1.
  199. this.mapPageButtonControls = function()
  200. {
  201. console.log("View Route - mapPageButtonControls");
  202. return [];
  203. }
  204.  
  205. // The MapPageController calls this when user taps on a button
  206. // specified by mapPageButtonControls(). The buttonIndex will
  207. // be the index of the button in the aray you returned.
  208. this.mapPageButtonTapped = function(buttonIndex)
  209. {
  210. console.log("View Route - mapPageButtonTapped(" + buttonIndex + ")");
  211. }
  212.  
  213. // The MapPageController calls this when the canvas needs to be
  214. // redrawn, such as due to the user panning or zooming the map.
  215. // It clears the canvas before calling this method.
  216. // 'context' is an HTML canvas element context. This is a
  217. // transparent layer that sits above the map and is redrawn
  218. // whenever the map is panned or zoomed. It can be used to
  219. // draw annotations on the map or display other information.
  220. this.mapPageDrawOverlay = function(context)
  221. {
  222. console.log("View Route - mapPageDrawOverlay");
  223. }
  224.  
  225. // The MapPageController calls this to ask if it should return
  226. // back to the start screen of the app when the user taps the
  227. // done button. If you are not letting the user return, you
  228. // should probably call displayMessage() to inform them why.
  229. this.mapPageShouldReturnFromDoneButtonTap = function()
  230. {
  231. console.log("viewPage mapShouldReturnFromDoneButtonTap");
  232. return true;
  233. }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement