active_frontend 13.3.0 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.fasterer.yml +19 -0
  4. data/.reek +27 -0
  5. data/.rubocop.yml +38 -0
  6. data/.scss-lint.yml +27 -0
  7. data/Rakefile +1 -1
  8. data/active_frontend.gemspec +21 -18
  9. data/app/.DS_Store +0 -0
  10. data/app/assets/.DS_Store +0 -0
  11. data/app/assets/fonts/.DS_Store +0 -0
  12. data/app/assets/fonts/dripicons/.DS_Store +0 -0
  13. data/app/assets/fonts/dripicons/dripicons.woff +0 -0
  14. data/app/assets/fonts/fakt-pro/.DS_Store +0 -0
  15. data/app/assets/fonts/fakt-pro/fakt-pro-bold.woff +0 -0
  16. data/app/assets/fonts/fakt-pro/fakt-pro-normal.woff +0 -0
  17. data/app/assets/fonts/fakt-pro/fakt-pro-semibold.woff +0 -0
  18. data/app/assets/fonts/fakt-pro/fakt-pro-semilight.woff +0 -0
  19. data/app/assets/fonts/fakt-soft-pro/.DS_Store +0 -0
  20. data/app/assets/fonts/fakt-soft-pro/fakt-soft-pro-bold.woff +0 -0
  21. data/app/assets/fonts/fakt-soft-pro/fakt-soft-pro-normal.woff +0 -0
  22. data/app/assets/fonts/fakt-soft-pro/fakt-soft-pro-semibold.woff +0 -0
  23. data/app/assets/fonts/fakt-soft-pro/fakt-soft-pro-semilight.woff +0 -0
  24. data/app/assets/images/.DS_Store +0 -0
  25. data/app/assets/images/.keep +0 -0
  26. data/app/assets/images/placeholders/.DS_Store +0 -0
  27. data/app/assets/images/placeholders/camera-large.png +0 -0
  28. data/app/assets/images/placeholders/camera-small.png +0 -0
  29. data/app/assets/images/placeholders/camera.png +0 -0
  30. data/app/assets/images/placeholders/document-large.png +0 -0
  31. data/app/assets/images/placeholders/document-small.png +0 -0
  32. data/app/assets/images/placeholders/document.png +0 -0
  33. data/app/assets/images/placeholders/photo-large.png +0 -0
  34. data/app/assets/images/placeholders/{picture-small.png → photo-small.png} +0 -0
  35. data/app/assets/images/placeholders/photo.png +0 -0
  36. data/app/assets/images/placeholders/store-large.png +0 -0
  37. data/app/assets/images/placeholders/store-small.png +0 -0
  38. data/app/assets/images/placeholders/store.png +0 -0
  39. data/app/assets/images/placeholders/user-large.png +0 -0
  40. data/app/assets/images/placeholders/user-small.png +0 -0
  41. data/app/assets/images/placeholders/user.png +0 -0
  42. data/app/helpers/active_frontend_helper.rb +22 -37
  43. data/lib/.DS_Store +0 -0
  44. data/lib/active_frontend.rb +3 -4
  45. data/lib/active_frontend/.DS_Store +0 -0
  46. data/lib/active_frontend/version.rb +1 -1
  47. data/lib/generators/active_frontend/install_generator.rb +3 -3
  48. data/lib/generators/active_frontend/templates/install.js +35 -30
  49. data/lib/generators/active_frontend/templates/install.scss +55 -58
  50. data/vendor/.DS_Store +0 -0
  51. data/vendor/assets/.DS_Store +0 -0
  52. data/vendor/assets/javascripts/.DS_Store +0 -0
  53. data/vendor/assets/javascripts/active_frontend.js +35 -30
  54. data/vendor/assets/javascripts/base/_affix.js +170 -0
  55. data/vendor/assets/javascripts/base/_alert.js +80 -0
  56. data/vendor/assets/javascripts/base/_animation.js +106 -0
  57. data/vendor/assets/javascripts/base/_button.js +123 -0
  58. data/vendor/assets/javascripts/base/_carousel.js +237 -0
  59. data/vendor/assets/javascripts/base/_collapse.js +200 -0
  60. data/vendor/assets/javascripts/base/_colorpicker.js +147 -0
  61. data/vendor/assets/javascripts/base/_datepicker.js +1411 -0
  62. data/vendor/assets/javascripts/base/_dropdown.js +154 -0
  63. data/vendor/assets/javascripts/base/_filepicker.js +235 -0
  64. data/vendor/assets/javascripts/base/_hoverdown.js +116 -0
  65. data/vendor/assets/javascripts/base/_layout.js +126 -0
  66. data/vendor/assets/javascripts/base/_list.js +103 -0
  67. data/vendor/assets/javascripts/{_modal.js → base/_modal.js} +170 -167
  68. data/vendor/assets/javascripts/base/_popover.js +101 -0
  69. data/vendor/assets/javascripts/base/_scrollspy.js +161 -0
  70. data/vendor/assets/javascripts/base/_switch.js +160 -0
  71. data/vendor/assets/javascripts/base/_tab.js +139 -0
  72. data/vendor/assets/javascripts/base/_table.js +224 -0
  73. data/vendor/assets/javascripts/base/_timeago.js +270 -0
  74. data/vendor/assets/javascripts/base/_timepicker.js +541 -0
  75. data/vendor/assets/javascripts/base/_tooltip.js +525 -0
  76. data/vendor/assets/javascripts/base/_tour.js +268 -0
  77. data/vendor/assets/javascripts/base/_transition.js +52 -0
  78. data/vendor/assets/javascripts/base/_typeahead.js +362 -0
  79. data/vendor/assets/javascripts/extensions/_calendar.js +4709 -0
  80. data/vendor/assets/javascripts/extensions/_chart.js +9371 -0
  81. data/vendor/assets/javascripts/extensions/_map.js +2153 -0
  82. data/vendor/assets/stylesheets/.DS_Store +0 -0
  83. data/vendor/assets/stylesheets/{_mixin.scss → _utility.scss} +96 -10
  84. data/vendor/assets/stylesheets/_variable.scss +201 -19
  85. data/vendor/assets/stylesheets/active_frontend.scss +55 -58
  86. data/vendor/assets/stylesheets/blocks/_anchor.scss +15 -0
  87. data/vendor/assets/stylesheets/blocks/_button.scss +278 -0
  88. data/vendor/assets/stylesheets/blocks/_code.scss +144 -0
  89. data/vendor/assets/stylesheets/blocks/_common.scss +127 -0
  90. data/vendor/assets/stylesheets/blocks/_form.scss +508 -0
  91. data/vendor/assets/stylesheets/blocks/_icon.scss +359 -0
  92. data/vendor/assets/stylesheets/blocks/_list.scss +76 -0
  93. data/vendor/assets/stylesheets/blocks/_multimedia.scss +62 -0
  94. data/vendor/assets/stylesheets/blocks/_reset.scss +179 -0
  95. data/vendor/assets/stylesheets/blocks/_table.scss +211 -0
  96. data/vendor/assets/stylesheets/blocks/_typography.scss +204 -0
  97. data/vendor/assets/stylesheets/components/_ad.scss +78 -0
  98. data/vendor/assets/stylesheets/components/_affix.scss +14 -0
  99. data/vendor/assets/stylesheets/components/_alert.scss +50 -0
  100. data/vendor/assets/stylesheets/components/_animation.scss +1670 -0
  101. data/vendor/assets/stylesheets/components/_breadcrumb.scss +17 -0
  102. data/vendor/assets/stylesheets/components/_calendar.scss +213 -0
  103. data/vendor/assets/stylesheets/components/_card.scss +30 -0
  104. data/vendor/assets/stylesheets/components/_carousel.scss +135 -0
  105. data/vendor/assets/stylesheets/components/_chart.scss +10 -0
  106. data/vendor/assets/stylesheets/components/_collapse.scss +17 -0
  107. data/vendor/assets/stylesheets/components/_colorpicker.scss +38 -0
  108. data/vendor/assets/stylesheets/components/_datepicker.scss +80 -0
  109. data/vendor/assets/stylesheets/components/_dropmenu.scss +151 -0
  110. data/vendor/assets/stylesheets/components/_footer.scss +11 -0
  111. data/vendor/assets/stylesheets/components/_grid.scss +144 -0
  112. data/vendor/assets/stylesheets/components/_header.scss +99 -0
  113. data/vendor/assets/stylesheets/components/_label_and_badge.scss +57 -0
  114. data/vendor/assets/stylesheets/components/_layout.scss +63 -0
  115. data/vendor/assets/stylesheets/components/_map.scss +14 -0
  116. data/vendor/assets/stylesheets/components/_milestone.scss +49 -0
  117. data/vendor/assets/stylesheets/components/_missive.scss +40 -0
  118. data/vendor/assets/stylesheets/components/_modal.scss +126 -0
  119. data/vendor/assets/stylesheets/components/_nav_and_tab.scss +202 -0
  120. data/vendor/assets/stylesheets/components/_navbar.scss +66 -0
  121. data/vendor/assets/stylesheets/components/_pagination.scss +79 -0
  122. data/vendor/assets/stylesheets/components/_placeholder.scss +23 -0
  123. data/vendor/assets/stylesheets/components/_popover.scss +167 -0
  124. data/vendor/assets/stylesheets/components/_progress.scss +62 -0
  125. data/vendor/assets/stylesheets/components/_sidebar.scss +74 -0
  126. data/vendor/assets/stylesheets/components/_spinner.scss +83 -0
  127. data/vendor/assets/stylesheets/components/_switch.scss +150 -0
  128. data/vendor/assets/stylesheets/components/_timepicker.scss +30 -0
  129. data/vendor/assets/stylesheets/components/_tooltip.scss +93 -0
  130. data/vendor/assets/stylesheets/components/_transition.scss +12 -0
  131. data/vendor/assets/stylesheets/components/_typeahead.scss +18 -0
  132. metadata +150 -94
  133. data/app/assets/fonts/gotham/gotham-bold.woff +0 -0
  134. data/app/assets/fonts/gotham/gotham-book.woff +0 -0
  135. data/app/assets/fonts/gotham/gotham-light.woff +0 -0
  136. data/app/assets/fonts/gotham/gotham-medium.woff +0 -0
  137. data/app/assets/fonts/gotham/gotham-rounded-bold.woff +0 -0
  138. data/app/assets/fonts/gotham/gotham-rounded-book.woff +0 -0
  139. data/app/assets/fonts/gotham/gotham-rounded-light.woff +0 -0
  140. data/app/assets/fonts/gotham/gotham-rounded-medium.woff +0 -0
  141. data/app/assets/images/placeholders/archive-large.png +0 -0
  142. data/app/assets/images/placeholders/archive-small.png +0 -0
  143. data/app/assets/images/placeholders/archive.png +0 -0
  144. data/app/assets/images/placeholders/picture-large.png +0 -0
  145. data/app/assets/images/placeholders/picture.png +0 -0
  146. data/vendor/assets/javascripts/_affix.js +0 -153
  147. data/vendor/assets/javascripts/_alert.js +0 -85
  148. data/vendor/assets/javascripts/_animation.js +0 -103
  149. data/vendor/assets/javascripts/_button.js +0 -107
  150. data/vendor/assets/javascripts/_carousel.js +0 -228
  151. data/vendor/assets/javascripts/_chart.js +0 -3742
  152. data/vendor/assets/javascripts/_collapse.js +0 -202
  153. data/vendor/assets/javascripts/_color_picker.js +0 -108
  154. data/vendor/assets/javascripts/_date_picker.js +0 -1650
  155. data/vendor/assets/javascripts/_dropdown.js +0 -156
  156. data/vendor/assets/javascripts/_file_input.js +0 -71
  157. data/vendor/assets/javascripts/_hoverdown.js +0 -109
  158. data/vendor/assets/javascripts/_inputmask.js +0 -341
  159. data/vendor/assets/javascripts/_loader.js +0 -361
  160. data/vendor/assets/javascripts/_map.js +0 -2401
  161. data/vendor/assets/javascripts/_popover.js +0 -99
  162. data/vendor/assets/javascripts/_scrollspy.js +0 -163
  163. data/vendor/assets/javascripts/_slider.js +0 -1572
  164. data/vendor/assets/javascripts/_sort.js +0 -1432
  165. data/vendor/assets/javascripts/_swoggle.js +0 -415
  166. data/vendor/assets/javascripts/_tab.js +0 -146
  167. data/vendor/assets/javascripts/_tablespy.js +0 -1883
  168. data/vendor/assets/javascripts/_time_ago.js +0 -206
  169. data/vendor/assets/javascripts/_time_picker.js +0 -1088
  170. data/vendor/assets/javascripts/_tooltip.js +0 -504
  171. data/vendor/assets/javascripts/_transition.js +0 -50
  172. data/vendor/assets/javascripts/_typeahead.js +0 -366
  173. data/vendor/assets/stylesheets/_ad.scss +0 -63
  174. data/vendor/assets/stylesheets/_affix.scss +0 -14
  175. data/vendor/assets/stylesheets/_alert.scss +0 -114
  176. data/vendor/assets/stylesheets/_animation.scss +0 -1370
  177. data/vendor/assets/stylesheets/_breadcrumb.scss +0 -100
  178. data/vendor/assets/stylesheets/_button.scss +0 -386
  179. data/vendor/assets/stylesheets/_canvas.scss +0 -182
  180. data/vendor/assets/stylesheets/_carousel.scss +0 -158
  181. data/vendor/assets/stylesheets/_chart.scss +0 -15
  182. data/vendor/assets/stylesheets/_code.scss +0 -150
  183. data/vendor/assets/stylesheets/_collapse.scss +0 -14
  184. data/vendor/assets/stylesheets/_color.scss +0 -55
  185. data/vendor/assets/stylesheets/_colorpicker.scss +0 -63
  186. data/vendor/assets/stylesheets/_datepicker.scss +0 -122
  187. data/vendor/assets/stylesheets/_dropdown.scss +0 -248
  188. data/vendor/assets/stylesheets/_footer.scss +0 -71
  189. data/vendor/assets/stylesheets/_form.scss +0 -661
  190. data/vendor/assets/stylesheets/_grid.scss +0 -184
  191. data/vendor/assets/stylesheets/_header.scss +0 -156
  192. data/vendor/assets/stylesheets/_icon.scss +0 -362
  193. data/vendor/assets/stylesheets/_image.scss +0 -33
  194. data/vendor/assets/stylesheets/_label_and_badge.scss +0 -104
  195. data/vendor/assets/stylesheets/_link.scss +0 -55
  196. data/vendor/assets/stylesheets/_list.scss +0 -122
  197. data/vendor/assets/stylesheets/_loader.scss +0 -71
  198. data/vendor/assets/stylesheets/_map.scss +0 -44
  199. data/vendor/assets/stylesheets/_missive.scss +0 -74
  200. data/vendor/assets/stylesheets/_modal.scss +0 -204
  201. data/vendor/assets/stylesheets/_nav_and_tab.scss +0 -230
  202. data/vendor/assets/stylesheets/_navbar.scss +0 -73
  203. data/vendor/assets/stylesheets/_pagination.scss +0 -79
  204. data/vendor/assets/stylesheets/_panel.scss +0 -80
  205. data/vendor/assets/stylesheets/_placeholder.scss +0 -63
  206. data/vendor/assets/stylesheets/_popover.scss +0 -128
  207. data/vendor/assets/stylesheets/_progress.scss +0 -86
  208. data/vendor/assets/stylesheets/_reset.scss +0 -140
  209. data/vendor/assets/stylesheets/_sidebar.scss +0 -148
  210. data/vendor/assets/stylesheets/_slider.scss +0 -151
  211. data/vendor/assets/stylesheets/_spinner.scss +0 -572
  212. data/vendor/assets/stylesheets/_subheader.scss +0 -112
  213. data/vendor/assets/stylesheets/_swoggle.scss +0 -120
  214. data/vendor/assets/stylesheets/_table.scss +0 -210
  215. data/vendor/assets/stylesheets/_timepicker.scss +0 -77
  216. data/vendor/assets/stylesheets/_toolbar.scss +0 -130
  217. data/vendor/assets/stylesheets/_tooltip.scss +0 -105
  218. data/vendor/assets/stylesheets/_transition.scss +0 -11
  219. data/vendor/assets/stylesheets/_trunk.scss +0 -147
  220. data/vendor/assets/stylesheets/_typeahead.scss +0 -18
  221. data/vendor/assets/stylesheets/_typography.scss +0 -233
