PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/files/jquery.ui.map/3.0rc/jquery.ui.map.extensions.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 209 lines | 90 code | 19 blank | 100 comment | 11 complexity | ad15665c69cda179e75cd5e8ba49a87e MD5 | raw file
  1. /*!
  2. * jQuery UI Google Map 3.0-rc
  3. * http://code.google.com/p/jquery-ui-map/
  4. * Copyright (c) 2010 - 2011 Johan Säll Larsson
  5. * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
  6. *
  7. * Depends:
  8. * jquery.ui.map.js
  9. */
  10. ( function($) {
  11. $.extend($.ui.gmap.prototype, {
  12. /**
  13. * Gets the current position
  14. * @param callback:function(position, status)
  15. * @param geoPositionOptions:object, see https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIDOMGeoPositionOptions
  16. */
  17. getCurrentPosition: function(callback, geoPositionOptions) {
  18. if ( navigator.geolocation ) {
  19. navigator.geolocation.getCurrentPosition (
  20. function(result) {
  21. callback(result, 'OK');
  22. },
  23. function(error) {
  24. callback(null, error);
  25. },
  26. geoPositionOptions
  27. );
  28. } else {
  29. callback(null, 'NOT_SUPPORTED');
  30. }
  31. },
  32. /**
  33. * Watches current position
  34. * To clear watch, call navigator.geolocation.clearWatch(this.get('watch'));
  35. * @param callback:function(position, status)
  36. * @param geoPositionOptions:object, see https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIDOMGeoPositionOptions
  37. */
  38. watchPosition: function(callback, geoPositionOptions) {
  39. if ( navigator.geolocation ) {
  40. this.set('watch', navigator.geolocation.watchPosition (
  41. function(result) {
  42. callback(result, "OK");
  43. },
  44. function(error) {
  45. callback(null, error);
  46. },
  47. geoPositionOptions
  48. ));
  49. } else {
  50. callback(null, "NOT_SUPPORTED");
  51. }
  52. },
  53. /**
  54. * Clears any watches
  55. */
  56. clearWatch: function() {
  57. if ( navigator.geolocation ) {
  58. navigator.geolocation.clearWatch(this.get('watch'));
  59. }
  60. },
  61. /**
  62. * Autocomplete using Google Geocoder
  63. * @param panel:string/node/jquery
  64. * @param callback:function(results, status)
  65. */
  66. autocomplete: function(panel, callback) {
  67. var self = this;
  68. $(this._unwrap(panel)).autocomplete({
  69. source: function( request, response ) {
  70. self.search({'address':request.term}, function(results, status) {
  71. if ( status === 'OK' ) {
  72. response( $.map( results, function(item) {
  73. return { label: item.formatted_address, value: item.formatted_address, position: item.geometry.location }
  74. }));
  75. } else if ( status === 'OVER_QUERY_LIMIT' ) {
  76. alert('Google said it\'s too much!');
  77. }
  78. });
  79. },
  80. minLength: 3,
  81. select: function(event, ui) {
  82. self._call(callback, ui);
  83. },
  84. open: function() { $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); },
  85. close: function() { $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); }
  86. });
  87. },
  88. /**
  89. * Retrieves a list of Places in a given area. The PlaceResultss passed to the callback are stripped-down versions of a full PlaceResult. A more detailed PlaceResult for each Place can be obtained by sending a Place Details request with the desired Place's reference value.
  90. * @param placeSearchRequest:google.maps.places.PlaceSearchRequest, http://code.google.com/apis/maps/documentation/javascript/reference.html#PlaceSearchRequest
  91. * @param callback:function(result:google.maps.places.PlaceResult, status:google.maps.places.PlacesServiceStatus), http://code.google.com/apis/maps/documentation/javascript/reference.html#PlaceResult
  92. */
  93. placesSearch: function(placeSearchRequest, callback) {
  94. this.get('services > PlacesService', new google.maps.places.PlacesService(this.get('map'))).search(placeSearchRequest, callback);
  95. },
  96. /**
  97. * Clears any directions
  98. */
  99. clearDirections: function() {
  100. var directionsRenderer = this.get('services > DirectionsRenderer');
  101. if (directionsRenderer) {
  102. directionsRenderer.setMap(null);
  103. directionsRenderer.setPanel(null);
  104. }
  105. },
  106. /**
  107. * Page through the markers. Very simple version.
  108. * @param prop:the marker property to show in display, defaults to title
  109. */
  110. pagination: function(prop) {
  111. var $el = $("<div id='pagination' class='pagination shadow gradient rounded clearfix'><div class='lt btn back-btn'></div><div class='lt display'></div><div class='rt btn fwd-btn'></div></div>");
  112. var self = this, i = 0, prop = prop || 'title';
  113. self.set('p_nav', function(a, b) {
  114. if (a) {
  115. i = i + b;
  116. $el.find('.display').text(self.get('markers')[i][prop]);
  117. self.get('map').panTo(self.get('markers')[i].getPosition());
  118. }
  119. });
  120. self.get('p_nav')(true, 0);
  121. $el.find('.back-btn').click(function() {
  122. self.get('p_nav')((i > 0), -1, this);
  123. });
  124. $el.find('.fwd-btn').click(function() {
  125. self.get('p_nav')((i < self.get('markers').length - 1), 1, this);
  126. });
  127. self.addControl($el, google.maps.ControlPosition.TOP_LEFT);
  128. }
  129. /**
  130. * A layer that displays data from Panoramio.
  131. * @param panoramioLayerOptions:google.maps.panoramio.PanoramioLayerOptions, http://code.google.com/apis/maps/documentation/javascript/reference.html#PanoramioLayerOptions
  132. */
  133. /*loadPanoramio: function(panoramioLayerOptions) {
  134. if ( !this.get('overlays').PanoramioLayer ) {
  135. this.get('overlays').PanoramioLayer = new google.maps.panoramio.PanoramioLayer();
  136. }
  137. this.get('overlays').PanoramioLayer.setOptions(jQuery.extend({'map': this.get('map') }, panoramioLayerOptions));
  138. },*/
  139. /**
  140. * Makes an elevation request along a path, where the elevation data are returned as distance-based samples along that path.
  141. * @param pathElevationRequest:google.maps.PathElevationRequest, http://code.google.com/apis/maps/documentation/javascript/reference.html#PathElevationRequest
  142. * @param callback:function(result:google.maps.ElevationResult, status:google.maps.ElevationStatus), http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#ElevationResult
  143. */
  144. /*elevationPath: function(pathElevationRequest, callback) {
  145. this.get('services > ElevationService', new google.maps.ElevationService()).getElevationAlongPath(pathElevationRequest, callback);
  146. },*/
  147. /**
  148. * Makes an elevation request for a list of discrete locations.
  149. * @param pathElevationRequest:google.maps.PathElevationRequest, http://code.google.com/apis/maps/documentation/javascript/reference.html#PathElevationRequest
  150. * @param callback:function(result:google.maps.ElevationResult, status:google.maps.ElevationStatus), http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#ElevationResult
  151. */
  152. /*elevationLocations: function(pathElevationRequest, callback) {
  153. this.get('services > ElevationService', new google.maps.ElevationService()).getElevationForLocations(pathElevationRequest, callback);
  154. },*/
  155. /* PLACES SERVICE */
  156. /**
  157. * Retrieves a list of Places in a given area. The PlaceResultss passed to the callback are stripped-down versions of a full PlaceResult. A more detailed PlaceResult for each Place can be obtained by sending a Place Details request with the desired Place's reference value.
  158. * @param placeSearchRequest:google.maps.places.PlaceSearchRequest, http://code.google.com/apis/maps/documentation/javascript/reference.html#PlaceSearchRequest
  159. * @param callback:function(result:google.maps.places.PlaceResult, status:google.maps.places.PlacesServiceStatus), http://code.google.com/apis/maps/documentation/javascript/reference.html#PlaceResult
  160. */
  161. /*placesSearch: function(placeSearchRequest, callback) {
  162. this.get('services > PlacesService', new google.maps.places.PlacesService(this.get('map'))).search(placeSearchRequest, callback);
  163. },*/
  164. /**
  165. * Retrieves details about the Place identified by the given reference.
  166. * @param placeDetailsRequest:google.maps.places.PlaceDetailsRequest, http://code.google.com/apis/maps/documentation/javascript/reference.html#PlaceDetailsRequest
  167. * @param callback:function(result:google.maps.places.PlaceResult, status:google.maps.places.PlacesServiceStatus), http://code.google.com/apis/maps/documentation/javascript/reference.html#PlaceResult
  168. */
  169. /*placesDetails: function(placeDetailsRequest, callback) {
  170. this.get('services > PlacesService', new google.maps.places.PlacesService(this.get('map'))).getDetails(placeDetailsRequest, callback);
  171. },*/
  172. /**
  173. * A service to predict the desired Place based on user input. The service is attached to an <input> field in the form of a drop-down list. The list of predictions is updated dynamically as text is typed into the input field.
  174. * @param panel:jquery/node/string
  175. * @param autocompleteOptions:google.maps.places.AutocompleteOptions, http://code.google.com/apis/maps/documentation/javascript/reference.html#AutocompleteOptions
  176. */
  177. /*placesAutocomplete: function(panel, autocompleteOptions) {
  178. this.get('services > Autocomplete', new google.maps.places.Autocomplete(this._unwrap(panel)));
  179. },*/
  180. /* DISTANCE MATRIX SERVICE */
  181. /**
  182. * Issues a distance matrix request.
  183. * @param distanceMatrixRequest:google.maps.DistanceMatrixRequest, http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixRequest
  184. * @param callback:function(result:google.maps.DistanceMatrixResponse, status: google.maps.DistanceMatrixStatus), http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixResponse
  185. */
  186. /*displayDistanceMatrix: function(distanceMatrixRequest, callback) {
  187. this.get('services > DistanceMatrixService', new google.maps.DistanceMatrixService()).getDistanceMatrix(distanceMatrixRequest, callback);
  188. }*/
  189. });
  190. } (jQuery) );