This repository has been archived by the owner on Nov 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
angular-google-maps.js
14176 lines (12774 loc) · 505 KB
/
angular-google-maps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*! angular-google-maps 2.4.1 2017-01-05
* AngularJS directives for Google Maps
* git: https://github.com/angular-ui/angular-google-maps.git
*/
;
(function( window, angular, _, undefined ){
'use strict';
/*
!
The MIT License
Copyright (c) 2010-2013 Google, Inc. http://angularjs.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
angular-google-maps
https://github.com/angular-ui/angular-google-maps
@authors
Nicolas Laplante - https://plus.google.com/108189012221374960701
Nicholas McCready - https://twitter.com/nmccready
*/
(function() {
angular.module('uiGmapgoogle-maps.providers', ['nemLogging']);
angular.module('uiGmapgoogle-maps.wrapped', []);
angular.module('uiGmapgoogle-maps.extensions', ['uiGmapgoogle-maps.wrapped', 'uiGmapgoogle-maps.providers']);
angular.module('uiGmapgoogle-maps.directives.api.utils', ['uiGmapgoogle-maps.extensions']);
angular.module('uiGmapgoogle-maps.directives.api.managers', []);
angular.module('uiGmapgoogle-maps.directives.api.options', ['uiGmapgoogle-maps.directives.api.utils']);
angular.module('uiGmapgoogle-maps.directives.api.options.builders', []);
angular.module('uiGmapgoogle-maps.directives.api.models.child', ['uiGmapgoogle-maps.directives.api.utils', 'uiGmapgoogle-maps.directives.api.options', 'uiGmapgoogle-maps.directives.api.options.builders']);
angular.module('uiGmapgoogle-maps.directives.api.models.parent', ['uiGmapgoogle-maps.directives.api.managers', 'uiGmapgoogle-maps.directives.api.models.child', 'uiGmapgoogle-maps.providers']);
angular.module('uiGmapgoogle-maps.directives.api', ['uiGmapgoogle-maps.directives.api.models.parent']);
angular.module('uiGmapgoogle-maps', ['uiGmapgoogle-maps.directives.api', 'uiGmapgoogle-maps.providers']);
}).call(this);
;(function() {
angular.module('uiGmapgoogle-maps.providers').factory('uiGmapMapScriptLoader', [
'$q', 'uiGmapuuid', function($q, uuid) {
var getScriptUrl, includeScript, isGoogleMapsLoaded, scriptId, usedConfiguration;
scriptId = void 0;
usedConfiguration = void 0;
getScriptUrl = function(options) {
if (options.china) {
return 'http://maps.google.cn/maps/api/js?';
} else {
if (options.transport === 'auto') {
return '//maps.googleapis.com/maps/api/js?';
} else {
return options.transport + '://maps.googleapis.com/maps/api/js?';
}
}
};
includeScript = function(options) {
var omitOptions, query, script, scriptElem;
omitOptions = ['transport', 'isGoogleMapsForWork', 'china', 'preventLoad'];
if (options.isGoogleMapsForWork) {
omitOptions.push('key');
}
query = _.map(_.omit(options, omitOptions), function(v, k) {
return k + '=' + v;
});
if (scriptId) {
scriptElem = document.getElementById(scriptId);
scriptElem.parentNode.removeChild(scriptElem);
}
query = query.join('&');
script = document.createElement('script');
script.id = scriptId = "ui_gmap_map_load_" + (uuid.generate());
script.type = 'text/javascript';
script.src = getScriptUrl(options) + query;
return document.head.appendChild(script);
};
isGoogleMapsLoaded = function() {
return angular.isDefined(window.google) && angular.isDefined(window.google.maps);
};
return {
load: function(options) {
var deferred, randomizedFunctionName;
deferred = $q.defer();
if (isGoogleMapsLoaded()) {
deferred.resolve(window.google.maps);
return deferred.promise;
}
randomizedFunctionName = options.callback = 'onGoogleMapsReady' + Math.round(Math.random() * 1000);
window[randomizedFunctionName] = function() {
window[randomizedFunctionName] = null;
deferred.resolve(window.google.maps);
};
if (window.navigator.connection && window.Connection && window.navigator.connection.type === window.Connection.NONE && !options.preventLoad) {
document.addEventListener('online', function() {
if (!isGoogleMapsLoaded()) {
return includeScript(options);
}
});
} else if (!options.preventLoad) {
includeScript(options);
}
usedConfiguration = options;
usedConfiguration.randomizedFunctionName = randomizedFunctionName;
return deferred.promise;
},
manualLoad: function() {
var config;
config = usedConfiguration;
if (!isGoogleMapsLoaded()) {
return includeScript(config);
} else {
if (window[config.randomizedFunctionName]) {
return window[config.randomizedFunctionName]();
}
}
}
};
}
]).provider('uiGmapGoogleMapApi', function() {
this.options = {
transport: 'https',
isGoogleMapsForWork: false,
china: false,
v: '3',
libraries: '',
language: 'en',
preventLoad: false
};
this.configure = function(options) {
angular.extend(this.options, options);
};
this.$get = [
'uiGmapMapScriptLoader', (function(_this) {
return function(loader) {
return loader.load(_this.options);
};
})(this)
];
return this;
}).service('uiGmapGoogleMapApiManualLoader', [
'uiGmapMapScriptLoader', function(loader) {
return {
load: function() {
loader.manualLoad();
}
};
}
]);
}).call(this);
;(function() {
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
angular.module('uiGmapgoogle-maps.extensions').service('uiGmapExtendGWin', function() {
return {
init: _.once(function() {
var uiGmapInfoBox;
if (!(google || (typeof google !== "undefined" && google !== null ? google.maps : void 0) || (google.maps.InfoWindow != null))) {
return;
}
google.maps.InfoWindow.prototype._open = google.maps.InfoWindow.prototype.open;
google.maps.InfoWindow.prototype._close = google.maps.InfoWindow.prototype.close;
google.maps.InfoWindow.prototype._isOpen = false;
google.maps.InfoWindow.prototype.open = function(map, anchor, recurse) {
if (recurse != null) {
return;
}
this._isOpen = true;
this._open(map, anchor, true);
};
google.maps.InfoWindow.prototype.close = function(recurse) {
if (recurse != null) {
return;
}
this._isOpen = false;
this._close(true);
};
google.maps.InfoWindow.prototype.isOpen = function(val) {
if (val == null) {
val = void 0;
}
if (val == null) {
return this._isOpen;
} else {
return this._isOpen = val;
}
};
/*
Do the same for InfoBox
TODO: Clean this up so the logic is defined once, wait until develop becomes master as this will be easier
*/
if (window.InfoBox) {
window.InfoBox.prototype._open = window.InfoBox.prototype.open;
window.InfoBox.prototype._close = window.InfoBox.prototype.close;
window.InfoBox.prototype._isOpen = false;
window.InfoBox.prototype.open = function(map, anchor) {
this._isOpen = true;
this._open(map, anchor);
};
window.InfoBox.prototype.close = function() {
this._isOpen = false;
this._close();
};
window.InfoBox.prototype.isOpen = function(val) {
if (val == null) {
val = void 0;
}
if (val == null) {
return this._isOpen;
} else {
return this._isOpen = val;
}
};
uiGmapInfoBox = (function(superClass) {
extend(uiGmapInfoBox, superClass);
function uiGmapInfoBox(opts) {
this.getOrigCloseBoxImg_ = bind(this.getOrigCloseBoxImg_, this);
this.getCloseBoxDiv_ = bind(this.getCloseBoxDiv_, this);
var box;
box = new window.InfoBox(opts);
_.extend(this, box);
if (opts.closeBoxDiv != null) {
this.closeBoxDiv_ = opts.closeBoxDiv;
}
}
uiGmapInfoBox.prototype.getCloseBoxDiv_ = function() {
return this.closeBoxDiv_;
};
uiGmapInfoBox.prototype.getCloseBoxImg_ = function() {
var div, img;
div = this.getCloseBoxDiv_();
img = this.getOrigCloseBoxImg_();
return div || img;
};
uiGmapInfoBox.prototype.getOrigCloseBoxImg_ = function() {
var img;
img = "";
if (this.closeBoxURL_ !== "") {
img = "<img";
img += " src='" + this.closeBoxURL_ + "'";
img += " align=right";
img += " style='";
img += " position: relative;";
img += " cursor: pointer;";
img += " margin: " + this.closeBoxMargin_ + ";";
img += "'>";
}
return img;
};
return uiGmapInfoBox;
})(window.InfoBox);
window.uiGmapInfoBox = uiGmapInfoBox;
}
if (window.MarkerLabel_) {
return window.MarkerLabel_.prototype.setContent = function() {
var content;
content = this.marker_.get('labelContent');
if (!content || _.isEqual(this.oldContent, content)) {
return;
}
if (typeof (content != null ? content.nodeType : void 0) === 'undefined') {
this.labelDiv_.innerHTML = content;
this.eventDiv_.innerHTML = this.labelDiv_.innerHTML;
this.oldContent = content;
} else {
this.labelDiv_.innerHTML = '';
this.labelDiv_.appendChild(content);
content = content.cloneNode(true);
this.labelDiv_.innerHTML = '';
this.eventDiv_.appendChild(content);
this.oldContent = content;
}
};
}
})
};
});
}).call(this);
;
/*global _:true, angular:true */
(function() {
angular.module('uiGmapgoogle-maps.extensions').service('uiGmapLodash', function() {
var baseGet, baseToString, fixLodash, get, reEscapeChar, rePropName, toObject, toPath;
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
reEscapeChar = /\\(\\)?/g;
/*
For Lodash 4 compatibility (some aliases are removed)
*/
fixLodash = function(arg) {
var isProto, missingName, swapName;
missingName = arg.missingName, swapName = arg.swapName, isProto = arg.isProto;
if (_[missingName] == null) {
_[missingName] = _[swapName];
if (isProto) {
return _.prototype[missingName] = _[swapName];
}
}
};
[
{
missingName: 'contains',
swapName: 'includes',
isProto: true
}, {
missingName: 'includes',
swapName: 'contains',
isProto: true
}, {
missingName: 'object',
swapName: 'zipObject'
}, {
missingName: 'zipObject',
swapName: 'object'
}, {
missingName: 'all',
swapName: 'every'
}, {
missingName: 'every',
swapName: 'all'
}, {
missingName: 'any',
swapName: 'some'
}, {
missingName: 'some',
swapName: 'any'
}, {
missingName: 'first',
swapName: 'head'
}, {
missingName: 'head',
swapName: 'first'
}
].forEach(function(toMonkeyPatch) {
return fixLodash(toMonkeyPatch);
});
if (_.get == null) {
/**
* Converts `value` to an object if it's not one.
*
* @private
* @param {*} value The value to process.
* @returns {Object} Returns the object.
*/
toObject = function(value) {
if (_.isObject(value)) {
return value;
} else {
return Object(value);
}
};
/**
* Converts `value` to a string if it's not one. An empty string is returned
* for `null` or `undefined` values.
*
* @private
* @param {*} value The value to process.
* @returns {string} Returns the string.
*/
baseToString = function(value) {
if (value === null) {
return '';
} else {
return value + '';
}
};
/**
* Converts `value` to property path array if it's not one.
*
* @private
* @param {*} value The value to process.
* @returns {Array} Returns the property path array.
*/
toPath = function(value) {
var result;
if (_.isArray(value)) {
return value;
}
result = [];
baseToString(value).replace(rePropName, function(match, number, quote, string) {
result.push(quote ? string.replace(reEscapeChar, '$1') : number || match);
});
return result;
};
/**
* The base implementation of `get` without support for string paths
* and default values.
*
* @private
* @param {Object} object The object to query.
* @param {Array} path The path of the property to get.
* @param {string} [pathKey] The key representation of path.
* @returns {*} Returns the resolved value.
*/
baseGet = function(object, path, pathKey) {
var index, length;
if (object === null) {
return;
}
if (pathKey !== void 0 && pathKey in toObject(object)) {
path = [pathKey];
}
index = 0;
length = path.length;
while (!_.isUndefined(object) && index < length) {
object = object[path[index++]];
}
if (index && index === length) {
return object;
} else {
return void 0;
}
};
/**
* Gets the property value at `path` of `object`. If the resolved value is
* `undefined` the `defaultValue` is used in its place.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.get(object, 'a[0].b.c');
* // => 3
*
* _.get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* _.get(object, 'a.b.c', 'default');
* // => 'default'
*/
get = function(object, path, defaultValue) {
var result;
result = object === null ? void 0 : baseGet(object, toPath(path), path + '');
if (result === void 0) {
return defaultValue;
} else {
return result;
}
};
_.get = get;
}
/*
Author Nick McCready
Intersection of Objects if the arrays have something in common each intersecting object will be returned
in an new array.
*/
this.intersectionObjects = function(array1, array2, comparison) {
var res;
if (comparison == null) {
comparison = void 0;
}
res = _.map(array1, function(obj1) {
return _.find(array2, function(obj2) {
if (comparison != null) {
return comparison(obj1, obj2);
} else {
return _.isEqual(obj1, obj2);
}
});
});
return _.filter(res, function(o) {
return o != null;
});
};
this.containsObject = _.includeObject = function(obj, target, comparison) {
if (comparison == null) {
comparison = void 0;
}
if (obj === null) {
return false;
}
return _.some(obj, function(value) {
if (comparison != null) {
return comparison(value, target);
} else {
return _.isEqual(value, target);
}
});
};
this.differenceObjects = function(array1, array2, comparison) {
if (comparison == null) {
comparison = void 0;
}
return _.filter(array1, (function(_this) {
return function(value) {
return !_this.containsObject(array2, value, comparison);
};
})(this));
};
this.withoutObjects = this.differenceObjects;
this.indexOfObject = function(array, item, comparison, isSorted) {
var i, length;
if (array == null) {
return -1;
}
i = 0;
length = array.length;
if (isSorted) {
if (typeof isSorted === "number") {
i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
} else {
i = _.sortedIndex(array, item);
return (array[i] === item ? i : -1);
}
}
while (i < length) {
if (comparison != null) {
if (comparison(array[i], item)) {
return i;
}
} else {
if (_.isEqual(array[i], item)) {
return i;
}
}
i++;
}
return -1;
};
this.isNullOrUndefined = function(thing) {
return _.isNull(thing || _.isUndefined(thing));
};
return this;
});
}).call(this);
;(function() {
angular.module('uiGmapgoogle-maps.extensions').factory('uiGmapString', function() {
return function(str) {
this.contains = function(value, fromIndex) {
return str.indexOf(value, fromIndex) !== -1;
};
return this;
};
});
}).call(this);
;
/*global _:true,angular:true, */
(function() {
angular.module('uiGmapgoogle-maps.directives.api.utils').service('uiGmap_sync', [
function() {
return {
fakePromise: function() {
var _cb;
_cb = void 0;
return {
then: function(cb) {
return _cb = cb;
},
resolve: function() {
return _cb.apply(void 0, arguments);
}
};
}
};
}
]).service('uiGmap_async', [
'$timeout', 'uiGmapPromise', 'uiGmapLogger', '$q', 'uiGmapDataStructures', 'uiGmapGmapUtil', function($timeout, uiGmapPromise, $log, $q, uiGmapDataStructures, uiGmapGmapUtil) {
var ExposedPromise, PromiseQueueManager, SniffedPromise, _getIterateeValue, _ignoreFields, defaultChunkSize, doChunk, doSkippPromise, each, errorObject, getArrayAndKeys, isInProgress, kickPromise, logTryCatch, managePromiseQueue, map, maybeCancelPromises, promiseStatus, promiseTypes, tryCatch;
promiseTypes = uiGmapPromise.promiseTypes;
isInProgress = uiGmapPromise.isInProgress;
promiseStatus = uiGmapPromise.promiseStatus;
ExposedPromise = uiGmapPromise.ExposedPromise;
SniffedPromise = uiGmapPromise.SniffedPromise;
kickPromise = function(sniffedPromise, cancelCb) {
var promise;
promise = sniffedPromise.promise();
promise.promiseType = sniffedPromise.promiseType;
if (promise.$$state) {
$log.debug("promiseType: " + promise.promiseType + ", state: " + (promiseStatus(promise.$$state.status)));
}
promise.cancelCb = cancelCb;
return promise;
};
doSkippPromise = function(sniffedPromise, lastPromise) {
if (sniffedPromise.promiseType === promiseTypes.create && lastPromise.promiseType !== promiseTypes["delete"] && lastPromise.promiseType !== promiseTypes.init) {
$log.debug("lastPromise.promiseType " + lastPromise.promiseType + ", newPromiseType: " + sniffedPromise.promiseType + ", SKIPPED MUST COME AFTER DELETE ONLY");
return true;
}
return false;
};
maybeCancelPromises = function(queue, sniffedPromise, lastPromise) {
var first;
if (sniffedPromise.promiseType === promiseTypes["delete"] && lastPromise.promiseType !== promiseTypes["delete"]) {
if ((lastPromise.cancelCb != null) && _.isFunction(lastPromise.cancelCb) && isInProgress(lastPromise)) {
$log.debug("promiseType: " + sniffedPromise.promiseType + ", CANCELING LAST PROMISE type: " + lastPromise.promiseType);
lastPromise.cancelCb('cancel safe');
first = queue.peek();
if ((first != null) && isInProgress(first)) {
if (first.hasOwnProperty("cancelCb") && _.isFunction(first.cancelCb)) {
$log.debug("promiseType: " + first.promiseType + ", CANCELING FIRST PROMISE type: " + first.promiseType);
return first.cancelCb('cancel safe');
} else {
return $log.warn('first promise was not cancelable');
}
}
}
}
};
/*
From a High Level:
This is a SniffedPromiseQueueManager (looking to rename) where the queue is existingPiecesObj.existingPieces.
This is a function and should not be considered a class.
So it is run to manage the state (cancel, skip, link) as needed.
Purpose:
The whole point is to check if there is existing async work going on. If so we wait on it.
arguments:
- existingPiecesObj = Queue<Promises>
- sniffedPromise = object wrapper holding a function to a pending (function) promise (promise: fnPromise)
with its intended type.
- cancelCb = callback which accepts a string, this string is intended to be returned at the end of _async.each iterator
Where the cancelCb passed msg is 'cancel safe' _async.each will drop out and fall through. Thus canceling the promise
gracefully without messing up state.
Synopsis:
- Promises have been broken down to 4 states create, update,delete (3 main) and init. (Helps boil down problems in ordering)
where (init) is special to indicate that it is one of the first or to allow a create promise to work beyond being after a delete
- Every Promise that comes in is enqueued and linked to the last promise in the queue.
- A promise can be skipped or canceled to save cycles.
Saved Cycles:
- Skipped - This will only happen if async work comes in out of order. Where a pending create promise (un-executed) comes in
after a delete promise.
- Canceled - Where an incoming promise (un-executed promise) is of type delete and the any lastPromise is not a delete type.
NOTE:
- You should not muck with existingPieces as its state is dependent on this functional loop.
- PromiseQueueManager should not be thought of as a class that has a life expectancy (it has none). It's sole
purpose is to link, skip, and kill promises. It also manages the promise queue existingPieces.
*/
PromiseQueueManager = function(existingPiecesObj, sniffedPromise, cancelCb) {
var lastPromise, newPromise;
if (!existingPiecesObj.existingPieces) {
existingPiecesObj.existingPieces = new uiGmapDataStructures.Queue();
return existingPiecesObj.existingPieces.enqueue(kickPromise(sniffedPromise, cancelCb));
} else {
lastPromise = _.last(existingPiecesObj.existingPieces._content);
if (doSkippPromise(sniffedPromise, lastPromise)) {
return;
}
maybeCancelPromises(existingPiecesObj.existingPieces, sniffedPromise, lastPromise);
newPromise = ExposedPromise(lastPromise["finally"](function() {
return kickPromise(sniffedPromise, cancelCb);
}));
newPromise.cancelCb = cancelCb;
newPromise.promiseType = sniffedPromise.promiseType;
existingPiecesObj.existingPieces.enqueue(newPromise);
return lastPromise["finally"](function() {
return existingPiecesObj.existingPieces.dequeue();
});
}
};
managePromiseQueue = function(objectToLock, promiseType, msg, cancelCb, fnPromise) {
var cancelLogger;
if (msg == null) {
msg = '';
}
cancelLogger = function(msg) {
$log.debug(msg + ": " + msg);
if ((cancelCb != null) && _.isFunction(cancelCb)) {
return cancelCb(msg);
}
};
return PromiseQueueManager(objectToLock, SniffedPromise(fnPromise, promiseType), cancelLogger);
};
defaultChunkSize = 80;
errorObject = {
value: null
};
tryCatch = function(fn, ctx, args) {
var e, error1;
try {
return fn.apply(ctx, args);
} catch (error1) {
e = error1;
errorObject.value = e;
return errorObject;
}
};
logTryCatch = function(fn, ctx, deferred, args) {
var msg, result;
result = tryCatch(fn, ctx, args);
if (result === errorObject) {
msg = "error within chunking iterator: " + errorObject.value;
$log.error(msg);
deferred.reject(msg);
}
if (result === 'cancel safe') {
return false;
}
return true;
};
_getIterateeValue = function(collection, array, index) {
var _isArray, valOrKey;
_isArray = collection === array;
valOrKey = array[index];
if (_isArray) {
return valOrKey;
}
return collection[valOrKey];
};
_ignoreFields = ['length', 'forEach', 'map'];
getArrayAndKeys = function(collection, keys, bailOutCb, cb) {
var array, propName, val;
if (angular.isArray(collection)) {
array = collection;
} else {
if (keys) {
array = keys;
} else {
array = [];
for (propName in collection) {
val = collection[propName];
if (collection.hasOwnProperty(propName) && !_.includes(_ignoreFields, propName)) {
array.push(propName);
}
}
}
}
if (cb == null) {
cb = bailOutCb;
}
if (angular.isArray(array) && !(array != null ? array.length : void 0)) {
if (cb !== bailOutCb) {
return bailOutCb();
}
}
return cb(array, keys);
};
/*
Author: Nicholas McCready & jfriend00
_async handles things asynchronous-like :), to allow the UI to be free'd to do other things
Code taken from http://stackoverflow.com/questions/10344498/best-way-to-iterate-over-an-array-without-blocking-the-ui
The design of any functionality of _async is to be like lodash/underscore and replicate it but call things
asynchronously underneath. Each should be sufficient for most things to be derived from.
Optional Asynchronous Chunking via promises.
*/
doChunk = function(collection, chunkSizeOrDontChunk, pauseMilli, chunkCb, pauseCb, overallD, index, _keys) {
return getArrayAndKeys(collection, _keys, function(array, keys) {
var cnt, i, keepGoing, val;
if (chunkSizeOrDontChunk && chunkSizeOrDontChunk < array.length) {
cnt = chunkSizeOrDontChunk;
} else {
cnt = array.length;
}
i = index;
keepGoing = true;
while (keepGoing && cnt-- && i < (array ? array.length : i + 1)) {
val = _getIterateeValue(collection, array, i);
keepGoing = angular.isFunction(val) ? true : logTryCatch(chunkCb, void 0, overallD, [val, i]);
++i;
}
if (array) {
if (keepGoing && i < array.length) {
index = i;
if (chunkSizeOrDontChunk) {
if ((pauseCb != null) && _.isFunction(pauseCb)) {
logTryCatch(pauseCb, void 0, overallD, []);
}
return $timeout(function() {
return doChunk(collection, chunkSizeOrDontChunk, pauseMilli, chunkCb, pauseCb, overallD, index, keys);
}, pauseMilli, false);
}
} else {
return overallD.resolve();
}
}
});
};
each = function(collection, chunk, chunkSizeOrDontChunk, pauseCb, index, pauseMilli, _keys) {
var error, overallD, ret;
if (chunkSizeOrDontChunk == null) {
chunkSizeOrDontChunk = defaultChunkSize;
}
if (index == null) {
index = 0;
}
if (pauseMilli == null) {
pauseMilli = 1;
}
ret = void 0;
overallD = uiGmapPromise.defer();
ret = overallD.promise;
if (!pauseMilli) {
error = 'pause (delay) must be set from _async!';
$log.error(error);
overallD.reject(error);
return ret;
}
return getArrayAndKeys(collection, _keys, function() {
overallD.resolve();
return ret;
}, function(array, keys) {
doChunk(collection, chunkSizeOrDontChunk, pauseMilli, chunk, pauseCb, overallD, index, keys);
return ret;
});
};
map = function(collection, iterator, chunkSizeOrDontChunk, pauseCb, index, pauseMilli, _keys) {
var results;
results = [];
return getArrayAndKeys(collection, _keys, function() {
return uiGmapPromise.resolve(results);
}, function(array, keys) {
return each(collection, function(o) {
return results.push(iterator(o));
}, chunkSizeOrDontChunk, pauseCb, index, pauseMilli, keys).then(function() {
return results;
});
});
};
return {
each: each,
map: map,
managePromiseQueue: managePromiseQueue,
promiseLock: managePromiseQueue,
defaultChunkSize: defaultChunkSize,
getArrayAndKeys: getArrayAndKeys,
chunkSizeFrom: function(fromSize, ret) {
if (ret == null) {
ret = void 0;
}
if (_.isNumber(fromSize)) {
ret = fromSize;
}
if (uiGmapGmapUtil.isFalse(fromSize) || fromSize === false) {
ret = false;
}
return ret;
}
};
}
]);
}).call(this);
;(function() {
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
angular.module('uiGmapgoogle-maps.directives.api.utils').factory('uiGmapBaseObject', function() {
var BaseObject, baseObjectKeywords;
baseObjectKeywords = ['extended', 'included'];
BaseObject = (function() {
function BaseObject() {}
BaseObject.extend = function(obj) {
var key, ref, value;
for (key in obj) {
value = obj[key];
if (indexOf.call(baseObjectKeywords, key) < 0) {
this[key] = value;
}
}
if ((ref = obj.extended) != null) {
ref.apply(this);
}
return this;
};
BaseObject.include = function(obj) {
var key, ref, value;
for (key in obj) {
value = obj[key];
if (indexOf.call(baseObjectKeywords, key) < 0) {
this.prototype[key] = value;
}
}
if ((ref = obj.included) != null) {
ref.apply(this);
}
return this;
};
return BaseObject;
})();
return BaseObject;
});
}).call(this);
;
/*
Useful function callbacks that should be defined at later time.
Mainly to be used for specs to verify creation / linking.
This is to lead a common design in notifying child stuff.
*/
(function() {
angular.module('uiGmapgoogle-maps.directives.api.utils').factory('uiGmapChildEvents', function() {
return {
onChildCreation: function(child) {}
};
});
}).call(this);
;(function() {
angular.module('uiGmapgoogle-maps.directives.api.utils').service('uiGmapCtrlHandle', [
'$q', function($q) {
var CtrlHandle;
return CtrlHandle = {
handle: function($scope, $element) {
$scope.$on('$destroy', function() {
return CtrlHandle.handle($scope);
});
$scope.deferred = $q.defer();
return {
getScope: function() {
return $scope;
}
};
},
mapPromise: function(scope, ctrl) {
var mapScope;
mapScope = ctrl.getScope();
mapScope.deferred.promise.then(function(map) {
return scope.map = map;
});
return mapScope.deferred.promise;
}
};
}
]);
}).call(this);
;(function() {
angular.module("uiGmapgoogle-maps.directives.api.utils").service("uiGmapEventsHelper", [
"uiGmapLogger", function($log) {
var _getEventsObj, _hasEvents;
_hasEvents = function(obj) {
return angular.isDefined(obj.events) && (obj.events != null) && angular.isObject(obj.events);
};
_getEventsObj = function(scope, model) {
if (_hasEvents(scope)) {
return scope;
}
if (_hasEvents(model)) {
return model;
}
};
return {
setEvents: function(gObject, scope, model, ignores) {