@@ -0,0 +1,2153 @@
1
+ (function (root, factory) {
2
+ 'use strict';
3
+
4
+ root.GMaps = factory();
5
+
6
+ }(this, function () {
7
+
8
+ var extend_object = function (obj, new_obj) {
9
+ var name;
10
+
11
+ if (obj === new_obj) return obj;
12
+
13
+ for (name in new_obj) {
14
+ if (new_obj[name] !== undefined) {
15
+ obj[name] = new_obj[name];
16
+ }
17
+ }
18
+
19
+ return obj;
20
+ };
21
+
22
+ var replace_object = function (obj, replace) {
23
+ var name;
24
+
25
+ if (obj === replace) return obj;
26
+
27
+ for (name in replace) {
28
+ if (obj[name] !== undefined) {
29
+ obj[name] = replace[name];
30
+ }
31
+ }
32
+
33
+ return obj;
34
+ };
35
+
36
+ var array_map = function (array, callback) {
37
+ var i;
38
+ var original_callback_params = Array.prototype.slice.call(arguments, 2);
39
+ var array_return = [];
40
+ var array_length = array.length;
41
+
42
+ if (Array.prototype.map && array.map === Array.prototype.map) {
43
+ array_return = Array.prototype.map.call(array, function (item) {
44
+ var callback_params = original_callback_params.slice(0);
45
+
46
+ callback_params.splice(0, 0, item);
47
+ return callback.apply(this, callback_params);
48
+ });
49
+ } else {
50
+ for (i = 0; i < array_length; i++) {
51
+ callback_params = original_callback_params;
52
+
53
+ callback_params.splice(0, 0, array[i]);
54
+ array_return.push(callback.apply(this, callback_params));
55
+ }
56
+ }
57
+
58
+ return array_return;
59
+ };
60
+
61
+ var array_flat = function (array) {
62
+ var i;
63
+ var new_array = [];
64
+
65
+ for (i = 0; i < array.length; i++) {
66
+ new_array = new_array.concat(array[i]);
67
+ }
68
+
69
+ return new_array;
70
+ };
71
+
72
+ var coordsToLatLngs = function (coords, useGeoJSON) {
73
+ var first_coord = coords[0];
74
+ var second_coord = coords[1];
75
+
76
+ if (useGeoJSON) {
77
+ first_coord = coords[1];
78
+ second_coord = coords[0];
79
+ }
80
+
81
+ return new google.maps.LatLng(first_coord, second_coord);
82
+ };
83
+
84
+ var arrayToLatLng = function (coords, useGeoJSON) {
85
+ var i;
86
+
87
+ for (i = 0; i < coords.length; i++) {
88
+ if (!(coords[i] instanceof google.maps.LatLng)) {
89
+ if (coords[i].length > 0 && typeof(coords[i][0]) === 'object') {
90
+ coords[i] = arrayToLatLng(coords[i], useGeoJSON);
91
+ } else {
92
+ coords[i] = coordsToLatLngs(coords[i], useGeoJSON);
93
+ }
94
+ }
95
+ }
96
+
97
+ return coords;
98
+ };
99
+
100
+ var getElementsByClassName = function (class_name, context) {
101
+ var element;
102
+ var _class = class_name.replace('.', '');
103
+
104
+ if ('jQuery' in this && context) {
105
+ element = $('.' + _class, context)[0];
106
+ } else {
107
+ element = document.getElementsByClassName(_class)[0];
108
+ }
109
+
110
+ return element;
111
+ };
112
+
113
+ var getElementById = function (id, context) {
114
+ var element;
115
+ var new_id = id.replace('#', '');
116
+
117
+ if ('jQuery' in window && context) {
118
+ element = $('#' + new_id, context)[0];
119
+ } else {
120
+ element = document.getElementById(new_id);
121
+ }
122
+
123
+ return element;
124
+ };
125
+
126
+ var findAbsolutePosition = function (obj) {
127
+ var curleft = 0;
128
+ var curtop = 0;
129
+
130
+ if (obj.offsetParent) {
131
+ do {
132
+ curleft += obj.offsetLeft;
133
+ curtop += obj.offsetTop;
134
+ } while (obj = obj.offsetParent);
135
+ }
136
+
137
+ return [curleft, curtop];
138
+ };
139
+
140
+ var GMaps = (function (global) {
141
+ 'use strict';
142
+
143
+ var doc = document;
144
+ var GMaps = function (options) {
145
+
146
+ if (!(typeof window.google === 'object' && window.google.maps)) {
147
+ if (typeof window.console === 'object' && window.console.error) {
148
+ console.error('Google Maps API is required. Please register the following JavaScript library https://maps.googleapis.com/maps/api/js.');
149
+ }
150
+
151
+ return function () {};
152
+ }
153
+
154
+ if (!this) return new GMaps(options);
155
+
156
+ options.zoom = options.zoom || 15;
157
+ options.mapType = options.mapType || 'roadmap';
158
+
159
+ var valueOrDefault = function (value, defaultValue) {
160
+ return value === undefined ? defaultValue : value;
161
+ };
162
+
163
+ var i;
164
+ var self = this;
165
+ var events_that_hide_context_menu = [
166
+ 'bounds_changed', 'center_changed', 'click', 'dblclick', 'drag',
167
+ 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed',
168
+ 'resize', 'tilesloaded', 'zoom_changed'
169
+ ];
170
+ var events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover'];
171
+ var options_to_be_deleted = ['el', 'lat', 'lng', 'mapType', 'width', 'height', 'markerClusterer', 'enableNewStyle'];
172
+ var identifier = options.el || options.div;
173
+ var markerClustererFunction = options.markerClusterer;
174
+ var mapType = google.maps.MapTypeId[options.mapType.toUpperCase()];
175
+ var map_center = new google.maps.LatLng(options.lat, options.lng);
176
+ var zoomControl = valueOrDefault(options.zoomControl, true);
177
+ var zoomControlOpt = options.zoomControlOpt || {
178
+ style: 'DEFAULT',
179
+ position: 'TOP_LEFT'
180
+ };
181
+ var zoomControlStyle = zoomControlOpt.style || 'DEFAULT';
182
+ var zoomControlPosition = zoomControlOpt.position || 'TOP_LEFT';
183
+ var panControl = valueOrDefault(options.panControl, true);
184
+ var mapTypeControl = valueOrDefault(options.mapTypeControl, true);
185
+ var scaleControl = valueOrDefault(options.scaleControl, true);
186
+ var streetViewControl = valueOrDefault(options.streetViewControl, true);
187
+ var overviewMapControl = valueOrDefault(overviewMapControl, true);
188
+ var map_options = {};
189
+ var map_base_options = {
190
+ zoom: this.zoom,
191
+ center: map_center,
192
+ mapTypeId: mapType
193
+ };
194
+ var map_controls_options = {
195
+ panControl: panControl,
196
+ zoomControl: zoomControl,
197
+ zoomControlOptions: {
198
+ style: google.maps.ZoomControlStyle[zoomControlStyle],
199
+ position: google.maps.ControlPosition[zoomControlPosition]
200
+ },
201
+ mapTypeControl: mapTypeControl,
202
+ scaleControl: scaleControl,
203
+ streetViewControl: streetViewControl,
204
+ overviewMapControl: overviewMapControl
205
+ };
206
+
207
+ if (typeof(options.el) === 'string' || typeof(options.div) === 'string') {
208
+ if (identifier.indexOf('#') > -1) {
209
+ this.el = getElementById(identifier, options.context);
210
+ } else {
211
+ this.el = getElementsByClassName.apply(this, [identifier, options.context]);
212
+ }
213
+ } else {
214
+ this.el = identifier;
215
+ }
216
+
217
+ if (typeof(this.el) === 'undefined' || this.el === null) {
218
+ throw 'No element defined.';
219
+ }
220
+
221
+ window.context_menu = window.context_menu || {};
222
+ window.context_menu[self.el.id] = {};
223
+
224
+ this.controls = [];
225
+ this.overlays = [];
226
+ this.layers = [];
227
+ this.singleLayers = {};
228
+ this.markers = [];
229
+ this.polylines = [];
230
+ this.routes = [];
231
+ this.polygons = [];
232
+ this.infoWindow = null;
233
+ this.overlay_el = null;
234
+ this.zoom = options.zoom;
235
+ this.registered_events = {};
236
+ this.el.style.width = options.width || this.el.scrollWidth || this.el.offsetWidth;
237
+ this.el.style.height = options.height || this.el.scrollHeight || this.el.offsetHeight;
238
+ google.maps.visualRefresh = options.enableNewStyle;
239
+
240
+ for (i = 0; i < options_to_be_deleted.length; i++) {
241
+ delete options[options_to_be_deleted[i]];
242
+ }
243
+
244
+ if (options.disableDefaultUI !== true) {
245
+ map_base_options = extend_object(map_base_options, map_controls_options);
246
+ }
247
+
248
+ map_options = extend_object(map_base_options, options);
249
+
250
+ for (i = 0; i < events_that_hide_context_menu.length; i++) {
251
+ delete map_options[events_that_hide_context_menu[i]];
252
+ }
253
+
254
+ for (i = 0; i < events_that_doesnt_hide_context_menu.length; i++) {
255
+ delete map_options[events_that_doesnt_hide_context_menu[i]];
256
+ }
257
+
258
+ this.map = new google.maps.Map(this.el, map_options);
259
+
260
+ if (markerClustererFunction) {
261
+ this.markerClusterer = markerClustererFunction.apply(this, [this.map]);
262
+ }
263
+
264
+ var buildContextMenuHTML = function (control, e) {
265
+ var i;
266
+ var html = '';
267
+ var options = window.context_menu[self.el.id][control];
268
+
269
+ for (i in options) {
270
+ if (options.hasOwnProperty(i)) {
271
+ var option = options[i];
272
+
273
+ html += '<li><a id="' + control + '_' + i + '" href="#">' + option.title + '</a></li>';
274
+ }
275
+ }
276
+
277
+ if (!getElementById('gmaps_context_menu')) return;
278
+
279
+ var context_menu_element = getElementById('gmaps_context_menu');
280
+
281
+ context_menu_element.innerHTML = html;
282
+
283
+ var context_menu_items = context_menu_element.getElementsByTagName('a');
284
+ var context_menu_items_count = context_menu_items.length;
285
+
286
+ for (i = 0; i < context_menu_items_count; i++) {
287
+ var context_menu_item = context_menu_items[i];
288
+
289
+ var assign_menu_item_action = function (ev) {
290
+ ev.preventDefault();
291
+
292
+ options[this.id.replace(control + '_', '')].action.apply(self, [e]);
293
+
294
+ self.hideContextMenu();
295
+ };
296
+
297
+ google.maps.event.clearListeners(context_menu_item, 'click');
298
+ google.maps.event.addDomListenerOnce(context_menu_item, 'click', assign_menu_item_action, false);
299
+ }
300
+
301
+ var position = findAbsolutePosition.apply(this, [self.el]);
302
+ var left = position[0] + e.pixel.x - 15;
303
+ var top = position[1] + e.pixel.y- 15;
304
+
305
+ context_menu_element.style.left = left + 'px';
306
+ context_menu_element.style.top = top + 'px';
307
+
308
+ // context_menu_element.style.display = 'block';
309
+ };
310
+
311
+ this.buildContextMenu = function (control, e) {
312
+ if (control === 'marker') {
313
+ e.pixel = {};
314
+
315
+ var overlay = new google.maps.OverlayView();
316
+ overlay.setMap(self.map);
317
+
318
+ overlay.draw = function () {
319
+ var projection = overlay.getProjection();
320
+ var position = e.marker.getPosition();
321
+
322
+ e.pixel = projection.fromLatLngToContainerPixel(position);
323
+
324
+ buildContextMenuHTML(control, e);
325
+ };
326
+ } else {
327
+ buildContextMenuHTML(control, e);
328
+ }
329
+
330
+ var context_menu_element = getElementById('gmaps_context_menu');
331
+
332
+ setTimeout(function () {
333
+ context_menu_element.style.display = 'block';
334
+ }, 0);
335
+ };
336
+
337
+ this.setContextMenu = function (options) {
338
+ window.context_menu[self.el.id][options.control] = {};
339
+
340
+ var i;
341
+ var ul = doc.createElement('ul');
342
+
343
+ for (i in options.options) {
344
+ if (options.options.hasOwnProperty(i)) {
345
+ var option = options.options[i];
346
+
347
+ window.context_menu[self.el.id][options.control][option.name] = {
348
+ title: option.title,
349
+ action: option.action
350
+ };
351
+ }
352
+ }
353
+
354
+ ul.id = 'gmaps_context_menu';
355
+ ul.style.display = 'none';
356
+ ul.style.position = 'absolute';
357
+ ul.style.minWidth = '100px';
358
+ ul.style.background = 'white';
359
+ ul.style.listStyle = 'none';
360
+ ul.style.padding = '8px';
361
+ ul.style.boxShadow = '2px 2px 6px #ccc';
362
+
363
+ if (!getElementById('gmaps_context_menu')) {
364
+ doc.body.appendChild(ul);
365
+ }
366
+
367
+ var context_menu_element = getElementById('gmaps_context_menu');
368
+
369
+ google.maps.event.addDomListener(context_menu_element, 'mouseout', function (ev) {
370
+ if (!ev.relatedTarget || !this.contains(ev.relatedTarget)) {
371
+ window.setTimeout(function () {
372
+ context_menu_element.style.display = 'none';
373
+ }, 400);
374
+ }
375
+ }, false);
376
+ };
377
+
378
+ this.hideContextMenu = function () {
379
+ var context_menu_element = getElementById('gmaps_context_menu');
380
+
381
+ if (context_menu_element) {
382
+ context_menu_element.style.display = 'none';
383
+ }
384
+ };
385
+
386
+ var setupListener = function (object, name) {
387
+ google.maps.event.addListener(object, name, function (e) {
388
+ if (e === undefined) {
389
+ e = this;
390
+ }
391
+
392
+ options[name].apply(this, [e]);
393
+
394
+ self.hideContextMenu();
395
+ });
396
+ };
397
+
398
+ // google.maps.event.addListener(this.map, 'idle', this.hideContextMenu);
399
+ google.maps.event.addListener(this.map, 'zoom_changed', this.hideContextMenu);
400
+
401
+ var ev, name;
402
+
403
+ for (ev = 0; ev < events_that_hide_context_menu.length; ev++) {
404
+ name = events_that_hide_context_menu[ev];
405
+
406
+ if (name in options) setupListener(this.map, name);
407
+ }
408
+
409
+ for (ev = 0; ev < events_that_doesnt_hide_context_menu.length; ev++) {
410
+ name = events_that_doesnt_hide_context_menu[ev];
411
+
412
+ if (name in options) setupListener(this.map, name);
413
+ }
414
+
415
+ google.maps.event.addListener(this.map, 'rightclick', function (e) {
416
+ if (options.rightclick) options.rightclick.apply(this, [e]);
417
+
418
+ if (window.context_menu[self.el.id]['map'] !== undefined) {
419
+ self.buildContextMenu('map', e);
420
+ }
421
+ });
422
+
423
+ this.refresh = function () {
424
+ google.maps.event.trigger(this.map, 'resize');
425
+ };
426
+
427
+ this.fitZoom = function () {
428
+ var i;
429
+ var latLngs = [];
430
+ var markers_length = this.markers.length;
431
+
432
+ for (i = 0; i < markers_length; i++) {
433
+ if (typeof(this.markers[i].visible) === 'boolean' && this.markers[i].visible) {
434
+ latLngs.push(this.markers[i].getPosition());
435
+ }
436
+ }
437
+
438
+ this.fitLatLngBounds(latLngs);
439
+ };
440
+
441
+ this.fitLatLngBounds = function (latLngs) {
442
+ var i;
443
+ var total = latLngs.length;
444
+ var bounds = new google.maps.LatLngBounds();
445
+
446
+ for (i = 0; i < total; i++) {
447
+ bounds.extend(latLngs[i]);
448
+ }
449
+
450
+ this.map.fitBounds(bounds);
451
+ };
452
+
453
+ this.setCenter = function (lat, lng, callback) {
454
+ this.map.panTo(new google.maps.LatLng(lat, lng));
455
+
456
+ if (callback) callback();
457
+ };
458
+
459
+ this.getElement = function () {
460
+ return this.el;
461
+ };
462
+
463
+ this.zoomIn = function (value) {
464
+ value = value || 1;
465
+
466
+ this.zoom = this.map.getZoom() + value;
467
+ this.map.setZoom(this.zoom);
468
+ };
469
+
470
+ this.zoomOut = function (value) {
471
+ value = value || 1;
472
+
473
+ this.zoom = this.map.getZoom() - value;
474
+ this.map.setZoom(this.zoom);
475
+ };
476
+
477
+ var method;
478
+ var native_methods = [];
479
+
480
+ for (method in this.map) {
481
+ if (typeof(this.map[method]) === 'function' && !this[method]) {
482
+ native_methods.push(method);
483
+ }
484
+ }
485
+
486
+ for (i = 0; i < native_methods.length; i++) {
487
+ (function (gmaps, scope, method_name) {
488
+ gmaps[method_name] = function () {
489
+ return scope[method_name].apply(scope, arguments);
490
+ };
491
+ })(this, this.map, native_methods[i]);
492
+ }
493
+ };
494
+
495
+ return GMaps;
496
+ })(this);
497
+
498
+ GMaps.prototype.createControl = function (options) {
499
+ var control = document.createElement('div');
500
+
501
+ control.style.cursor = 'pointer';
502
+
503
+ if (options.disableDefaultStyles !== true) {
504
+ control.style.fontFamily = '"Fakt Soft Pro", "Fakt Pro", Roboto, Arial, sans-serif';
505
+ control.style.fontSize = '12px';
506
+ control.style.boxShadow = 'rgba(0,0,0,0.298039) 0px 1px 4px -1px';
507
+ }
508
+
509
+ for (var option in options.style) {
510
+ control.style[option] = options.style[option];
511
+ }
512
+
513
+ if (options.id) {
514
+ control.id = options.id;
515
+ }
516
+
517
+ if (options.title) {
518
+ control.title = options.title;
519
+ }
520
+
521
+ if (options.classes) {
522
+ control.className = options.classes;
523
+ }
524
+
525
+ if (options.content) {
526
+ if (typeof options.content === 'string') {
527
+ control.innerHTML = options.content;
528
+ } else if (options.content instanceof HTMLElement) {
529
+ control.appendChild(options.content);
530
+ }
531
+ }
532
+
533
+ if (options.position) {
534
+ control.position = google.maps.ControlPosition[options.position.toUpperCase()];
535
+ }
536
+
537
+ for (var ev in options.events) {
538
+ (function (object, name) {
539
+ google.maps.event.addDomListener(object, name, function () {
540
+ options.events[name].apply(this, [this]);
541
+ });
542
+ })(control, ev);
543
+ }
544
+
545
+ control.index = 1;
546
+
547
+ return control;
548
+ };
549
+
550
+ GMaps.prototype.addControl = function (options) {
551
+ var control = this.createControl(options);
552
+
553
+ this.controls.push(control);
554
+ this.map.controls[control.position].push(control);
555
+
556
+ return control;
557
+ };
558
+
559
+ GMaps.prototype.removeControl = function (control) {
560
+ var i;
561
+ var position = null;
562
+
563
+ for (i = 0; i < this.controls.length; i++) {
564
+ if (this.controls[i] === control) {
565
+ position = this.controls[i].position;
566
+ this.controls.splice(i, 1);
567
+ }
568
+ }
569
+
570
+ if (position) {
571
+ for (i = 0; i < this.map.controls.length; i++) {
572
+ var controlsForPosition = this.map.controls[control.position];
573
+
574
+ if (controlsForPosition.getAt(i) === control) {
575
+ controlsForPosition.removeAt(i);
576
+
577
+ break;
578
+ }
579
+ }
580
+ }
581
+
582
+ return control;
583
+ };
584
+
585
+ GMaps.prototype.createMarker = function (options) {
586
+ if (options.lat === undefined && options.lng === undefined && options.position === undefined) {
587
+ throw 'No latitude or longitude defined.';
588
+ }
589
+
590
+ var self = this;
591
+ var details = options.details;
592
+ var fences = options.fences;
593
+ var outside = options.outside;
594
+ var base_options = {
595
+ position: new google.maps.LatLng(options.lat, options.lng),
596
+ map: null
597
+ };
598
+ var marker_options = extend_object(base_options, options);
599
+
600
+ delete marker_options.lat;
601
+ delete marker_options.lng;
602
+ delete marker_options.fences;
603
+ delete marker_options.outside;
604
+
605
+ var marker = new google.maps.Marker(marker_options);
606
+
607
+ marker.fences = fences;
608
+
609
+ if (options.infoWindow) {
610
+ marker.infoWindow = new google.maps.InfoWindow(options.infoWindow);
611
+
612
+ var info_window_events = ['closeclick', 'content_changed', 'domready', 'position_changed', 'zindex_changed'];
613
+
614
+ for (var ev = 0; ev < info_window_events.length; ev++) {
615
+ (function (object, name) {
616
+ if (options.infoWindow[name]) {
617
+ google.maps.event.addListener(object, name, function (e) {
618
+ options.infoWindow[name].apply(this, [e]);
619
+ });
620
+ }
621
+ })(marker.infoWindow, info_window_events[ev]);
622
+ }
623
+ }
624
+
625
+ var ev;
626
+ var marker_events_with_mouse = ['dblclick', 'drag', 'dragend', 'dragstart', 'mousedown', 'mouseout', 'mouseover', 'mouseup'];
627
+ var marker_events = [
628
+ 'animation_changed', 'clickable_changed', 'cursor_changed', 'draggable_changed', 'flat_changed', 'icon_changed',
629
+ 'position_changed', 'shadow_changed', 'shape_changed', 'title_changed', 'visible_changed', 'zindex_changed'
630
+ ];
631
+
632
+ for (ev = 0; ev < marker_events.length; ev++) {
633
+ (function (object, name) {
634
+ if (options[name]) {
635
+ google.maps.event.addListener(object, name, function () {
636
+ options[name].apply(this, [this]);
637
+ });
638
+ }
639
+ })(marker, marker_events[ev]);
640
+ }
641
+
642
+ for (ev = 0; ev < marker_events_with_mouse.length; ev++) {
643
+ (function (map, object, name) {
644
+ if (options[name]) {
645
+ google.maps.event.addListener(object, name, function (me) {
646
+ if (!me.pixel) {
647
+ me.pixel = map.getProjection().fromLatLngToPoint(me.latLng);
648
+ }
649
+
650
+ options[name].apply(this, [me]);
651
+ });
652
+ }
653
+ })(this.map, marker, marker_events_with_mouse[ev]);
654
+ }
655
+
656
+ google.maps.event.addListener(marker, 'click', function () {
657
+ this.details = details;
658
+
659
+ if (options.click) options.click.apply(this, [this]);
660
+
661
+ if (marker.infoWindow) {
662
+ self.hideInfoWindows();
663
+ marker.infoWindow.open(self.map, marker);
664
+ }
665
+ });
666
+
667
+ google.maps.event.addListener(marker, 'rightclick', function (e) {
668
+ e.marker = this;
669
+
670
+ if (options.rightclick) options.rightclick.apply(this, [e]);
671
+ if (window.context_menu[self.el.id]['marker'] !== undefined) self.buildContextMenu('marker', e);
672
+ });
673
+
674
+ if (marker.fences) {
675
+ google.maps.event.addListener(marker, 'dragend', function () {
676
+ self.checkMarkerGeofence(marker, function (m, f) {
677
+ outside(m, f);
678
+ });
679
+ });
680
+ }
681
+
682
+ return marker;
683
+ };
684
+
685
+ GMaps.prototype.addMarker = function (options) {
686
+ var marker;
687
+ if (options.hasOwnProperty('gm_accessors_')) {
688
+ marker = options;
689
+ } else {
690
+ if ((options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) || options.position) {
691
+ marker = this.createMarker(options);
692
+ } else {
693
+ throw 'No latitude or longitude defined.';
694
+ }
695
+ }
696
+
697
+ marker.setMap(this.map);
698
+
699
+ if (this.markerClusterer) this.markerClusterer.addMarker(marker);
700
+
701
+ this.markers.push(marker);
702
+
703
+ GMaps.fire('marker_added', marker, this);
704
+
705
+ return marker;
706
+ };
707
+
708
+ GMaps.prototype.addMarkers = function (array) {
709
+ for (var i = 0, marker; marker=array[i]; i++) {
710
+ this.addMarker(marker);
711
+ }
712
+
713
+ return this.markers;
714
+ };
715
+
716
+ GMaps.prototype.hideInfoWindows = function () {
717
+ for (var i = 0, marker; marker = this.markers[i]; i++) {
718
+ if (marker.infoWindow) marker.infoWindow.close();
719
+ }
720
+ };
721
+
722
+ GMaps.prototype.removeMarker = function (marker) {
723
+ for (var i = 0; i < this.markers.length; i++) {
724
+ if (this.markers[i] === marker) {
725
+ this.markers[i].setMap(null);
726
+ this.markers.splice(i, 1);
727
+
728
+ if (this.markerClusterer) this.markerClusterer.removeMarker(marker);
729
+
730
+ GMaps.fire('marker_removed', marker, this);
731
+
732
+ break;
733
+ }
734
+ }
735
+
736
+ return marker;
737
+ };
738
+
739
+ GMaps.prototype.removeMarkers = function (collection) {
740
+ var i, marker;
741
+ var new_markers = [];
742
+
743
+ if (typeof collection === 'undefined') {
744
+ for (i = 0; i < this.markers.length; i++) {
745
+ marker = this.markers[i];
746
+
747
+ marker.setMap(null);
748
+
749
+ GMaps.fire('marker_removed', marker, this);
750
+ }
751
+
752
+ if (this.markerClusterer && this.markerClusterer.clearMarkers) this.markerClusterer.clearMarkers();
753
+
754
+ this.markers = new_markers;
755
+ } else {
756
+ for (i = 0; i < collection.length; i++) {
757
+ var index = this.markers.indexOf(collection[i]);
758
+
759
+ if (index > -1) {
760
+ marker = this.markers[index];
761
+ marker.setMap(null);
762
+
763
+ if (this.markerClusterer) this.markerClusterer.removeMarker(marker);
764
+
765
+ GMaps.fire('marker_removed', marker, this);
766
+ }
767
+ }
768
+
769
+ for (i = 0; i < this.markers.length; i++) {
770
+ marker = this.markers[i];
771
+
772
+ if (marker.getMap() !== null) new_markers.push(marker);
773
+ }
774
+
775
+ this.markers = new_markers;
776
+ }
777
+ };
778
+
779
+ GMaps.prototype.drawOverlay = function (options) {
780
+ var overlay = new google.maps.OverlayView();
781
+ var auto_show = true;
782
+
783
+ overlay.setMap(this.map);
784
+
785
+ if (options.auto_show !== null) {
786
+ auto_show = options.auto_show;
787
+ }
788
+
789
+ overlay.onAdd = function () {
790
+ var el = document.createElement('div');
791
+
792
+ el.style.borderStyle = 'none';
793
+ el.style.borderWidth = '0px';
794
+ el.style.position = 'absolute';
795
+ el.style.zIndex = 100;
796
+ el.innerHTML = options.content;
797
+
798
+ overlay.el = el;
799
+
800
+ if (!options.layer) {
801
+ options.layer = 'overlayLayer';
802
+ }
803
+
804
+ var panes = this.getPanes();
805
+ var overlayLayer = panes[options.layer];
806
+ var stop_overlay_events = ['contextmenu', 'DOMMouseScroll', 'dblclick', 'mousedown'];
807
+
808
+ overlayLayer.appendChild(el);
809
+
810
+ for (var ev = 0; ev < stop_overlay_events.length; ev++) {
811
+ (function (object, name) {
812
+ google.maps.event.addDomListener(object, name, function (e) {
813
+ if (navigator.userAgent.toLowerCase().indexOf('msie') != -1 && document.all) {
814
+ e.cancelBubble = true;
815
+ e.returnValue = false;
816
+ } else {
817
+ e.stopPropagation();
818
+ }
819
+ });
820
+ })(el, stop_overlay_events[ev]);
821
+ }
822
+
823
+ if (options.click) {
824
+ panes.overlayMouseTarget.appendChild(overlay.el);
825
+ google.maps.event.addDomListener(overlay.el, 'click', function () {
826
+ options.click.apply(overlay, [overlay]);
827
+ });
828
+ }
829
+
830
+ google.maps.event.trigger(this, 'ready');
831
+ };
832
+
833
+ overlay.draw = function () {
834
+ var projection = this.getProjection();
835
+ var pixel = projection.fromLatLngToDivPixel(new google.maps.LatLng(options.lat, options.lng));
836
+
837
+ options.horizontalOffset = options.horizontalOffset || 0;
838
+ options.verticalOffset = options.verticalOffset || 0;
839
+
840
+ var el = overlay.el;
841
+ var content = el.children[0];
842
+ var content_height = content.clientHeight;
843
+ var content_width = content.clientWidth;
844
+
845
+ switch (options.verticalAlign) {
846
+ case 'top':
847
+ el.style.top = (pixel.y - content_height + options.verticalOffset) + 'px';
848
+ break;
849
+
850
+ default:
851
+ case 'middle':
852
+ el.style.top = (pixel.y - (content_height / 2) + options.verticalOffset) + 'px';
853
+ break;
854
+
855
+ case 'bottom':
856
+ el.style.top = (pixel.y + options.verticalOffset) + 'px';
857
+ break;
858
+ }
859
+
860
+ switch (options.horizontalAlign) {
861
+ case 'left':
862
+ el.style.left = (pixel.x - content_width + options.horizontalOffset) + 'px';
863
+ break;
864
+
865
+ default:
866
+ case 'center':
867
+ el.style.left = (pixel.x - (content_width / 2) + options.horizontalOffset) + 'px';
868
+ break;
869
+
870
+ case 'right':
871
+ el.style.left = (pixel.x + options.horizontalOffset) + 'px';
872
+ break;
873
+ }
874
+
875
+ el.style.display = auto_show ? 'block' : 'none';
876
+
877
+ if (!auto_show) options.show.apply(this, [el]);
878
+ };
879
+
880
+ overlay.onRemove = function () {
881
+ var el = overlay.el;
882
+
883
+ if (options.remove) {
884
+ options.remove.apply(this, [el]);
885
+ } else {
886
+ overlay.el.parentNode.removeChild(overlay.el);
887
+ overlay.el = null;
888
+ }
889
+ };
890
+
891
+ this.overlays.push(overlay);
892
+ return overlay;
893
+ };
894
+
895
+ GMaps.prototype.removeOverlay = function (overlay) {
896
+ for (var i = 0; i < this.overlays.length; i++) {
897
+ if (this.overlays[i] === overlay) {
898
+ this.overlays[i].setMap(null);
899
+ this.overlays.splice(i, 1);
900
+
901
+ break;
902
+ }
903
+ }
904
+ };
905
+
906
+ GMaps.prototype.removeOverlays = function () {
907
+ for (var i = 0, item; item = this.overlays[i]; i++) {
908
+ item.setMap(null);
909
+ }
910
+
911
+ this.overlays = [];
912
+ };
913
+
914
+ GMaps.prototype.drawPolyline = function (options) {
915
+ var path = [];
916
+ var points = options.path;
917
+
918
+ if (points.length) {
919
+ if (points[0][0] === undefined) {
920
+ path = points;
921
+ } else {
922
+ for (var i = 0, latlng; latlng = points[i]; i++) {
923
+ path.push(new google.maps.LatLng(latlng[0], latlng[1]));
924
+ }
925
+ }
926
+ }
927
+
928
+ var polyline_options = {
929
+ map: this.map,
930
+ path: path,
931
+ strokeColor: options.strokeColor,
932
+ strokeOpacity: options.strokeOpacity,
933
+ strokeWeight: options.strokeWeight,
934
+ geodesic: options.geodesic,
935
+ clickable: true,
936
+ editable: false,
937
+ visible: true
938
+ };
939
+
940
+ if (options.hasOwnProperty('clickable')) {
941
+ polyline_options.clickable = options.clickable;
942
+ }
943
+
944
+ if (options.hasOwnProperty('editable')) {
945
+ polyline_options.editable = options.editable;
946
+ }
947
+
948
+ if (options.hasOwnProperty('icons')) {
949
+ polyline_options.icons = options.icons;
950
+ }
951
+
952
+ if (options.hasOwnProperty('zIndex')) {
953
+ polyline_options.zIndex = options.zIndex;
954
+ }
955
+
956
+ var polyline = new google.maps.Polyline(polyline_options);
957
+ var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
958
+
959
+ for (var ev = 0; ev < polyline_events.length; ev++) {
960
+ (function (object, name) {
961
+ if (options[name]) {
962
+ google.maps.event.addListener(object, name, function (e) {
963
+ options[name].apply(this, [e]);
964
+ });
965
+ }
966
+ })(polyline, polyline_events[ev]);
967
+ }
968
+
969
+ this.polylines.push(polyline);
970
+
971
+ GMaps.fire('polyline_added', polyline, this);
972
+
973
+ return polyline;
974
+ };
975
+
976
+ GMaps.prototype.removePolyline = function (polyline) {
977
+ for (var i = 0; i < this.polylines.length; i++) {
978
+ if (this.polylines[i] === polyline) {
979
+ this.polylines[i].setMap(null);
980
+ this.polylines.splice(i, 1);
981
+
982
+ GMaps.fire('polyline_removed', polyline, this);
983
+
984
+ break;
985
+ }
986
+ }
987
+ };
988
+
989
+ GMaps.prototype.removePolylines = function () {
990
+ for (var i = 0, item; item = this.polylines[i]; i++) {
991
+ item.setMap(null);
992
+ }
993
+
994
+ this.polylines = [];
995
+ };
996
+
997
+ GMaps.prototype.drawCircle = function (options) {
998
+ options = extend_object({
999
+ map: this.map,
1000
+ center: new google.maps.LatLng(options.lat, options.lng)
1001
+ }, options);
1002
+
1003
+ delete options.lat;
1004
+ delete options.lng;
1005
+
1006
+ var polygon = new google.maps.Circle(options);
1007
+ var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
1008
+
1009
+ for (var ev = 0; ev < polygon_events.length; ev++) {
1010
+ (function (object, name) {
1011
+ if (options[name]) {
1012
+ google.maps.event.addListener(object, name, function (e) {
1013
+ options[name].apply(this, [e]);
1014
+ });
1015
+ }
1016
+ })(polygon, polygon_events[ev]);
1017
+ }
1018
+
1019
+ this.polygons.push(polygon);
1020
+
1021
+ return polygon;
1022
+ };
1023
+
1024
+ GMaps.prototype.drawRectangle = function (options) {
1025
+ options = extend_object({
1026
+ map: this.map
1027
+ }, options);
1028
+
1029
+ var latLngBounds = new google.maps.LatLngBounds(
1030
+ new google.maps.LatLng(options.bounds[0][0], options.bounds[0][1]),
1031
+ new google.maps.LatLng(options.bounds[1][0], options.bounds[1][1])
1032
+ );
1033
+
1034
+ options.bounds = latLngBounds;
1035
+
1036
+ var polygon = new google.maps.Rectangle(options);
1037
+ var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
1038
+
1039
+ for (var ev = 0; ev < polygon_events.length; ev++) {
1040
+ (function (object, name) {
1041
+ if (options[name]) {
1042
+ google.maps.event.addListener(object, name, function (e) {
1043
+ options[name].apply(this, [e]);
1044
+ });
1045
+ }
1046
+ })(polygon, polygon_events[ev]);
1047
+ }
1048
+
1049
+ this.polygons.push(polygon);
1050
+
1051
+ return polygon;
1052
+ };
1053
+
1054
+ GMaps.prototype.drawPolygon = function (options) {
1055
+ var useGeoJSON = false;
1056
+
1057
+ if (options.hasOwnProperty('useGeoJSON')) {
1058
+ useGeoJSON = options.useGeoJSON;
1059
+ }
1060
+
1061
+ delete options.useGeoJSON;
1062
+
1063
+ options = extend_object({
1064
+ map: this.map
1065
+ }, options);
1066
+
1067
+ if (useGeoJSON === false) {
1068
+ options.paths = [options.paths.slice(0)];
1069
+ }
1070
+
1071
+ if (options.paths.length > 0) {
1072
+ if (options.paths[0].length > 0) {
1073
+ options.paths = array_flat(array_map(options.paths, arrayToLatLng, useGeoJSON));
1074
+ }
1075
+ }
1076
+
1077
+ var polygon = new google.maps.Polygon(options);
1078
+ var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
1079
+
1080
+ for (var ev = 0; ev < polygon_events.length; ev++) {
1081
+ (function (object, name) {
1082
+ if (options[name]) {
1083
+ google.maps.event.addListener(object, name, function (e) {
1084
+ options[name].apply(this, [e]);
1085
+ });
1086
+ }
1087
+ })(polygon, polygon_events[ev]);
1088
+ }
1089
+
1090
+ this.polygons.push(polygon);
1091
+
1092
+ GMaps.fire('polygon_added', polygon, this);
1093
+
1094
+ return polygon;
1095
+ };
1096
+
1097
+ GMaps.prototype.removePolygon = function (polygon) {
1098
+ for (var i = 0; i < this.polygons.length; i++) {
1099
+ if (this.polygons[i] === polygon) {
1100
+ this.polygons[i].setMap(null);
1101
+ this.polygons.splice(i, 1);
1102
+
1103
+ GMaps.fire('polygon_removed', polygon, this);
1104
+
1105
+ break;
1106
+ }
1107
+ }
1108
+ };
1109
+
1110
+ GMaps.prototype.removePolygons = function () {
1111
+ for (var i = 0, item; item = this.polygons[i]; i++) {
1112
+ item.setMap(null);
1113
+ }
1114
+
1115
+ this.polygons = [];
1116
+ };
1117
+
1118
+ GMaps.prototype.getFromFusionTables = function (options) {
1119
+ var events = options.events;
1120
+
1121
+ delete options.events;
1122
+
1123
+ var fusion_tables_options = options;
1124
+ var layer = new google.maps.FusionTablesLayer(fusion_tables_options);
1125
+
1126
+ for (var ev in events) {
1127
+ (function (object, name) {
1128
+ google.maps.event.addListener(object, name, function (e) {
1129
+ events[name].apply(this, [e]);
1130
+ });
1131
+ })(layer, ev);
1132
+ }
1133
+
1134
+ this.layers.push(layer);
1135
+
1136
+ return layer;
1137
+ };
1138
+
1139
+ GMaps.prototype.loadFromFusionTables = function (options) {
1140
+ var layer = this.getFromFusionTables(options);
1141
+ layer.setMap(this.map);
1142
+
1143
+ return layer;
1144
+ };
1145
+
1146
+ GMaps.prototype.getFromKML = function (options) {
1147
+ var url = options.url;
1148
+ var events = options.events;
1149
+
1150
+ delete options.url;
1151
+ delete options.events;
1152
+
1153
+ var kml_options = options;
1154
+ var layer = new google.maps.KmlLayer(url, kml_options);
1155
+
1156
+ for (var ev in events) {
1157
+ (function (object, name) {
1158
+ google.maps.event.addListener(object, name, function (e) {
1159
+ events[name].apply(this, [e]);
1160
+ });
1161
+ })(layer, ev);
1162
+ }
1163
+
1164
+ this.layers.push(layer);
1165
+
1166
+ return layer;
1167
+ };
1168
+
1169
+ GMaps.prototype.loadFromKML = function (options) {
1170
+ var layer = this.getFromKML(options);
1171
+ layer.setMap(this.map);
1172
+
1173
+ return layer;
1174
+ };
1175
+
1176
+ GMaps.prototype.addLayer = function (layerName, options) {
1177
+ // var default_layers = ['weather', 'clouds', 'traffic', 'transit', 'bicycling', 'panoramio', 'places'];
1178
+ options = options || {};
1179
+ var layer;
1180
+
1181
+ switch(layerName) {
1182
+ case 'weather': this.singleLayers.weather = layer = new google.maps.weather.WeatherLayer();
1183
+ break;
1184
+
1185
+ case 'clouds': this.singleLayers.clouds = layer = new google.maps.weather.CloudLayer();
1186
+ break;
1187
+
1188
+ case 'traffic': this.singleLayers.traffic = layer = new google.maps.TrafficLayer();
1189
+ break;
1190
+
1191
+ case 'transit': this.singleLayers.transit = layer = new google.maps.TransitLayer();
1192
+ break;
1193
+
1194
+ case 'bicycling': this.singleLayers.bicycling = layer = new google.maps.BicyclingLayer();
1195
+ break;
1196
+
1197
+ case 'panoramio':
1198
+ this.singleLayers.panoramio = layer = new google.maps.panoramio.PanoramioLayer();
1199
+ layer.setTag(options.filter);
1200
+ delete options.filter;
1201
+
1202
+ if (options.click) {
1203
+ google.maps.event.addListener(layer, 'click', function (event) {
1204
+ options.click(event);
1205
+ delete options.click;
1206
+ });
1207
+ }
1208
+ break;
1209
+ case 'places':
1210
+ this.singleLayers.places = layer = new google.maps.places.PlacesService(this.map);
1211
+
1212
+ if (options.search || options.nearbySearch || options.radarSearch) {
1213
+ var placeSearchRequest = {
1214
+ bounds : options.bounds || null,
1215
+ keyword : options.keyword || null,
1216
+ location : options.location || null,
1217
+ name : options.name || null,
1218
+ radius : options.radius || null,
1219
+ rankBy : options.rankBy || null,
1220
+ types : options.types || null
1221
+ };
1222
+
1223
+ if (options.radarSearch) layer.radarSearch(placeSearchRequest, options.radarSearch);
1224
+ if (options.search) layer.search(placeSearchRequest, options.search);
1225
+ if (options.nearbySearch) layer.nearbySearch(placeSearchRequest, options.nearbySearch);
1226
+ }
1227
+
1228
+ if (options.textSearch) {
1229
+ var textSearchRequest = {
1230
+ bounds : options.bounds || null,
1231
+ location : options.location || null,
1232
+ query : options.query || null,
1233
+ radius : options.radius || null
1234
+ };
1235
+
1236
+ layer.textSearch(textSearchRequest, options.textSearch);
1237
+ }
1238
+ break;
1239
+ }
1240
+
1241
+ if (layer !== undefined) {
1242
+ if (typeof layer.setOptions === 'function') {
1243
+ layer.setOptions(options);
1244
+ }
1245
+ if (typeof layer.setMap === 'function') {
1246
+ layer.setMap(this.map);
1247
+ }
1248
+
1249
+ return layer;
1250
+ }
1251
+ };
1252
+
1253
+ GMaps.prototype.removeLayer = function (layer) {
1254
+ if (typeof(layer) === 'string' && this.singleLayers[layer] !== undefined) {
1255
+ this.singleLayers[layer].setMap(null);
1256
+
1257
+ delete this.singleLayers[layer];
1258
+ } else {
1259
+ for (var i = 0; i < this.layers.length; i++) {
1260
+ if (this.layers[i] === layer) {
1261
+ this.layers[i].setMap(null);
1262
+ this.layers.splice(i, 1);
1263
+
1264
+ break;
1265
+ }
1266
+ }
1267
+ }
1268
+ };
1269
+
1270
+ var travelMode, unitSystem;
1271
+
1272
+ GMaps.prototype.getRoutes = function (options) {
1273
+ switch (options.travelMode) {
1274
+ case 'bicycling':
1275
+ travelMode = google.maps.TravelMode.BICYCLING;
1276
+ break;
1277
+
1278
+ case 'transit':
1279
+ travelMode = google.maps.TravelMode.TRANSIT;
1280
+ break;
1281
+
1282
+ case 'driving':
1283
+ travelMode = google.maps.TravelMode.DRIVING;
1284
+ break;
1285
+
1286
+ default:
1287
+ travelMode = google.maps.TravelMode.WALKING;
1288
+ break;
1289
+ }
1290
+
1291
+ if (options.unitSystem === 'imperial') {
1292
+ unitSystem = google.maps.UnitSystem.IMPERIAL;
1293
+ } else {
1294
+ unitSystem = google.maps.UnitSystem.METRIC;
1295
+ }
1296
+
1297
+ var base_options = {
1298
+ avoidHighways: false,
1299
+ avoidTolls: false,
1300
+ optimizeWaypoints: false,
1301
+ waypoints: []
1302
+ };
1303
+ var request_options = extend_object(base_options, options);
1304
+
1305
+ request_options.origin = /string/.test(typeof options.origin) ? options.origin : new google.maps.LatLng(options.origin[0], options.origin[1]);
1306
+ request_options.destination = /string/.test(typeof options.destination) ? options.destination : new google.maps.LatLng(options.destination[0], options.destination[1]);
1307
+ request_options.travelMode = travelMode;
1308
+ request_options.unitSystem = unitSystem;
1309
+
1310
+ delete request_options.callback;
1311
+ delete request_options.error;
1312
+
1313
+ var self = this;
1314
+ var routes = [];
1315
+ var service = new google.maps.DirectionsService();
1316
+
1317
+ service.route(request_options, function (result, status) {
1318
+ if (status === google.maps.DirectionsStatus.OK) {
1319
+ for (var r in result.routes) {
1320
+ if (result.routes.hasOwnProperty(r)) routes.push(result.routes[r]);
1321
+ }
1322
+
1323
+ if (options.callback) options.callback(routes, result, status);
1324
+ } else {
1325
+ if (options.error) options.error(result, status);
1326
+ }
1327
+ });
1328
+ };
1329
+
1330
+ GMaps.prototype.removeRoutes = function () {
1331
+ this.routes.length = 0;
1332
+ };
1333
+
1334
+ GMaps.prototype.getElevations = function (options) {
1335
+ options = extend_object({
1336
+ locations: [],
1337
+ path : false,
1338
+ samples : 256
1339
+ }, options);
1340
+
1341
+ if (options.locations.length > 0) {
1342
+ if (options.locations[0].length > 0) {
1343
+ options.locations = array_flat(array_map([options.locations], arrayToLatLng, false));
1344
+ }
1345
+ }
1346
+
1347
+ var callback = options.callback;
1348
+
1349
+ delete options.callback;
1350
+
1351
+ var service = new google.maps.ElevationService();
1352
+
1353
+ if (!options.path) {
1354
+ delete options.path;
1355
+ delete options.samples;
1356
+
1357
+ service.getElevationForLocations(options, function (result, status) {
1358
+ if (callback && typeof(callback) === 'function') callback(result, status);
1359
+ });
1360
+ } else {
1361
+ var pathRequest = {
1362
+ path : options.locations,
1363
+ samples : options.samples
1364
+ };
1365
+
1366
+ service.getElevationAlongPath(pathRequest, function (result, status) {
1367
+ if (callback && typeof(callback) === 'function') callback(result, status);
1368
+ });
1369
+ }
1370
+ };
1371
+
1372
+ GMaps.prototype.cleanRoute = GMaps.prototype.removePolylines;
1373
+
1374
+ GMaps.prototype.renderRoute = function (options, renderOptions) {
1375
+ var self = this;
1376
+ var panel = ((typeof renderOptions.panel === 'string') ? document.getElementById(renderOptions.panel.replace('#', '')) : renderOptions.panel);
1377
+
1378
+ renderOptions.panel = panel;
1379
+ renderOptions = extend_object({
1380
+ map: this.map
1381
+ }, renderOptions);
1382
+
1383
+ var display = new google.maps.DirectionsRenderer(renderOptions);
1384
+
1385
+ this.getRoutes({
1386
+ origin: options.origin,
1387
+ destination: options.destination,
1388
+ travelMode: options.travelMode,
1389
+ waypoints: options.waypoints,
1390
+ unitSystem: options.unitSystem,
1391
+ error: options.error,
1392
+ avoidHighways: options.avoidHighways,
1393
+ avoidTolls: options.avoidTolls,
1394
+ optimizeWaypoints: options.optimizeWaypoints,
1395
+ callback: function (routes, response, status) {
1396
+ if (status === google.maps.DirectionsStatus.OK) display.setDirections(response);
1397
+ }
1398
+ });
1399
+ };
1400
+
1401
+ GMaps.prototype.drawRoute = function (options) {
1402
+ var self = this;
1403
+
1404
+ this.getRoutes({
1405
+ origin: options.origin,
1406
+ destination: options.destination,
1407
+ travelMode: options.travelMode,
1408
+ waypoints: options.waypoints,
1409
+ unitSystem: options.unitSystem,
1410
+ error: options.error,
1411
+ avoidHighways: options.avoidHighways,
1412
+ avoidTolls: options.avoidTolls,
1413
+ optimizeWaypoints: options.optimizeWaypoints,
1414
+ callback: function (routes) {
1415
+ if (routes.length > 0) {
1416
+ var polyline_options = {
1417
+ path: routes[routes.length - 1].overview_path,
1418
+ strokeColor: options.strokeColor,
1419
+ strokeOpacity: options.strokeOpacity,
1420
+ strokeWeight: options.strokeWeight
1421
+ };
1422
+
1423
+ if (options.hasOwnProperty('icons')) {
1424
+ polyline_options.icons = options.icons;
1425
+ }
1426
+
1427
+ self.drawPolyline(polyline_options);
1428
+
1429
+ if (options.callback) options.callback(routes[routes.length - 1]);
1430
+ }
1431
+ }
1432
+ });
1433
+ };
1434
+
1435
+ GMaps.prototype.travelRoute = function (options) {
1436
+ if (options.origin && options.destination) {
1437
+ this.getRoutes({
1438
+ origin: options.origin,
1439
+ destination: options.destination,
1440
+ travelMode: options.travelMode,
1441
+ waypoints : options.waypoints,
1442
+ unitSystem: options.unitSystem,
1443
+ error: options.error,
1444
+ callback: function (e) {
1445
+ if (e.length > 0 && options.start) options.start(e[e.length - 1]);
1446
+
1447
+ if (e.length > 0 && options.step) {
1448
+ var route = e[e.length - 1];
1449
+
1450
+ if (route.legs.length > 0) {
1451
+ var steps = route.legs[0].steps;
1452
+
1453
+ for (var i = 0, step; step = steps[i]; i++) {
1454
+ step.step_number = i;
1455
+ options.step(step, (route.legs[0].steps.length - 1));
1456
+ }
1457
+ }
1458
+ }
1459
+
1460
+ if (e.length > 0 && options.end) options.end(e[e.length - 1]);
1461
+ }
1462
+ });
1463
+ } else if (options.route) {
1464
+ if (options.route.legs.length > 0) {
1465
+ var steps = options.route.legs[0].steps;
1466
+
1467
+ for (var i = 0, step; step = steps[i]; i++) {
1468
+ step.step_number = i;
1469
+ options.step(step);
1470
+ }
1471
+ }
1472
+ }
1473
+ };
1474
+
1475
+ GMaps.prototype.drawSteppedRoute = function (options) {
1476
+ var self = this;
1477
+
1478
+ if (options.origin && options.destination) {
1479
+ this.getRoutes({
1480
+ origin: options.origin,
1481
+ destination: options.destination,
1482
+ travelMode: options.travelMode,
1483
+ waypoints : options.waypoints,
1484
+ error: options.error,
1485
+ callback: function (e) {
1486
+ if (e.length > 0 && options.start) options.start(e[e.length - 1]);
1487
+
1488
+ if (e.length > 0 && options.step) {
1489
+ var route = e[e.length - 1];
1490
+
1491
+ if (route.legs.length > 0) {
1492
+ var steps = route.legs[0].steps;
1493
+
1494
+ for (var i = 0, step; step = steps[i]; i++) {
1495
+ step.step_number = i;
1496
+ var polyline_options = {
1497
+ path: step.path,
1498
+ strokeColor: options.strokeColor,
1499
+ strokeOpacity: options.strokeOpacity,
1500
+ strokeWeight: options.strokeWeight
1501
+ };
1502
+
1503
+ if (options.hasOwnProperty('icons')) {
1504
+ polyline_options.icons = options.icons;
1505
+ }
1506
+
1507
+ self.drawPolyline(polyline_options);
1508
+ options.step(step, (route.legs[0].steps.length - 1));
1509
+ }
1510
+ }
1511
+ }
1512
+
1513
+ if (e.length > 0 && options.end) options.end(e[e.length - 1]);
1514
+ }
1515
+ });
1516
+ } else if (options.route) {
1517
+ if (options.route.legs.length > 0) {
1518
+ var steps = options.route.legs[0].steps;
1519
+
1520
+ for (var i = 0, step; step = steps[i]; i++) {
1521
+ step.step_number = i;
1522
+ var polyline_options = {
1523
+ path: step.path,
1524
+ strokeColor: options.strokeColor,
1525
+ strokeOpacity: options.strokeOpacity,
1526
+ strokeWeight: options.strokeWeight
1527
+ };
1528
+
1529
+ if (options.hasOwnProperty('icons')) {
1530
+ polyline_options.icons = options.icons;
1531
+ }
1532
+
1533
+ self.drawPolyline(polyline_options);
1534
+ options.step(step);
1535
+ }
1536
+ }
1537
+ }
1538
+ };
1539
+
1540
+ GMaps.Route = function (options) {
1541
+ this.origin = options.origin;
1542
+ this.destination = options.destination;
1543
+ this.waypoints = options.waypoints;
1544
+
1545
+ this.map = options.map;
1546
+ this.route = options.route;
1547
+ this.step_count = 0;
1548
+ this.steps = this.route.legs[0].steps;
1549
+ this.steps_length = this.steps.length;
1550
+
1551
+ var polyline_options = {
1552
+ path: new google.maps.MVCArray(),
1553
+ strokeColor: options.strokeColor,
1554
+ strokeOpacity: options.strokeOpacity,
1555
+ strokeWeight: options.strokeWeight
1556
+ };
1557
+
1558
+ if (options.hasOwnProperty('icons')) {
1559
+ polyline_options.icons = options.icons;
1560
+ }
1561
+
1562
+ this.polyline = this.map.drawPolyline(polyline_options).getPath();
1563
+ };
1564
+
1565
+ GMaps.Route.prototype.getRoute = function (options) {
1566
+ var self = this;
1567
+
1568
+ this.map.getRoutes({
1569
+ origin : this.origin,
1570
+ destination : this.destination,
1571
+ travelMode : options.travelMode,
1572
+ waypoints : this.waypoints || [],
1573
+ error: options.error,
1574
+ callback : function () {
1575
+ self.route = e[0];
1576
+
1577
+ if (options.callback) options.callback.call(self);
1578
+ }
1579
+ });
1580
+ };
1581
+
1582
+ GMaps.Route.prototype.back = function () {
1583
+ if (this.step_count > 0) {
1584
+ this.step_count--;
1585
+ var path = this.route.legs[0].steps[this.step_count].path;
1586
+
1587
+ for (var p in path) {
1588
+ if (path.hasOwnProperty(p)) this.polyline.pop();
1589
+ }
1590
+ }
1591
+ };
1592
+
1593
+ GMaps.Route.prototype.forward = function () {
1594
+ if (this.step_count < this.steps_length) {
1595
+ var path = this.route.legs[0].steps[this.step_count].path;
1596
+
1597
+ for (var p in path) {
1598
+ if (path.hasOwnProperty(p)) this.polyline.push(path[p]);
1599
+ }
1600
+
1601
+ this.step_count++;
1602
+ }
1603
+ };
1604
+
1605
+ GMaps.prototype.checkGeofence = function (lat, lng, fence) {
1606
+ return fence.containsLatLng(new google.maps.LatLng(lat, lng));
1607
+ };
1608
+
1609
+ GMaps.prototype.checkMarkerGeofence = function (marker, outside_callback) {
1610
+ if (marker.fences) {
1611
+ for (var i = 0, fence; fence = marker.fences[i]; i++) {
1612
+ var pos = marker.getPosition();
1613
+
1614
+ if (!this.checkGeofence(pos.lat(), pos.lng(), fence)) outside_callback(marker, fence);
1615
+ }
1616
+ }
1617
+ };
1618
+
1619
+ GMaps.prototype.toImage = function (options) {
1620
+ var options = options || {};
1621
+ var static_map_options = {};
1622
+
1623
+ static_map_options['size'] = options['size'] || [this.el.clientWidth, this.el.clientHeight];
1624
+ static_map_options['lat'] = this.getCenter().lat();
1625
+ static_map_options['lng'] = this.getCenter().lng();
1626
+
1627
+ if (this.markers.length > 0) {
1628
+ static_map_options['markers'] = [];
1629
+
1630
+ for (var i = 0; i < this.markers.length; i++) {
1631
+ static_map_options['markers'].push({
1632
+ lat: this.markers[i].getPosition().lat(),
1633
+ lng: this.markers[i].getPosition().lng()
1634
+ });
1635
+ }
1636
+ }
1637
+
1638
+ if (this.polylines.length > 0) {
1639
+ var polyline = this.polylines[0];
1640
+
1641
+ static_map_options['polyline'] = {};
1642
+ static_map_options['polyline']['path'] = google.maps.geometry.encoding.encodePath(polyline.getPath());
1643
+ static_map_options['polyline']['strokeColor'] = polyline.strokeColor;
1644
+ static_map_options['polyline']['strokeOpacity'] = polyline.strokeOpacity;
1645
+ static_map_options['polyline']['strokeWeight'] = polyline.strokeWeight;
1646
+ }
1647
+
1648
+ return GMaps.staticMapURL(static_map_options);
1649
+ };
1650
+
1651
+ GMaps.staticMapURL = function (options) {
1652
+ var data;
1653
+ var parameters = [];
1654
+ var static_root = (location.protocol === 'file:' ? 'http:' : location.protocol ) + '//maps.googleapis.com/maps/api/staticmap';
1655
+
1656
+ if (options.url) {
1657
+ static_root = options.url;
1658
+ delete options.url;
1659
+ }
1660
+
1661
+ static_root += '?';
1662
+
1663
+ var markers = options.markers;
1664
+
1665
+ delete options.markers;
1666
+
1667
+ if (!markers && options.marker) {
1668
+ markers = [options.marker];
1669
+ delete options.marker;
1670
+ }
1671
+
1672
+ var styles = options.styles;
1673
+
1674
+ delete options.styles;
1675
+
1676
+ var polyline = options.polyline;
1677
+
1678
+ delete options.polyline;
1679
+
1680
+ if (options.center) {
1681
+ parameters.push('center=' + options.center);
1682
+ delete options.center;
1683
+ } else if (options.address) {
1684
+ parameters.push('center=' + options.address);
1685
+ delete options.address;
1686
+ } else if (options.lat) {
1687
+ parameters.push(['center=', options.lat, ',', options.lng].join(''));
1688
+ delete options.lat;
1689
+ delete options.lng;
1690
+ } else if (options.visible) {
1691
+ var visible = encodeURI(options.visible.join('|'));
1692
+ parameters.push('visible=' + visible);
1693
+ }
1694
+
1695
+ var size = options.size;
1696
+
1697
+ if (size) {
1698
+ if (size.join) {
1699
+ size = size.join('x');
1700
+ }
1701
+
1702
+ delete options.size;
1703
+ } else {
1704
+ size = '630x300';
1705
+ }
1706
+
1707
+ parameters.push('size=' + size);
1708
+
1709
+ if (!options.zoom && options.zoom !== false) {
1710
+ options.zoom = 15;
1711
+ }
1712
+
1713
+ var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true;
1714
+ delete options.sensor;
1715
+ parameters.push('sensor=' + sensor);
1716
+
1717
+ for (var param in options) {
1718
+ if (options.hasOwnProperty(param)) parameters.push(param + '=' + options[param]);
1719
+ }
1720
+
1721
+ if (markers) {
1722
+ var marker, loc;
1723
+
1724
+ for (var i = 0; data = markers[i]; i++) {
1725
+ marker = [];
1726
+
1727
+ if (data.size && data.size !== 'normal') {
1728
+ marker.push('size:' + data.size);
1729
+ delete data.size;
1730
+ } else if (data.icon) {
1731
+ marker.push('icon:' + encodeURI(data.icon));
1732
+ delete data.icon;
1733
+ }
1734
+
1735
+ if (data.color) {
1736
+ marker.push('color:' + data.color.replace('#', '0x'));
1737
+ delete data.color;
1738
+ }
1739
+
1740
+ if (data.label) {
1741
+ marker.push('label:' + data.label[0].toUpperCase());
1742
+ delete data.label;
1743
+ }
1744
+
1745
+ loc = (data.address ? data.address : data.lat + ',' + data.lng);
1746
+ delete data.address;
1747
+ delete data.lat;
1748
+ delete data.lng;
1749
+
1750
+ for (var new_param in data) {
1751
+ if (data.hasOwnProperty(new_param)) marker.push(new_param + ':' + data[new_param]);
1752
+ }
1753
+
1754
+ if (marker.length || i === 0) {
1755
+ marker.push(loc);
1756
+ marker = marker.join('|');
1757
+ parameters.push('markers=' + encodeURI(marker));
1758
+ } else {
1759
+ marker = parameters.pop() + encodeURI('|' + loc);
1760
+ parameters.push(marker);
1761
+ }
1762
+ }
1763
+ }
1764
+
1765
+ if (styles) {
1766
+ for (var i = 0; i < styles.length; i++) {
1767
+ var styleRule = [];
1768
+
1769
+ if (styles[i].featureType) styleRule.push('feature:' + styles[i].featureType.toLowerCase());
1770
+
1771
+ if (styles[i].elementType) styleRule.push('element:' + styles[i].elementType.toLowerCase());
1772
+
1773
+ for (var j = 0; j < styles[i].stylers.length; j++) {
1774
+ for (var p in styles[i].stylers[j]) {
1775
+ var ruleArg = styles[i].stylers[j][p];
1776
+
1777
+ if (p === 'hue' || p === 'color') {
1778
+ ruleArg = '0x' + ruleArg.substring(1);
1779
+ }
1780
+
1781
+ styleRule.push(p + ':' + ruleArg);
1782
+ }
1783
+ }
1784
+
1785
+ var rule = styleRule.join('|');
1786
+ if (rule !== '') parameters.push('style=' + rule);
1787
+ }
1788
+ }
1789
+
1790
+ function parseColor(color, opacity) {
1791
+ if (color[0] === '#') {
1792
+ color = color.replace('#', '0x');
1793
+
1794
+ if (opacity) {
1795
+ opacity = parseFloat(opacity);
1796
+ opacity = Math.min(1, Math.max(opacity, 0));
1797
+
1798
+ if (opacity === 0) return '0x00000000';
1799
+
1800
+ opacity = (opacity * 255).toString(16);
1801
+
1802
+ if (opacity.length === 1) {
1803
+ opacity += opacity;
1804
+ }
1805
+
1806
+ color = color.slice(0,8) + opacity;
1807
+ }
1808
+ }
1809
+
1810
+ return color;
1811
+ }
1812
+
1813
+ if (polyline) {
1814
+ data = polyline;
1815
+ polyline = [];
1816
+
1817
+ if (data.strokeWeight) polyline.push('weight:' + parseInt(data.strokeWeight, 10));
1818
+
1819
+ if (data.strokeColor) {
1820
+ var color = parseColor(data.strokeColor, data.strokeOpacity);
1821
+ polyline.push('color:' + color);
1822
+ }
1823
+
1824
+ if (data.fillColor) {
1825
+ var fillcolor = parseColor(data.fillColor, data.fillOpacity);
1826
+ polyline.push('fillcolor:' + fillcolor);
1827
+ }
1828
+
1829
+ var path = data.path;
1830
+ if (path.join) {
1831
+ for (var j = 0, pos; pos=path[j]; j++) polyline.push(pos.join(','));
1832
+ } else {
1833
+ polyline.push('enc:' + path);
1834
+ }
1835
+
1836
+ polyline = polyline.join('|');
1837
+ parameters.push('path=' + encodeURI(polyline));
1838
+ }
1839
+
1840
+ var dpi = window.devicePixelRatio || 1;
1841
+ parameters.push('scale=' + dpi);
1842
+
1843
+ parameters = parameters.join('&');
1844
+ return static_root + parameters;
1845
+ };
1846
+
1847
+ GMaps.prototype.addMapType = function (mapTypeId, options) {
1848
+ if (options.hasOwnProperty('getTileUrl') && typeof(options['getTileUrl']) === 'function') {
1849
+ options.tileSize = options.tileSize || new google.maps.Size(256, 256);
1850
+
1851
+ var mapType = new google.maps.ImageMapType(options);
1852
+
1853
+ this.map.mapTypes.set(mapTypeId, mapType);
1854
+ } else {
1855
+ throw '"getTileUrl" function required.';
1856
+ }
1857
+ };
1858
+
1859
+ GMaps.prototype.addOverlayMapType = function (options) {
1860
+ if (options.hasOwnProperty('getTile') && typeof(options['getTile']) === 'function') {
1861
+ var overlayMapTypeIndex = options.index;
1862
+
1863
+ delete options.index;
1864
+
1865
+ this.map.overlayMapTypes.insertAt(overlayMapTypeIndex, options);
1866
+ }else {
1867
+ throw '"getTileUrl" function required.';
1868
+ }
1869
+ };
1870
+
1871
+ GMaps.prototype.removeOverlayMapType = function (overlayMapTypeIndex) {
1872
+ this.map.overlayMapTypes.removeAt(overlayMapTypeIndex);
1873
+ };
1874
+
1875
+ GMaps.prototype.addStyle = function (options) {
1876
+ var styledMapType = new google.maps.StyledMapType(options.styles, { name: options.styledMapName });
1877
+
1878
+ this.map.mapTypes.set(options.mapTypeId, styledMapType);
1879
+ };
1880
+
1881
+ GMaps.prototype.setStyle = function (mapTypeId) {
1882
+ this.map.setMapTypeId(mapTypeId);
1883
+ };
1884
+
1885
+ GMaps.prototype.createPanorama = function (streetview_options) {
1886
+ if (!streetview_options.hasOwnProperty('lat') || !streetview_options.hasOwnProperty('lng')) {
1887
+ streetview_options.lat = this.getCenter().lat();
1888
+ streetview_options.lng = this.getCenter().lng();
1889
+ }
1890
+
1891
+ this.panorama = GMaps.createPanorama(streetview_options);
1892
+ this.map.setStreetView(this.panorama);
1893
+
1894
+ return this.panorama;
1895
+ };
1896
+
1897
+ GMaps.createPanorama = function (options) {
1898
+ var el = getElementById(options.el, options.context);
1899
+
1900
+ options.position = new google.maps.LatLng(options.lat, options.lng);
1901
+
1902
+ delete options.el;
1903
+ delete options.context;
1904
+ delete options.lat;
1905
+ delete options.lng;
1906
+
1907
+ var streetview_options = extend_object({ visible : true }, options);
1908
+ var streetview_events = [
1909
+ 'closeclick', 'links_changed', 'pano_changed', 'position_changed', 'pov_changed', 'resize', 'visible_changed'
1910
+ ];
1911
+
1912
+ for (var i = 0; i < streetview_events.length; i++) {
1913
+ delete streetview_options[streetview_events[i]];
1914
+ }
1915
+
1916
+ var panorama = new google.maps.StreetViewPanorama(el, streetview_options);
1917
+
1918
+ for (var i = 0; i < streetview_events.length; i++) {
1919
+ (function (object, name) {
1920
+ if (options[name]) {
1921
+ google.maps.event.addListener(object, name, function () {
1922
+ options[name].apply(this);
1923
+ });
1924
+ }
1925
+ })(panorama, streetview_events[i]);
1926
+ }
1927
+
1928
+ return panorama;
1929
+ };
1930
+
1931
+ GMaps.prototype.on = function (event_name, handler) {
1932
+ return GMaps.on(event_name, this, handler);
1933
+ };
1934
+
1935
+ GMaps.prototype.off = function (event_name) {
1936
+ GMaps.off(event_name, this);
1937
+ };
1938
+
1939
+ GMaps.prototype.once = function (event_name, handler) {
1940
+ return GMaps.once(event_name, this, handler);
1941
+ };
1942
+
1943
+ GMaps.custom_events = [
1944
+ 'marker_added', 'marker_removed', 'polyline_added', 'polyline_removed', 'polygon_added', 'polygon_removed',
1945
+ 'geolocated', 'geolocation_failed'
1946
+ ];
1947
+
1948
+ GMaps.on = function (event_name, object, handler) {
1949
+ if (GMaps.custom_events.indexOf(event_name) === -1) {
1950
+ if (object instanceof GMaps) object = object.map;
1951
+ return google.maps.event.addListener(object, event_name, handler);
1952
+ } else {
1953
+ var registered_event = {
1954
+ handler : handler,
1955
+ eventName : event_name
1956
+ };
1957
+
1958
+ object.registered_events[event_name] = object.registered_events[event_name] || [];
1959
+ object.registered_events[event_name].push(registered_event);
1960
+
1961
+ return registered_event;
1962
+ }
1963
+ };
1964
+
1965
+ GMaps.off = function (event_name, object) {
1966
+ if (GMaps.custom_events.indexOf(event_name) === -1) {
1967
+ if (object instanceof GMaps) object = object.map;
1968
+
1969
+ google.maps.event.clearListeners(object, event_name);
1970
+ } else {
1971
+ object.registered_events[event_name] = [];
1972
+ }
1973
+ };
1974
+
1975
+ GMaps.once = function (event_name, object, handler) {
1976
+ if (GMaps.custom_events.indexOf(event_name) === -1) {
1977
+ if (object instanceof GMaps) object = object.map;
1978
+ return google.maps.event.addListenerOnce(object, event_name, handler);
1979
+ }
1980
+ };
1981
+
1982
+ GMaps.fire = function (event_name, object, scope) {
1983
+ if (GMaps.custom_events.indexOf(event_name) === -1) {
1984
+ google.maps.event.trigger(object, event_name, Array.prototype.slice.apply(arguments).slice(2));
1985
+ } else {
1986
+ if (event_name in scope.registered_events) {
1987
+ var firing_events = scope.registered_events[event_name];
1988
+
1989
+ for (var i = 0; i < firing_events.length; i++) {
1990
+ (function (handler, scope, object) {
1991
+ handler.apply(scope, [object]);
1992
+ })(firing_events[i]['handler'], scope, object);
1993
+ }
1994
+ }
1995
+ }
1996
+ };
1997
+
1998
+ GMaps.geolocate = function (options) {
1999
+ var complete_callback = options.always || options.complete;
2000
+
2001
+ if (navigator.geolocation) {
2002
+ navigator.geolocation.getCurrentPosition(function (position) {
2003
+ options.success(position);
2004
+ if (complete_callback) complete_callback();
2005
+ }, function (error) {
2006
+ options.error(error);
2007
+ if (complete_callback) complete_callback();
2008
+ }, options.options);
2009
+ } else {
2010
+ options.not_supported();
2011
+ if (complete_callback) complete_callback();
2012
+ }
2013
+ };
2014
+
2015
+ GMaps.geocode = function (options) {
2016
+ this.geocoder = new google.maps.Geocoder();
2017
+
2018
+ var callback = options.callback;
2019
+
2020
+ if (options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) {
2021
+ options.latLng = new google.maps.LatLng(options.lat, options.lng);
2022
+ }
2023
+
2024
+ delete options.lat;
2025
+ delete options.lng;
2026
+ delete options.callback;
2027
+
2028
+ this.geocoder.geocode(options, function (results, status) {
2029
+ callback(results, status);
2030
+ });
2031
+ };
2032
+
2033
+ if (typeof window.google === 'object' && window.google.maps) {
2034
+ if (!google.maps.Polygon.prototype.getBounds) {
2035
+ google.maps.Polygon.prototype.getBounds = function (latLng) {
2036
+ var bounds = new google.maps.LatLngBounds();
2037
+ var paths = this.getPaths();
2038
+ var path;
2039
+
2040
+ for (var p = 0; p < paths.getLength(); p++) {
2041
+ path = paths.getAt(p);
2042
+ for (var i = 0; i < path.getLength(); i++) {
2043
+ bounds.extend(path.getAt(i));
2044
+ }
2045
+ }
2046
+
2047
+ return bounds;
2048
+ };
2049
+ }
2050
+
2051
+ if (!google.maps.Polygon.prototype.containsLatLng) {
2052
+ google.maps.Polygon.prototype.containsLatLng = function (latLng) {
2053
+ var bounds = this.getBounds();
2054
+
2055
+ if (bounds !== null && !bounds.contains(latLng)) return false;
2056
+
2057
+ var inPoly = false;
2058
+ var numPaths = this.getPaths().getLength();
2059
+
2060
+ for (var p = 0; p < numPaths; p++) {
2061
+ var path = this.getPaths().getAt(p);
2062
+ var numPoints = path.getLength();
2063
+ var j = numPoints - 1;
2064
+
2065
+ for (var i = 0; i < numPoints; i++) {
2066
+ var vertex1 = path.getAt(i);
2067
+ var vertex2 = path.getAt(j);
2068
+
2069
+ if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
2070
+ if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
2071
+ inPoly = !inPoly;
2072
+ }
2073
+ }
2074
+
2075
+ j = i;
2076
+ }
2077
+ }
2078
+
2079
+ return inPoly;
2080
+ };
2081
+ }
2082
+
2083
+ if (!google.maps.Circle.prototype.containsLatLng) {
2084
+ google.maps.Circle.prototype.containsLatLng = function (latLng) {
2085
+ if (google.maps.geometry) {
2086
+ return google.maps.geometry.spherical.computeDistanceBetween(this.getCenter(), latLng) <= this.getRadius();
2087
+ } else {
2088
+ return true;
2089
+ }
2090
+ };
2091
+ }
2092
+
2093
+ google.maps.Rectangle.prototype.containsLatLng = function (latLng) {
2094
+ return this.getBounds().contains(latLng);
2095
+ };
2096
+
2097
+ google.maps.LatLngBounds.prototype.containsLatLng = function (latLng) {
2098
+ return this.contains(latLng);
2099
+ };
2100
+
2101
+ google.maps.Marker.prototype.setFences = function (fences) {
2102
+ this.fences = fences;
2103
+ };
2104
+
2105
+ google.maps.Marker.prototype.addFence = function (fence) {
2106
+ this.fences.push(fence);
2107
+ };
2108
+
2109
+ google.maps.Marker.prototype.getId = function () {
2110
+ return this['__gm_id'];
2111
+ };
2112
+ }
2113
+
2114
+ if (!Array.prototype.indexOf) {
2115
+ Array.prototype.indexOf = function (searchElement) {
2116
+ 'use strict';
2117
+
2118
+ if (this === null) {
2119
+ throw new TypeError();
2120
+ }
2121
+
2122
+ var t = Object(this);
2123
+ var len = t.length >>> 0;
2124
+
2125
+ if (len === 0) return -1;
2126
+
2127
+ var n = 0;
2128
+
2129
+ if (arguments.length > 1) {
2130
+ n = Number(arguments[1]);
2131
+
2132
+ if (n != n) {
2133
+ n = 0;
2134
+ } else if (n != 0 && n != Infinity && n != -Infinity) {
2135
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
2136
+ }
2137
+ }
2138
+
2139
+ if (n >= len) return -1;
2140
+
2141
+ var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
2142
+
2143
+ for (; k < len; k++) {
2144
+ if (k in t && t[k] === searchElement) return k;
2145
+ }
2146
+
2147
+ return -1;
2148
+ }
2149
+ }
2150
+
2151
+ return GMaps;
2152
+
2153
+ }));