Repository navigation
Expand file tree
/
Copy pathmapv.js
More file actions
4431 lines (3740 loc) · 133 KB
/
Copy pathmapv.js
File metadata and controls
4431 lines (3740 loc) · 133 KB
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
!function(){
var Mapv;
/**
* @author nikai (@胖嘟嘟的骨头, nikai@baidu.com)
* 一些常用的方法库
*/
var util = {
isPlainObject: function isPlainObject(obj) {
var key;
var class2type = {};
var hasOwn = class2type.hasOwnProperty;
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
if (!obj || typeof obj !== 'object' || obj.nodeType) {
return false;
}
// Not own constructor property must be Object
var hasNoOwn = !hasOwn.call(obj, 'constructor');
var hasNoOwnPrototypeOf = !hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
if (obj.constructor && hasNoOwn && hasNoOwnPrototypeOf) {
return false;
}
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
for (key in obj) {}
return key === undefined || hasOwn.call(obj, key);
},
/**
* 深度扩展一个对象
*/
extend: function extend(destination, source) {
var i,
toStr = Object.prototype.toString,
astr = '[object Array]';
destination = destination || {};
for (i in source) {
if (source.hasOwnProperty(i)) {
if (util.isPlainObject(source[i])) {
destination[i] = toStr.call(source[i]) === astr ? [] : {};
util.extend(destination[i], source[i]);
destination[i] = source[i];
} else {
destination[i] = source[i];
}
}
}
return destination;
},
/**
* copy an object
* @param {Object} obj the obj
* @return {Object} new object
*/
copy: function copy(obj) {
return this.extend({}, obj);
},
/**
* 为类型构造器建立继承关系
* @name baidu.lang.inherits
* @function
* @grammar baidu.lang.inherits(subClass, superClass[, className])
* @param {Function} subClass 子类构造器
* @param {Function} superClass 父类构造器
* @remark
*
使subClass继承superClass的prototype,因此subClass的实例能够使用superClass的prototype中定义的所有属性和方法。<br>
这个函数实际上是建立了subClass和superClass的原型链集成,并对subClass进行了constructor修正。<br>
<strong>注意:如果要继承构造函数,需要在subClass里面call一下,具体见下面的demo例子</strong>
* @shortcut inherits
* @meta standard
*/
inherits: function inherits(subClass, superClass) {
var key;
var proto;
var selfProps = subClass.prototype;
var Clazz = new Function();
Clazz.prototype = superClass.prototype;
proto = subClass.prototype = new Clazz();
for (key in selfProps) {
proto[key] = selfProps[key];
}
subClass.prototype.constructor = subClass;
subClass.superClass = superClass.prototype;
},
// 在页面中添加样式
addCssByStyle: function addCssByStyle(cssString) {
var doc = document;
var style = doc.createElement('style');
style.setAttribute('type', 'text/css');
if (style.styleSheet) {
// IE
style.styleSheet.cssText = cssString;
} else {
// w3c
var cssText = doc.createTextNode(cssString);
style.appendChild(cssText);
}
var heads = doc.getElementsByTagName('head');
if (heads.length) {
heads[0].appendChild(style);
} else {
doc.documentElement.appendChild(style);
}
},
// 获取坐标的中心点
getGeoCenter: function getGeoCenter(geo) {
var minX = geo[0][0];
var minY = geo[0][1];
var maxX = geo[0][0];
var maxY = geo[0][1];
for (var i = 1; i < geo.length; i++) {
minX = Math.min(minX, geo[i][0]);
maxX = Math.max(maxX, geo[i][0]);
minY = Math.min(minY, geo[i][1]);
maxY = Math.max(maxY, geo[i][1]);
}
return [minX + (maxX - minX) / 2, minY + (maxY - minY) / 2];
}
};
/**
* @file MVC架构
*
*/
var MVCObject;
(function () {
function Accessor(target, targetKey) {
var self = this;
self.target = target;
self.targetKey = targetKey;
}
Accessor.prototype.transform = function (from, to) {
var self = this;
self.from = from;
self.to = to;
self.target.notify(self.targetKey);
return self;
};
MVCObject = (function () {
var getterNameCache = {};
var setterNameCache = {};
var uuid = 0;
var bindings = '__bindings__';
var accessors = '__accessors__';
var uid = '__uid__';
function capitalize(str) {
return str.substr(0, 1).toUpperCase() + str.substr(1);
}
function getUid(obj) {
return obj[uid] || (obj[uid] = ++uuid);
}
function toKey(key) {
return '_' + key;
}
function getGetterName(key) {
if (getterNameCache.hasOwnProperty(key)) {
return getterNameCache[key];
} else {
return getterNameCache[key] = 'get' + capitalize(key);
}
}
function getSetterName(key) {
if (setterNameCache.hasOwnProperty(key)) {
return setterNameCache[key];
} else {
return setterNameCache[key] = 'set' + capitalize(key);
}
}
/**
* @description 这个函数的触发需要时机
* 在一个key所在的终端对象遍历到时触发
* 同时传播给所有直接、间接监听targetKey的对象
* 在调用MVCObject的set方法时开始遍历
*
* @param target {MVCObject} 继承了MVCObject的对象
* @param targetKey {String} 当前对象中被监听的字段
* @return {void}
*/
function triggerChange(target, targetKey) {
var evt = targetKey + '_changed';
/**
* 优先检测并执行目标对象key对应的响应方法
* 其次检测并执行默认方法
*/
if (target[evt]) {
target[evt]();
} else if (typeof target.changed === 'function') {
target.changed(targetKey);
}
if (target[bindings] && target[bindings][targetKey]) {
var ref = target[bindings][targetKey];
var bindingObj, bindingUid;
for (bindingUid in ref) {
if (ref.hasOwnProperty(bindingUid)) {
bindingObj = ref[bindingUid];
triggerChange(bindingObj.target, bindingObj.targetKey);
}
}
}
}
function MVCObject() {};
var proto = MVCObject.prototype;
/**
* @description 从依赖链中获取对应key的值
* @param {String} key 关键值
* @return {mixed} 对应的值
*/
proto.get = function (key) {
var self = this;
if (self[accessors] && self[accessors].hasOwnProperty(key)) {
var accessor = self[accessors][key];
var targetKey = accessor.targetKey;
var target = accessor.target;
var getterName = getGetterName(targetKey);
var value;
if (target[getterName]) {
value = target[getterName]();
} else {
value = target.get(targetKey);
}
if (accessor.to) {
value = accessor.to(value);
}
} else if (self.hasOwnProperty(toKey(key))) {
value = self[toKey(key)];
}
return value;
};
/**
* @description set方法遍历依赖链直到找到key的持有对象设置key的值;
* 有三个分支
* @param {String} key 关键值
* @param {all} value 要给key设定的值,可以是所有类型
* @return {this}
*/
proto.set = function (key, value) {
var self = this;
if (self[accessors] && self[accessors].hasOwnProperty(key)) {
var accessor = self[accessors][key];
var targetKey = accessor.targetKey;
var target = accessor.target;
var setterName = getSetterName(targetKey);
if (accessor.from) {
value = accessor.from(value);
}
if (target[setterName]) {
target[setterName](value);
} else {
target.set(targetKey, value);
}
} else {
this[toKey(key)] = value;
triggerChange(self, key);
}
return self;
};
/**
* @description 没个MVCObject对象各自的响应对应的key值变化时的逻辑
*/
proto.changed = function () {};
/**
* @description 手动触发对应key的事件传播
* @param {String} key 关键值
* @return {this}
*/
proto.notify = function (key) {
var self = this;
if (self[accessors] && self[accessors].hasOwnProperty(key)) {
var accessor = self[accessors][key];
var targetKey = accessor.targetKey;
var target = accessor.target;
target.notify(targetKey);
} else {
triggerChange(self, key);
}
return self;
};
proto.setValues = function (values) {
var self = this;
var key, setterName, value;
for (key in values) {
if (values.hasOwnProperty(key)) {
value = values[key];
setterName = getSetterName(key);
if (self[setterName]) {
self[setterName](value);
} else {
self.set(key, value);
}
}
}
return self;
};
proto.setOptions = proto.setValues;
/**
* @description 将当前对象的一个key与目标对象的targetKey建立监听和广播关系
* @param key {String} 当前对象上的key
* @param target {Object} 目标对象
* @param tarrgetKey {String} 目标对象上的key
* @param noNotify {Boolean}
* @return {Accessor}
*/
proto.bindTo = function (key, target, targetKey, noNotify) {
targetKey || (targetKey = key);
var self = this;
self.unbind(key);
self[accessors] || (self[accessors] = {});
target[bindings] || (target[bindings] = {});
target[bindings][targetKey] || (target[bindings][targetKey] = {});
var binding = new Accessor(self, key);
var accessor = new Accessor(target, targetKey);
self[accessors][key] = accessor;
target[bindings][targetKey][getUid(self)] = binding;
if (!noNotify) {
triggerChange(self, key);
}
return accessor;
};
/**
* @description 解除当前对象上key与目标对象的监听
* @param {String} key 关键字
* @return {this}
*/
proto.unbind = function (key) {
var self = this;
if (self[accessors]) {
var accessor = self[accessors][key];
if (accessor) {
var target = accessor.target;
var targetKey = accessor.targetKey;
self[toKey(key)] = self.get(key);
delete target[bindings][targetKey][getUid(self)];
delete self[accessors][key];
}
}
return self;
};
proto.unbindAll = function () {
var self = this;
if (self[accessors]) {
var ref = self[accessors];
for (var key in ref) {
if (ref.hasOwnProperty(key)) {
self.unbind(key);
}
}
}
return self;
};
proto.initOptions = function (options) {
for (var key in options) {
this[getGetterName(key)] = (function (key) {
return function () {
return this.get(key);
};
})(key);
this[getSetterName(key)] = (function (key) {
return function (value) {
this.set(key, value);
};
})(key);
this[toKey(key)] = options[key];
}
};
return MVCObject;
})();
})();
Mapv.MVCObject = MVCObject;
/**
* base Class
*
*/
function Class() {
this.__listeners = {}; // 存储自定义事件对象
}
util.inherits(Class, MVCObject);
/**
* 注册对象的事件监听器
* @grammar obj.addEventListener(type, handler[, key])
* @param {string} type 自定义事件的名称
* @param {Function} handler 自定义事件被触发时应该调用的回调函数
* @remark 事件类型区分大小写。如果自定义事件名称不是以小写"on"开头,该方法会给它加上"on"再进行判断,即"click"和"onclick"会被认为是同一种事件。
*/
Class.prototype.addEventListener = function (type, handler) {
typeof this.__listeners[type] != "object" && (this.__listeners[type] = []);
this.__listeners[type].push(handler);
return this;
};
/**
* 移除对象的事件监听器。
* @grammar obj.removeEventListener(type, handler)
* @param {string} type 事件类型
* @param {Function} handler 要移除的事件监听函数
* @remark 如果第二个参数handler没有被绑定到对应的自定义事件中,什么也不做。
*/
Class.prototype.removeEventListener = function (type, handler) {
var fns = this.__listeners[type];
if (!fns) {
return false;
}
for (var i = fns.length; i >= 0; i--) {
if (fns[i] === handler) {
fns.splice(i, 1);
}
}
return this;
};
/**
* 派发自定义事件,使得绑定到自定义事件上面的函数都会被执行
* @grammar obj.dispatchEvent(event, options)
* @param {String} 事件名称
* @param {Object} options 扩展参数
*/
Class.prototype.dispatchEvent = function (type, options) {
var event = util.extend({}, options);
var fns = this.__listeners[type];
if (!fns) {
return false;
}
for (var i = fns.length - 1; i >= 0; i--) {
fns[i].call(this, event);
}
return this;
};
Class.prototype.dispose = function () {};
/**
* @file 控制值域的类
* @author nikai (@胖嘟嘟的骨头, nikai@baidu.com)
*/
function DataRange(layer) {
Class.call(this);
this.initOptions({
min: 0,
max: 0
});
this.set('layer', layer);
this.bindTo('data', layer);
this.bindTo('drawOptions', layer);
this.bindTo('drawType', layer);
var me = this;
}
util.inherits(DataRange, Class);
util.extend(DataRange.prototype, {
defaultGradient: {
'0.4': 'blue',
'0.6': 'cyan',
'0.7': 'lime',
'0.8': 'yellow',
'1.0': 'red'
},
colors: ['rgba(17, 102, 252, 0.8)', 'rgba(52, 139, 251, 0.8)', 'rgba(110, 176, 253, 0.8)', 'rgba(255, 241, 193, 0.8)', 'rgba(255, 146, 149, 0.8)', 'rgba(253, 98, 104, 0.8)', 'rgba(255, 0, 0, 0.8)', 'rgba(255, 51, 61, 0.8)'],
// 根据count值获取对应的大小,在bubble绘制中用到
getSize: function getSize(count) {
var size = 1;
var splitList = this.splitList;
for (var i = 0; i < splitList.length; i++) {
if ((splitList[i].start === undefined || splitList[i].start !== undefined && count >= splitList[i].start) && (splitList[i].end === undefined || splitList[i].end !== undefined && count < splitList[i].end)) {
size = splitList[i].size;
break;
}
}
return size;
},
// 根据count值获取对应的颜色,在choropleth中使用
getColorByRange: function getColorByRange(count) {
var color = 'rgba(50, 50, 255, 1)';
var splitList = this.splitList;
for (var i = 0; i < splitList.length; i++) {
if ((splitList[i].start === undefined || splitList[i].start !== undefined && count >= splitList[i].start) && (splitList[i].end === undefined || splitList[i].end !== undefined && count < splitList[i].end)) {
color = splitList[i].color;
break;
}
}
return color;
},
data_changed: function data_changed() {
var data = this.get('data');
if (data && data.length > 0) {
this._min = data[0].count;
this._max = data[0].count;
for (var i = 0; i < data.length; i++) {
this._max = Math.max(this._max, data[i].count);
this._min = Math.min(this._min, data[i].count);
}
}
},
drawType_changed: function drawType_changed() {
this.update();
},
drawOptions_changed: function drawOptions_changed() {
this.update();
},
update: function update() {
var drawOptions = this.get("drawOptions");
if (drawOptions && drawOptions.splitList) {
this.splitList = drawOptions.splitList;
} else {
this.generalSplitList();
}
if (this.get("layer").getDrawType() === 'category') {
if (drawOptions && drawOptions.splitList) {
this.categorySplitList = drawOptions.splitList;
} else {
this.generalCategorySplitList();
}
}
if (this.get("layer").getDrawType() === 'heatmap' || this.get("layer").getDrawType() === 'density' || this.get("layer").getDrawType() === 'intensity') {
this.generalGradient(drawOptions.gradient || this.defaultGradient);
}
this.draw();
},
draw: function draw() {
if (this.get("layer").getDataRangeControl()) {
this.get("layer").dataRangeControl.show();
}
if (this.get("layer").getDrawType() === 'bubble') {
this.get("layer").dataRangeControl.drawSizeSplit(this.splitList, this.get('drawOptions'));
} else if (this.get("layer").getDrawType() === 'category') {
// this.get("layer").dataRangeControl.drawCategorySplit(this.categorySplitList, this.get('drawOptions'));
} else if (this.get("layer").getDrawType() === 'choropleth') {
this.get("layer").dataRangeControl.drawChoroplethSplit(this.splitList, this.get('drawOptions'));
} else {
this.get("layer").dataRangeControl.hide();
}
},
generalSplitList: function generalSplitList() {
var splitNum = Math.ceil((this._max - this._min) / 7);
var index = this._min;
this.splitList = [];
var radius = 1;
while (index < this._max) {
this.splitList.push({
start: index,
end: index + splitNum,
size: radius,
color: this.colors[radius - 1]
});
index += splitNum;
radius++;
}
},
generalCategorySplitList: function generalCategorySplitList() {
var colors = ['rgba(255, 255, 0, 0.8)', 'rgba(253, 98, 104, 0.8)', 'rgba(255, 146, 149, 0.8)', 'rgba(255, 241, 193, 0.8)', 'rgba(110, 176, 253, 0.8)', 'rgba(52, 139, 251, 0.8)', 'rgba(17, 102, 252, 0.8)'];
var data = this.get("data");
this.categorySplitList = {};
var count = 0;
for (var i = 0; i < data.length; i++) {
if (this.categorySplitList[data[i].count] === undefined) {
this.categorySplitList[data[i].count] = colors[count];
count++;
}
if (count >= colors.length - 1) {
break;
}
}
this.categorySplitList['other'] = colors[colors.length - 1];
},
getCategoryColor: function getCategoryColor(count) {
var splitList = this.categorySplitList;
var color = splitList['other'];
for (var i in splitList) {
if (count == i) {
color = splitList[i];
break;
}
}
return color;
},
generalGradient: function generalGradient(grad) {
// create a 256x1 gradient that we'll use to turn a grayscale heatmap into a colored one
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var gradient = ctx.createLinearGradient(0, 0, 0, 256);
canvas.width = 1;
canvas.height = 256;
for (var i in grad) {
gradient.addColorStop(i, grad[i]);
}
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 1, 256);
this._grad = ctx.getImageData(0, 0, 1, 256).data;
},
getGradient: function getGradient() {
return this._grad;
},
getColorByGradient: function getColorByGradient(count) {
var max = this.get("max") || 10;
var index = count / max;
if (index > 1) {
index = 1;
}
index *= 255;
index = parseInt(index, 10);
index *= 4;
var color = 'rgba(' + this._grad[index] + ', ' + this._grad[index + 1] + ', ' + this._grad[index + 2] + ',' + this._grad[index + 3] + ')';
return color;
}
}); // end extend
/**
* @file Animation.js
*/
function Animation(opts) {
var defaultOptions = {
duration: 1000, // 动画时长, 单位毫秒
fps: 30, // 每秒帧数
delay: 0, // 延迟执行时间,单位毫秒,如果delay为infinite则表示手动执行
transition: Transitions.linear,
onStop: function onStop() {} // 调用stop停止时的回调函数
};
// 需要后续执行动画
this._anis = [];
if (opts) {
for (var i in opts) {
defaultOptions[i] = opts[i];
}
}
this._opts = defaultOptions;
if (isNumber(defaultOptions.delay)) {
var me = this;
setTimeout(function () {
me.start();
}, defaultOptions.delay);
} else if (defaultOptions.delay != Animation.INFINITE) {
this.start();
}
}
/**
* 常量,表示动画无限循环
*/
Animation.INFINITE = "INFINITE";
/**
* 启动动画方法
*/
Animation.prototype.start = function () {
this._beginTime = getCurrentTime();
this._endTime = this._beginTime + this._opts.duration;
this._launch();
};
Animation.prototype.add = function (ani) {
this._anis.push(ani);
};
Animation.prototype._launch = function () {
var me = this;
var now = getCurrentTime();
if (now >= me._endTime) {
if (me._opts.render) me._opts.render(me._opts.transition(1));
// finish()接口,时间线结束时对应的操作
if (me._opts.finish) me._opts.finish();
// 开始后续动画
if (me._anis.length > 0) {
var newAni = me._anis[0];
newAni._anis = [].concat(me._anis.slice(1));
newAni.start();
}
return;
}
me.schedule = me._opts.transition((now - me._beginTime) / me._opts.duration);
// render()接口,用来实现每个脉冲所要实现的效果
if (me._opts.render) me._opts.render(me.schedule);
// 执行下一个动作
if (!me.terminative) {
me._timer = setTimeout(function () {
me._launch();
}, 1000 / me._opts.fps);
}
};
/**
* 停止当前动画
* @type {Boolean 是否停止到动画的终止时刻}
*/
Animation.prototype.stop = function (gotoEnd) {
this.terminative = true;
for (var i = 0; i < this._anis.length; i++) {
this._anis[i].stop();
this._anis[i] = null;
}
this._anis.length = 0;
if (this._timer) {
clearTimeout(this._timer);
this._timer = null;
}
this._opts.onStop(this.schedule);
if (gotoEnd) {
this._endTime = this._beginTime;
this._launch();
}
};
/**
* 取消动画
*/
Animation.prototype.cancel = function () {
if (this._timer) clearTimeout(this._timer);
this._endTime = this._beginTime;
this.schedule = 0;
};
/**
* 设置动画结束后的回调函数
* @param Function
*/
Animation.prototype.setFinishCallback = function (callback) {
if (this._anis.length > 0) {
this._anis[this._anis.length - 1]._opts.finish = callback;
} else {
this._opts.finish = callback;
}
};
/**
* 变换效果函数库
*/
var Transitions = {
linear: function linear(t) {
return t;
},
reverse: function reverse(t) {
return 1 - t;
},
easeInQuad: function easeInQuad(t) {
return t * t;
},
easeInCubic: function easeInCubic(t) {
return Math.pow(t, 3);
},
easeOutQuad: function easeOutQuad(t) {
return -(t * (t - 2));
},
easeOutCubic: function easeOutCubic(t) {
return Math.pow(t - 1, 3) + 1;
},
easeInOutQuad: function easeInOutQuad(t) {
if (t < 0.5) {
return t * t * 2;
} else {
return -2 * (t - 2) * t - 1;
}
return;
},
easeInOutCubic: function easeInOutCubic(t) {
if (t < 0.5) {
return Math.pow(t, 3) * 4;
} else {
return Math.pow(t - 1, 3) * 4 + 1;
}
},
easeInOutSine: function easeInOutSine(t) {
return (1 - Math.cos(Math.PI * t)) / 2;
}
};
Transitions['ease-in'] = Transitions.easeInQuad;
Transitions['ease-out'] = Transitions.easeOutQuad;
/**
* 获取当前时间
* @returns {String} 当前时间
*/
function getCurrentTime() {
return new Date().getTime();
}
/**
* 是否是数字
* @param {Mix}
* @returns {Boolean}
*/
function isNumber(number) {
return typeof number == "number";
}
/**
* @file 控制大小值域的类
* @author nikai (@胖嘟嘟的骨头, nikai@baidu.com)
*/
function SizeDataRange() {
DataRange.call(this);
}
util.inherits(SizeDataRange, DataRange);
util.extend(SizeDataRange.prototype, {}); // end extend
/**
* TimeLine Component
*/
function TimeLine(options) {
Class.call(this);
}
util.inherits(TimeLine, Class);
util.extend(TimeLine.prototype, {});
var timeLine = new TimeLine({});
/**
* @author nikai (@胖嘟嘟的骨头, nikai@baidu.com)
* 地图可视化库,目前依赖与百度地图api,在百度地图api上展示点数据
*
*/
/**
* Mapv主类
* @param {Object}
*/
function Mapv(options) {
Class.call(this);
this.initOptions($.extend({
map: null, //地图参数
drawTypeControl: false,
drawTypeControlOptions: {
a: 1
}
}, options));
this._layers = [];
//this._initDrawScale();
this.notify('drawTypeControl');
}
util.inherits(Mapv, Class);
Mapv.prototype._initDrawScale = function () {
this.Scale = new DrawScale();
};
Mapv.prototype.drawTypeControl_changed = function () {
if (this.getDrawTypeControl()) {
if (!this.drawTypeControl) {
this.drawTypeControl = new DrawTypeControl({
mapv: this
});
}
this.getMap().addControl(this.drawTypeControl);
} else {
if (this.drawTypeControl) {
this.getMap().removeControl(this.drawTypeControl);
}
}
};
/**
*
*/
goog.provide('ol.MyOverlay');
goog.require('goog.asserts');
goog.require('goog.events');
goog.require('goog.math');
goog.require('goog.object');
goog.require('ol.Object');
goog.require('ol.dom');
goog.require('ol.Overlay');
goog.require('ol.render.EventType');
goog.require('ol.style.Icon');
goog.require('ol.style.Style');
ol.MyOverlay=function(opt_options){
var options = opt_options ? opt_options : {};
var baseOptions = goog.object.clone(options);
goog.base(this,baseOptions);
// goog.base(this, {
// handleDownEvent: ol.interaction.DragPan.handleDownEvent_,
// handleDragEvent: ol.interaction.DragPan.handleDragEvent_,
// handleUpEvent: ol.interaction.DragPan.handleUpEvent_
// });
}
goog.inherits(ol.MyOverlay,ol.Overlay);
/**
* 一直覆盖在当前地图视野的Canvas对象
*
* @author nikai (@胖嘟嘟的骨头, nikai@baidu.com)
*
* @param
* {
* map 地图实例对象
* }
*/
function CanvasLayer(options) {
this.options = options || {};
this.paneName = this.options.paneName || 'labelPane';
this.zIndex = this.options.zIndex || 0;
this.obj = this;
this._map = options.map;
this.contextType = options.canvasType;