active_frontend 13.3.0 → 14.0.0

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