-
Notifications
You must be signed in to change notification settings - Fork 33
/
g2b.o.js
1992 lines (1906 loc) · 49 KB
/
g2b.o.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
/**
* This is a un-pre-processed javascript file mixed with c/cpp macro
* run "cpp -P -C g2b.o.js>g2b.cpp.js" to pre-process
* or "cl /EP g2b.o.js>g2b.cpp.js
*/
//#include "g2b.h"
(function(_G,CFG){
if(_G.___G2B___)return;
//if not silence many exception/error will be threw
CFG = CFG || {silence:true};
//#ifndef __INLINE_IMPL_TO_TERNARY__
var _ = function(o){return o._impl ? o._impl : o;};
//#endif
//#ifdef __GOOGLE__
var TO_BLNG = function(lng){return lng+0.0065;};
var TO_BLAT = function(lat){return lat+0.0060;};
var TO_GLNG = function(lng){return lng-0.0065;};
var TO_GLAT = function(lat){return lat-0.0060;};
//#endif
var INTERNAL = function(x) {return "_"+x+"_";};
//globals
var DEBUG = false,EMPTY_FN = function(){};
_gprivate = {maps:[],activeMap:null,version:0.1};
_G.___G2B___ = _gprivate;
//properties updating
_gprivate.objs = [];
_gprivate.updateProperties = function(){
for(var i = 0;i<_gprivate.objs.length;++i){
_gprivate.objs[i]();
}
};
//var _updateTimer = _G.setInterval(_gprivate.update,1000);
//_gprivate.stopUpdate = function(){
// if(_updateTimer)clearInterval(_updateTimer);
//};
function _registerUpdater(callback){
if(callback && typeof(callback)==="function"){
_gprivate.objs.push(callback);
}
}
if(typeof(T)=="undefined"){
var t = document.createElement("script");
t.type = "text/javascript";
t.src = "http://img.baidu.com/js/tangram-base-core-1.3.7.js";
document.getElementsByTagName("head")[0].appendChild(t);
}
function log(message){
if(DEBUG && _G.console && _G.console.log){
_G.console.log(message);
}
}
var _$ = DEBUG ? log : EMPTY_FN;
/**
* declare a 'constant' in scope
*/
function Const(name,v,scope){
(scope || _G)[name] = v;
}
/**
* A Wrapper writing helper
* simplify wrapper writing, save some meta data
* for future use
*/
function Klass(name,value,father,inherit){
if(father && father.length>0){
if(father.splice){
father = father[0];
}
//base class of current class
Klass.f = father;
}
if(typeof(value)=="function"){
var fun = value.toString();
//we want the ctor has a function name not anonymouse
//_G.eval(fun.replace(/^function/,"function "+name));
//_G[name] = eval(name);
//exports to global namespace
_G[name] = value;
//current defining class
Klass.c = eval(name);
}else{
_G[name] = value;
Klass.c = value;
}
//name of current class
Klass.c.__name__ = name;
if(inherit){
Klass.c.prototype = new Klass.f();
}
_$("<class name='"+name+"'>");
return Klass;
}
var Interface = Klass;
function Typedef(name,type,scope){
var t = (scope || _G)[name] = type;
return t;
}
/**
* add addEventListener/removeEventListener to class
*/
Klass.dispatcher = function(){
_$(" <method name='addEventListener' />");
_$(" <method name='removeEventListener' />");
var that = Klass.c;
that.prototype.addEventListener = function(){
this._impl.addEventListener.apply(this._impl,arguments);
};
that.prototype.removeEventListener = function(){
this._impl.removeEventListener.apply(this._impl,arguments);
};
return Klass;
};
/**
* add a empty method
*/
Klass.dummy = function(){
for(var i = 0; i < arguments.length; ++i){
var f = arguments[i];
_$(" <method type='dummy' name='"+f+"' />");
Klass.c.prototype[f] = EMPTY_FN;
}
return Klass;
};
/**
* if wrapper class's method has the same name and signature and semantics with
* _impl then you can generate a proxy function by calling Klass(..).same("fun")
*/
Klass.same = function(){
for(var i = 0; i < arguments.length; ++i){
var f = arguments[i];
_$(" <method type='same' name='"+f+"' />");
(function(f){
Klass.c.prototype[f] = function(){
return this._impl[f].apply(this._impl,arguments);
};
})(f);
}
return Klass;
};
/**
* method a is an alias of method b
*/
Klass.alias = function(a,b){
Klass.c.prototype[a] = Klass.c.prototype[b];
return Klass;
};
/**
* implements an method which exits in _impl
*/
Klass.reimpl = function(name,fn){
_$(" <method type='reimp' name='"+name+"' />");
if(Klass.c.prototype[name]){
Klass.c.prototype[INTERNAL(name)] = Klass.c.prototype[name];
}
Klass.c.prototype[name] = fn;
return Klass;
};
/**
* implements an method which does not exits in _impl
*/
Klass.impl = function(name,fn){
_$(" <method type='impl' name='"+name+"' />");
Klass.c.prototype[name] = fn;
return Klass;
};
Klass.override = Klass.impl;
/**
* not supported features
*/
Klass.noimpl = function(){
for(var i = 0;i<arguments.length; ++i){
var f = arguments[i];
if(Klass.c.prototype[f]){
log("! "+f+" has already been defined !");
continue;
}
_$(" <method type='noimpl' name='"+f+"' />");
(function(f){
Klass.c.prototype[f] = function(){
if(!CFG.silence)
throw Error(f+" is not implemented!");
};
})(f);
}
return Klass;
};
/**
* methods of interface
*/
Klass.virtual = Klass.noimpl;
/**
* static method
*/
Klass.statik = function(name,v){
_$(" <method type='static' name='"+name+"' />");
if(Klass.c[name]){
Klass.c[INTERNAL(name)] = Klass.c[name];
}
Klass.c[name] = v;
return Klass;
};
/**
* class constants
*/
Klass.konst = Klass.statik;
function $tryget(o,path,v){
if(typeof(o)==="undefined")return v;
var props = path.split(".");
if(props.length===0)return v;
for(var t = o,i = 0;i<props.length;++i){
t = t[props[i]];
if(typeof(t)==="undefined")return v;
}
return t;
}
/**
* attribute accessor
*/
Klass.attr_reader = function(name,path){
Klass.prototype[name] = function(){
return $tryget(this,path);
};
return Klass;
};
/**
* end of a class delcareation
*/
Klass.end = function(){
_$("</class>");
};
/**
* event dispatcher for internal use
*/
Klass("_IDispatcher",function(){
this.subscribers = {};
})
.impl("addEventListener",function(event,callback){
var subs = this.subscribers;
if(!subs[event]){
subs[event] = [];
}
subs.push(callback);
return callback;
})
.impl("removeEventListener",function(event,callback){
if(!this.subscribers[event])return false;
var subs = this.subscribers[event];
for(var i in subs){
var c = subs[i];
if(c!==callback)continue;
subs.splice(i,1);
return true;
}
return false;
})
.impl("dispatch",function(event,e){
if(!this.subscribers[event])return;
var subs = this.subscribers[event];
for(var i in subs){
var c = subs[i];
if(typeof(c)!="function")continue;
c(e);
}
})
.end();
GLog = {write:log,writeUrl:log,writeHtml:log};
//global constants
Const("G_API_VERSION", "340c");
Const("G_ANCHOR_TOP_LEFT", BMAP_ANCHOR_TOP_LEFT);
Const("G_ANCHOR_TOP_RIGHT", BMAP_ANCHOR_TOP_RIGHT);
Const("G_ANCHOR_BOTTOM_LEFT", BMAP_ANCHOR_BOTTOM_LEFT);
Const("G_ANCHOR_BOTTOM_RIGHT", BMAP_ANCHOR_BOTTOM_RIGHT);
//TODO! G_*_MAP不是数值常量,而是对象
Const("G_NORMAL_MAP",BMAP_NORMAL_MAP);
Const("G_SATELLITE_MAP",BMAP_NORMAL_MAP);
Const("G_AERIAL_MAP",BMAP_NORMAL_MAP);
Const("G_HYBRID_MAP",BMAP_NORMAL_MAP);
Const("G_AERIAL_HYBRID_MAP",BMAP_NORMAL_MAP);
Const("G_PHYSICAL_MAP",BMAP_NORMAL_MAP);
Const("G_MAPMAKER_NORMAL_MAP",BMAP_NORMAL_MAP);
Const("G_MAPMAKER_HYBRID_MAP",BMAP_NORMAL_MAP);
//GGeoStatusCode
Const("G_GEO_SUCCESS",200);
Const("G_GEO_BAD_REQUEST",400);
Const("G_GEO_SERVER_ERROR",500);
Const("G_GEO_MISSING_QUERY",601);
Const("G_GEO_MISSING_ADDRESS",601);
Const("G_GEO_UNKNOWN_ADDRESS",602);
Const("G_GEO_UNAVAILABLE_ADDRESS",603);
Const("G_GEO_UNKNOWN_DIRECTIONS",604);
Const("G_GEO_BAD_KEY",610);
Const("G_GEO_TOO_MANY_QUERIES",620);
Const("G_MAP_MAP_PANE","mapPane");
Const("G_MAP_OVERLAY_LAYER_PANE","mapPane");
Const("G_MAP_MARKER_SHADOW_PANE","markerPane");
Const("G_MAP_MARKER_PANE","markerPane");
Const("G_MAP_FLOAT_SHADOW_PANE","floatShadow");
Const("G_MAP_MARKER_MOUSE_TARGET_PANE","markerMouseTarget");
Const("G_MAP_FLOAT_PANE","floatPane");
//global function
GBrowserIsCompatible = function(){
return true;
};
GUnload = EMPTY_FN;
//basic class
/**
* GLatLng
*/
Klass("GLatLng",function(lat,lng,unbounded){
//TODO unbounded?see google api doc
//lat,lng may be a string
if(typeof(lng)==="string"){
lng = parseFloat(lng);
}
if(typeof(lat)==="string"){
lat = parseFloat(lat);
}
this._impl = new BMap.Point(TO_BLNG(lng),TO_BLAT(lat));
},[
BMap.Point
])
.reimpl("equals",function(o){
return this._impl.equals(_(o));
})
.impl("lat",function(){
return TO_GLAT(this._impl.lat);
})
.impl("lng",function(){
return TO_GLNG(this._impl.lng);
})
.impl("latRadians",function(){
//TODO
})
.impl("lngRadians",function(){
//TODO
})
.impl("distancFrom",function(other,radius){
//TODO
})
.impl("toUrlValue",function(precision){
//TODO
})
.statik("fromUrlValue",function(latlng){
var v = latlng.split(",");
return new GLatLng(Number(v[0]),Number(v[1]));
})
.same("toString")
.end();
/**
* GLatLngBounds
*/
Klass("GLatLngBounds",function(sw,ne){
var swlng = sw ? TO_BLNG(sw.lng()) : 0,
swlat = sw ? TO_BLAT(sw.lat()) : 0,
nelng = ne ? TO_BLNG(ne.lng()) : 0,
nelat = ne ? TO_BLAT(ne.lat()) : 0;
var _sw = new BMap.Point(swlng,swlat),
_ne = new BMap.Point(nelng,nelat);
this._impl = new BMap.Bounds(_sw,_ne);
},[
BMap.Bounds
])
.reimpl("equals",function(o){
return this._impl.equals(_(o));
})
.reimpl("getSouthWest",function(){
var p = this._impl.getSouthWest();
return new GLatLng(TO_GLAT(p.lat),TO_GLNG(p.lng));
})
.reimpl("getNorthEast",function(){
var p = this._impl.getNorthEast();
return new GLatLng(TO_GLAT(p.lat),TO_GLNG(p.lng));
})
.reimpl("getCenter",function(){
var p = this._impl.getCenter();
return new GLatLng(TO_GLAT(p.lat),TO_GLNG(p.lng));
})
.impl("containsLatLng",function(latlng){
return this._impl.containsPoint(_(latlng));
})
.reimpl("containsBounds",function(b){
return this._impl.containsBounds(_(b));
})
.reimpl("extend",function(latlng){
this._impl.extend(_(latlng));
})
.reimpl("intersects",function(other){
return this._impl.intersects(_(other));
})
.reimpl("toSpan",function(){
var p = this._impl.toSpan();
return new GLatLng(TO_GLAT(p.lat),TO_GLNG(p.lng));
})
.noimpl("isFullLat","isFullLng")
.same("isEmpty")
.end();
/**
* GPoint
*/
Klass("GPoint",function(x,y){
this._impl = new BMap.Pixel(x,y);
this.x = this._impl.x;
this.y = this._impl.y;
//sync property?
},[
BMap.Pixel
])
.reimpl("equals",function(other){
return this._impl.equal(_(other));
})
.impl("toString",function(){//??
return "("+this._impl.x + "," + this._impl.y+")";
})
.konst("ORIGIN",new GPoint(0,0))
.impl()
.end();
/**
* GBounds is a rectangular area of the map in pixel coordinates
*/
//TEST
Klass("GBounds",function(points){
//NOTICE: max is negtive and min is positive
// and this make max<min
this.minX = this.minY = Number.MAX_VALUE;
this.maxX = this.maxY = -Number.MAX_VALUE;
var a = arguments;
if(a.length>=4){
this.minX = a[0];
this.minY = a[1];
this.maxX = a[2];
this.maxY = a[3];
}else if(a.length){
for(var i = 0;i<arguments.length;++i){
this.extend(arguments[i]);
}
}
},[
//BMap.Size
])
.impl("equals",function(o){
return this.minX == a.minX
&& this.minY == a.minY
&& this.maxX == a.maxX
&& this.maxY == a.maxY;
})
.impl("copy",function(){
return new GBounds(this.minX,this.minY,this.maxX,this.maxY);
})
.impl("mid",function(){
return new GPoint((this.minX+this.maxX)/2,(this.minY+this.maxY)/2);
})
.impl("min",function(){
return new GPoint(this.minX,this.minY);
})
.impl("max",function(){
return new GPoint(this.maxX,this.maxY);
})
.impl("extend",function(p){
})
.impl("containsBounds",function(other){
return this.minX <= a.minX && this.maxX >= a.maxX && this.minY <= a.minY && this.maxY >= a.maxY;
})
.impl("containsPoint",function(p){
return this.minX <= a.x && this.maxX >= a.x && this.minY <= a.y && this.maxY >= a.y;
})
.impl("empty",function(){
return this.minX > this.maxX || this.minY > this.maxY;
})
.impl("extend",function(p){
if(this.empty()){
this.minX = this.maxX = p.x;
this.minY = this.maxY = p.h;
}else{
this.minX = Math.min(this.minX,p.x);
this.maxX = Math.max(this.maxX,p.x);
this.minY = Math.min(this.minX,p.y);
this.maxY = Math.max(this.maxY,p.y);
}
})
.impl("toString",function(){
return "(" + this.min() + ", " + this.max() + ")";
})
.end();
/**
* GSize
*/
Typedef("GSize",BMap.Size).ZERO = new GSize(0,0);
/**
* GMarker
*/
Klass("GMarker",function(latlng,opt){
opt = opt || {};
options = baidu.object.clone(opt);
if(options.draggable)options.enableDragging = true;
if(opt.icon){
options["icon"] = _(opt.icon) ||new BMap.Icon(opt.icon.image,opt.icon.size);
}
this._impl = new BMap.Marker(_(latlng),options);
if(typeof(opt.zIndexProcess)==="function"){
var zIndex = opt.zIndexProcess();
if(!isNaN(zIndex)){
this._impl.setZIndex(zIndex);
}
}
},[
BMap.Marker
])
.dispatcher()
.reimpl("openInfoWindow",function(value,opt){
var infoWindow;
if(typeof(value)=="string"){
infoWindow = new BMap.InfoWindow(value);
}else{
//TODO! value is a DOM node
var t = GXml.value(value);
infoWindow = new BMap.InfoWindow(t);
}
this._impl.openInfoWindow(infoWindow,opt);
})
.impl("getLatLng",function(){
var p = this._impl.getPosition();
return new GLatLng(TO_GLAT(p.lat),TO_GLNG(p.lng));
})
.impl("setLatLng",function(latlng){
this._impl.setPosition(_(latlng));
})
.impl("isHidden",function(){
return !this._impl.isVisible();
})
.alias("openInfoWindowHtml","openInfoWindow")
.same("show","hide","closeInfoWindow","toString")
.end();
/**
* GMapType
*/
Klass("GMapType",function(layers,projection,name,opts){
if(!opts.impl){
throw Error("Sorry,you can not create GMapType");
}
this._impl = opts.impl;
})
.impl("getMinimumResolution",function(){
return this._impl.zoomLevelMin || this._impl.getMinZoom();
})
.impl("getMaximumResolution",function(){
return this._impl.zoomLevelMax || this._impl.getMaxZoom();
})
.impl("getTileSize",function(){
return this._impl.tileSize || this._impl.getTileSize();
})
.noimpl(
"getSpanZoomLevel","getBoundsZoomLevel","getName","getTileLayers",
"getMaxZoomAtLatLng","getTextColor","getLinkColor","getErrorMessage",
"getCopyrights","getAlt","getHeading"
)
.end();
/**
* GMap2
*/
//百度地图的一些API需要提供当前城市
//但是Google的不需要。这里保存下所有创建的map实例
//最好的情况是就一个实例,此时map._city就是当前城市
//如果有多余一个实例,还要想一个策略设置activeCity
Klass("GMap2",function(e,opt){
this._impl = new BMap.Map(e,opt);
this._config = {enableInfoWindow:true};
_gprivate.maps.push(this);
_gprivate.activeMap = this;
},[
BMap.Map
])
.dispatcher()
.impl("setCenter",function(center,zoom,type){
//zoom should not be undefined or zero!
if(!zoom){
zoom = this._impl.getZoom();
}
this._impl.centerAndZoom(_(center),zoom);
//尝试得到当前地图所在显示的城市
this._trySetCurrentCity();
})
.reimpl("getCenter",function(){
var p = this._impl.getCenter();
return new GLatLng(TO_GLAT(p.lat),TO_GLNG(p.lng));
})
.reimpl("openInfoWindow",function(latlng,value,opt){
//TODO get html from dom node
if(!this._config.enableInfoWindow)return;
var w = new BMap.InfoWindow(value.nodeValue);
this._impl.openInfoWindow(w,_(latlng));
})
.impl("openInfoWindowHtml",function(latlng,html,opt){
if(!this._config.enableInfoWindow)return;
var w = new BMap.InfoWindow(html);
this._impl.openInfoWindow(w,_(latlng));
})
.impl("setUIToDefault",function(){
this._impl.addControl(new BMap.NavigationControl());
})
.reimpl("getBounds",function(){
var b = this._impl.getBounds();
var sw = b.getSouthWest(),ne = b.getNorthEast();
return new GLatLngBounds(
new GLatLng(TO_GLAT(sw.lat),TO_GLNG(sw.lng)),
new GLatLng(TO_GLAT(ne.lat),TO_GLNG(ne.lng))
);
})
.reimpl("addOverlay",function(o){
if(!o)return;
o._initialize && o._initialize(this);
if(o._impl || o instanceof BMap.Overlay){
//builtin overlays
this._impl.addOverlay(_(o));
}else{
if(o.redraw && !o.draw){
//Overlay Manager will call 'draw'
//when map load/zoomed etc
o.draw = o.redraw;
}
//custom overlays
o.domElement = o.initialize(this);
o.draw(true);
var forceRedraw = function(){o.draw(true);};
this._impl.addEventListener("moveend",forceRedraw);
this._impl.addEventListener("zoomend",forceRedraw);
this._impl.addEventListener("dragend",forceRedraw);
if(!o._map){
o._gmap = this;
o._map = this._impl;
}
}
})
.reimpl("removeOverlay",function(o){
this._impl.removeOverlay(_(o));
})
.reimpl("addControl",function(c,pos){
var ctrl = c;
if(c._impl)ctrl = c._impl;
pos = pos || {_offset:new BMap.Size(0,0)};
ctrl.setOffset(pos._offset);
if(pos._impl)ctrl.setAnchor(_(pos));
this._impl.addControl(ctrl);
})
.reimpl("removeControl",function(c){
this._impl.removeControl(_(c));
})
.reimpl("setMapType",function(type){
if(type!=BMAP_NORMAL_MAP && type!=BMAP_PERSPECTIVE_MAP){
throw Error("map type "+type+" is not supported!");
}
this._impl.setMapType(type);
})
.impl("getCurrentMapType",function(){
var impl = null,mt = null;
if(typeof(BMap.MapType)==="function"){
//1.2
impl = this._impl.getMapType();
}else{
//1.1
impl = BMap.MapType[this._impl.getMapType()];
}
mt = new GMapType(null,null,null,{impl:impl});
return mt;
})
.impl("getMapTypes",function(){
return [this.getCurrentMapType()];
})
.impl("_trySetCurrentCity",function(callback){
var geo = new BMap.Geocoder(),m = this._impl,that = this;
geo.getLocation(m.getCenter(),function(result){
/*
if(result===null){
throw Error("Can not get current city!");
}
*/
if(result===null){
if(typeof(callback)=="function")callback(m,null);
return;
}
that._city = result.addressComponents.city;
m.setCurrentCity(that._city);
if(typeof(callback)=="function")callback(m,that._city);
});
})
.impl("setUI",function(opt){
var m = this._impl;
// Get current city from map.getCenter();
var geo = new BMap.Geocoder();
geo.getLocation(m.getCenter(),function(result){
if(result===null){
throw Error("Can not get current city!");
}
m._city = result.addressComponents.city;
m.setCurrentCity(m._city);
});
if(!opt)return;
if(opt.maptypes){
m.setMapType(opt.maptypes.normal ? BMAP_NORMAL_MAP : BMAP_PERSPECTIVE_MAP);
}
opt.keyboard ? m.enableKeyboard() : m.disableKeyboard();
if(opt.zoom){
opt.zoom.scrollwheel ? m.enableScrollWheelZoom() : m.disableScrollWheelZoom();
opt.zoom.doubleclick ? m.enableDoubleClickZoom() : m.disableDoubleClickZoom();
}
if(opt.controls){
for(var c in opt.controls){
if(!opt.controls[c])continue;
var meta = GControl._builtins[c];
if(!meta)continue;
m.addControl(new meta.klass(meta.param));
}
}
})
.impl("getDefaultUI",function(){
var opt = new GMapUIOptions(),m = this._impl;
opt.maptypes.normal = m.config.mapType == BMAP_NORMAL_MAP;
opt.keyboard = m.config.enableKeyboard;
opt.zoom.scrollwheel = m.config.enableWheelZoom;
opt.zoom.doubleclick = m.config.enableDblclickZoom;
//has navigation control by default
opt.controls._navigationcontrol = true;
return opt;
})
.reimpl("panTo",function(latlng){
this._impl.panTo(_(latlng));
})
.impl("panBy",function(size){
this._impl.panBy(size.width,size.height);
})
.impl("panDirection",function(dx,dy){
var s = this._impl.getSize();
this._impl.panBy(dx*(s.width/2),dy*(s.height/2));
})
.impl("getPane",function(pane){
var div = this._impl.getPanes()[pane];
return div;
})
.impl("fromLatLngToContainerPixel",function(latlng){
var pixel = this._impl.pointToPixel(_(latlng));
return new GPoint(pixel.x,pixel.y);
})
.impl("fromContainerPixelToLatLng",function(pixel){
var latlng = this._impl.pixelToPoint(_(pixel));
return new GLatLng(TO_GLAT(latlng.lat),TO_GLNG(latlng.lng));
})
.impl("fromLatLngToDivPixel",function(latlng){
var pixel = this._impl.pointToOverlayPixel(_(latlng));
return new GPoint(pixel.x,pixel.y);
})
.impl("fromDivPixelToLatLng",function(pixel){
var latlng = this._impl.overlayPixelToPoint(_(pixel));
return new GLatLng(TO_GLAT(latlng.lat),TO_GLNG(latlng.lng));
})
.reimpl("getZoom",function(){
return this._impl.getZoom();
})
.reimpl("setZoom",function(zoom){
this._impl.setZoom ? this._impl.setZoom(zoom) : this._impl.zoomTo(zoom);
})
.impl("getBoundsZoomLevel",function(bounds){
var sw = _(bounds).getSouthWest(),ne = _(bounds).getNorthEast();
this._impl.setViewport([sw,ne]);
return this._impl.getZoom();
//return this._impl._getBestLevel(_(bounds).getCenter(),{});
})
.impl("getPane",function(i){
return this._impl.getPanes()[i];
})
.impl("savePosition",function(){
//TODO multi map
this._lastPosition = this.getCenter();
})
.impl("returnToSavedPosition",function(){
//TODO multi map
var pos =this._lastPosition;
pos && this.panTo(pos);
})
.impl("zoomIn",function(latlng,center,continuose){
this._impl.zoomIn();
})
.impl("zoomOut",function(latlng,center,continuose){
this._impl.zoomOut();
})
.impl("getInfoWindow",function(){
//TODO TEST
var w = this._impl.getInfoWindow();
return new GInfoWindow(w);
})
.same(
"checkResize",
"getSize",
"enableDragging",
"disableDragging",
"enableDoubleClickZoom",
"disableDoubleClickZoom",
"enableScrollWheelZoom",
"disableScrollWheelZoom",
"enableContinuousZoom",
"disableContinuousZoom",
"enablePinchToZoom",
"disablePinchToZoom",
"clearOverlays",
"getContainer",
"closeInfoWindow"
)
.impl("enableInfoWindow",function(){
this._config.enableInfoWindow = true;
})
.impl("disableInfoWindow",function(){
this._config.enableInfoWindow = false;
this._impl.closeInfoWindow();
})
.attr_reader("infoWindowEnabled","_config.enableInfoWindow")
.attr_reader("draggingEnabled","_impl.config.enableDragging")
.attr_reader("doubleClickZoomEnabled","_impl.config.enableDblclickZoom")
.attr_reader("continuousZoomEnabled","_impl.config.enableContinuousZoom")
.attr_reader("scrollWheelZoomEnabled","_impl.config.enableWheelZoom")
.attr_reader("pinchToZoomEnabled","_impl.config.enablePinchToZoom")
.noimpl("enableRotation","disableRotation",
"rotationEnabled","isRotatable","changeHeading")
.end();
/**
* Translate baidu map event object into arguments
* array for google map event handlers
*/
///String,Boolean,GMapType,GOverlay,GLatLng,GPoint,Element,Number
var EVENT_SINGNATUR = {
'GEvent':{
'clearlisteners'
:['clearlisteners',['String']]
},
'GGroundOverlay':{
'visibilitychanged'
:['visibilitychanged',['Boolean']]
},
'GInfoWindow':{
'closeclick'
:['closeclick',[]],
'maximizeclick'
:['maximizeclick',[]],
'maximizeend'
:['maximizeend',[]],
'restoreclick'
:['restoreclick',[]],
'restoreend'
:['restoreend',[]]
},
'GMap2':{
//'addmaptype'
// :['addmaptype',['GMapType']],
//'removemaptype'
// :['removemaptype',['GMapType']],
'click'
:['click',['GOverlay','GLatLng','GLatLng']],
'dblclick'
:['dblclick',['GOverlay','GLatLng']],
'singlerightclick'
:['rightclick',['GPoint','Element','GOverlay']],
'movestart'
:['movestart',[]],
'move'
:['moving',[]],
'moveend'
:['moveend',[]],
'zoomend'
:['zoomend',['Number','Number']],
'maptypechanged'
:['maptypechange',[]],
'infowindowopen'
:['-infowindowopen',[]],
'infowindowbeforeclose'
:['-infowindowbeforeclose',[]],
'infowindowclose'
:['-infowindowclose',[]],
'addoverlay'
:['addoverlay',['GOverlay']],
'removeoverlay'
:['removeoverlay',['GOverlay']],
'clearoverlays'
:['clearoverlays',[]],
/**
* 2011年07月29日 API 1.2 Map增加mouseover和mouseout事件
* 百度地图的mouseover和mouseout没有提供坐标信息,所以在回调中得不到GLatLng
*/
'mouseover'
:['mouseover',[/* GLatLng */]],
'mouseout'
:['mouseout',[]],
'mousemove'
:['mousemove',['GLatLng']],
'dragstart'
:['dragstart',[]],
'drag'
:['dragging',[]],
'dragend'
:['dragend',[]],
'load'
:['load',[]],
'tilesloaded'
:['-tilesloaded',[]],
'headingchanged'
:['-headingchanged',[]],
'rotatabilitychanged'
:['-rotatabilitychanged',[]]
},
'GMarker':{
'click'
:['click',['GLatLng']],
'dblclick'
:['dblclick',['GLatLng']],
'mousedown'
:['mousedown',['GLatLng']],
'mouseup'
:['mouseup',['GLatLng']],
'mouseover'
:['mouseover',['GLatLng']],
'mouseout'
:['mouseout',['GLatLng']],
'infowindowopen'
:['infowindowopen',[]],
'infowindowbeforeclose'
:['-infowindowbeforeclose',[]],
/**
* 直接点击InfoWindow上的关闭按钮不会触发这个事件
* 点击InfoWindow和marker以外的地图才会触发这个事件
*/
'infowindowclose'
:['infowindowclose',[]],
'remove'
:['remove',[]],
'dragstart'
:['dragstart',['GLatLng']],
'drag'
:['dragging',['GLatLng']],
'dragend'
:['dragend',['GLatLng']]
//'visibilitychanged'
// :['visibilitychanged',['Boolean']]
},
'GPolygon':{
'remove'
:['remove',[]],
//'visibilitychanged'
// :['visibilitychanged',['Boolean']],
'click'
:['click',['GLatLng']],
'mouseover'
:['mouseover',[]],
'mouseout'
:['mouseout',[]],
'lineupdated'
:['lineupdate',[]]
//'endline'
// :['endline',[]],
//'cancelline'
// :['cancelline',[]]
},
'GPolyline':{