1
+ require ( '../../../src/leaflet/core/NonEarthCRS' ) ;
2
+
3
+ describe ( 'leaflet_NonEarthCRS' , function ( ) {
4
+ it ( 'initialize' , function ( ) {
5
+ var bounds = L . bounds ( [ - 180 , - 90 ] , [ 180 , 90 ] ) ;
6
+ var nonProjection = L . Projection . NonProjection ( bounds ) ;
7
+ expect ( nonProjection ) . not . toBeNull ( ) ;
8
+ expect ( nonProjection . bounds ) . not . toBeNull ( ) ;
9
+ expect ( nonProjection . bounds . max . x ) . toEqual ( 180 ) ;
10
+ expect ( nonProjection . bounds . max . y ) . toEqual ( 90 ) ;
11
+ expect ( nonProjection . bounds . min . x ) . toEqual ( - 180 ) ;
12
+ expect ( nonProjection . bounds . min . y ) . toEqual ( - 90 ) ;
13
+ } ) ;
14
+
15
+ it ( 'project, unproject' , function ( ) {
16
+ var bounds = L . bounds ( [ - 180 , - 90 ] , [ 180 , 90 ] ) ;
17
+ var latlng = L . latLng ( 50.5 , 30.5 ) ;
18
+ var nonProjection = L . Projection . NonProjection ( bounds ) ;
19
+ var point = nonProjection . project ( latlng ) ;
20
+ expect ( point ) . not . toBeNull ( ) ;
21
+ expect ( point . x ) . toEqual ( 30.5 ) ;
22
+ expect ( point . y ) . toEqual ( 50.5 ) ;
23
+ var newLatlng = nonProjection . unproject ( point ) ;
24
+ expect ( newLatlng ) . not . toBeNull ( ) ;
25
+ expect ( newLatlng . lat ) . toEqual ( 50.5 ) ;
26
+ expect ( newLatlng . lng ) . toEqual ( 30.5 ) ;
27
+ } ) ;
28
+
29
+ it ( 'CRS_initialize' , function ( ) {
30
+ var options = {
31
+ origin : { x : 30 , y : 50 } ,
32
+ bounds : L . bounds ( [ - 180 , - 90 ] , [ 180 , 90 ] ) ,
33
+ resolutions : [ 1000 , 100000 ]
34
+ } ;
35
+ var nonEarthCRS = L . CRS . NonEarthCRS ( options ) ;
36
+ expect ( nonEarthCRS ) . not . toBeNull ( ) ;
37
+ expect ( nonEarthCRS . bounds ) . not . toBeNull ( ) ;
38
+ expect ( nonEarthCRS . origin ) . toEqual ( options . origin ) ;
39
+ expect ( nonEarthCRS . projection . bounds ) . toEqual ( nonEarthCRS . bounds ) ;
40
+ expect ( nonEarthCRS . resolutions [ 0 ] ) . toEqual ( 1000 ) ;
41
+ expect ( nonEarthCRS . resolutions [ 1 ] ) . toEqual ( 100000 ) ;
42
+ expect ( nonEarthCRS . transformation ) . not . toBeNull ( ) ;
43
+ expect ( nonEarthCRS . _initHooksCalled ) . toBeTruthy ( ) ;
44
+ } ) ;
45
+
46
+ it ( 'CRS_scale' , function ( ) {
47
+ var options = {
48
+ origin : { x : 30 , y : 50 } ,
49
+ bounds : L . bounds ( [ - 180 , - 90 ] , [ 180 , 90 ] ) ,
50
+ resolutions : [ 100 , 100000 ]
51
+ } ;
52
+ var nonEarthCRS = L . CRS . NonEarthCRS ( options ) ;
53
+ var scale1 = nonEarthCRS . scale ( 0 ) ;
54
+ expect ( scale1 ) . toEqual ( 0.01 ) ;
55
+ nonEarthCRS . resolutions = [ ] ;
56
+ var scale2 = nonEarthCRS . scale ( 1 ) ;
57
+ expect ( scale2 ) . not . toBeNaN ( ) ;
58
+ } ) ;
59
+
60
+ it ( 'CRS_zoom' , function ( ) {
61
+ var options1 = {
62
+ origin : { x : 30 , y : 50 } ,
63
+ bounds : L . bounds ( [ - 180 , - 90 ] , [ 180 , 90 ] ) ,
64
+ resolutions : [ 100 , 100000 ]
65
+ } ;
66
+ var nonEarthCRS1 = L . CRS . NonEarthCRS ( options1 ) ;
67
+ var bound1 = nonEarthCRS1 . zoom ( 0.1 ) ;
68
+ expect ( bound1 ) . toEqual ( - 1 ) ;
69
+
70
+ //此处待开发修改后打开
71
+ // var options2 = {
72
+ // origin: {x: 30, y: 50},
73
+ // bounds: L.bounds([-180, -90], [180, 90]),
74
+ // resolutions: [100, 100000]
75
+ // };
76
+ // var nonEarthCRS2 = L.CRS.NonEarthCRS(options2);
77
+ // var bound2 = nonEarthCRS2.zoom(0.01);
78
+ // expect(bound2).toEqual(0);
79
+
80
+ var options3 = {
81
+ origin : { x : 30 , y : 50 } ,
82
+ bounds : L . bounds ( [ - 128 , - 90 ] , [ 128 , 90 ] ) ,
83
+ } ;
84
+ var nonEarthCRS3 = L . CRS . NonEarthCRS ( options3 ) ;
85
+ var bound3 = nonEarthCRS3 . zoom ( 10 ) ;
86
+ expect ( bound3 ) . toEqual ( 10 ) ;
87
+ } ) ;
88
+
89
+ it ( 'CRS_distance' , function ( ) {
90
+ var latlng1 = L . latLng ( 50.5 , 30.5 ) ;
91
+ var latlng2 = L . latLng ( 40 , 60.5 ) ;
92
+ var options = {
93
+ origin : { x : 30 , y : 50 } ,
94
+ bounds : L . bounds ( [ - 180 , - 90 ] , [ 180 , 90 ] ) ,
95
+ resolutions : [ 100 , 100000 ]
96
+ } ;
97
+ var nonEarthCRS = L . CRS . NonEarthCRS ( options ) ;
98
+ var distance = nonEarthCRS . distance ( latlng1 , latlng2 ) ;
99
+ expect ( distance ) . not . toBeNaN ( ) ;
100
+ } ) ;
101
+ } ) ;
0 commit comments