1- import { getMeterPerMapUnit } from '../../../src/common/util/MapCalculateUtil' ;
1+ import { getMeterPerMapUnit , scaleToResolution , scalesToResolutions } from '../../../src/common/util/MapCalculateUtil' ;
22
33describe ( 'MapCalculateUtil' , ( ) => {
44 it ( 'getMeterPerMapUnit m' , ( ) => {
@@ -20,5 +20,50 @@ describe('MapCalculateUtil', () => {
2020 expect ( getMeterPerMapUnit ( 'DEGREE' ) ) . toBeCloseTo ( 111319.49079327358 , 0.00001 ) ; ;
2121 expect ( getMeterPerMapUnit ( 'DD' ) ) . toBeCloseTo ( 111319.49079327358 , 0.00001 ) ; ;
2222 expect ( getMeterPerMapUnit ( 'degre' ) ) . toBeUndefined ( )
23- } ) ;
23+ } ) ;
24+ it ( 'scalesToResolutions with scales' , ( ) => {
25+ const scales = [ 50000 , 25000 ] ;
26+ const resolutions = scalesToResolutions ( scales , null , 96 , 'm' ) ;
27+
28+ expect ( resolutions . length ) . toBe ( 2 ) ;
29+ expect ( resolutions [ 0 ] ) . toBeCloseTo ( scaleToResolution ( 25000 , 96 , 'm' ) , 12 ) ;
30+ expect ( resolutions [ 1 ] ) . toBeCloseTo ( scaleToResolution ( 50000 , 96 , 'm' ) , 12 ) ;
31+ } ) ;
32+
33+ it ( 'scalesToResolutions dpi empty value should equal 96' , ( ) => {
34+ const scales = [ 50000 , 25000 ] ;
35+ const resolutionsWithEmptyDpi = scalesToResolutions ( scales , null , undefined , 'm' ) ;
36+ const resolutionsWith96Dpi = scalesToResolutions ( scales , null , 96 , 'm' ) ;
37+
38+ expect ( resolutionsWithEmptyDpi . length ) . toBe ( resolutionsWith96Dpi . length ) ;
39+ expect ( resolutionsWithEmptyDpi [ 0 ] ) . toBeCloseTo ( resolutionsWith96Dpi [ 0 ] , 12 ) ;
40+ expect ( resolutionsWithEmptyDpi [ 1 ] ) . toBeCloseTo ( resolutionsWith96Dpi [ 1 ] , 12 ) ;
41+ } ) ;
42+
43+ it ( 'scalesToResolutions with baseScale' , ( ) => {
44+ const bounds = { left : - 180 , right : 180 } ;
45+ const level = 3 ;
46+ const maxResolution = Math . abs ( bounds . left - bounds . right ) / 256 ;
47+ const baseResolution = maxResolution / 2 ;
48+ const baseScale = 1 / ( baseResolution * 96 * ( 1 / 0.0254 ) ) ;
49+ const resolutions = scalesToResolutions ( null , bounds , 96 , 'm' , level , baseScale ) ;
50+
51+ expect ( resolutions . length ) . toBe ( level ) ;
52+ expect ( resolutions [ 0 ] ) . toBeCloseTo ( maxResolution , 12 ) ;
53+ expect ( resolutions [ 1 ] ) . toBeCloseTo ( baseResolution , 12 ) ;
54+ expect ( resolutions [ 2 ] ) . toBeCloseTo ( baseResolution / 2 , 12 ) ;
55+ } ) ;
56+
57+ it ( 'scalesToResolutions with bounds and level' , ( ) => {
58+ const bounds = { left : - 180 , right : 180 } ;
59+ const level = 4 ;
60+ const maxResolution = Math . abs ( bounds . left - bounds . right ) / 256 ;
61+ const resolutions = scalesToResolutions ( null , bounds , 96 , 'degrees' , level ) ;
62+
63+ expect ( resolutions . length ) . toBe ( level ) ;
64+ expect ( resolutions [ 0 ] ) . toBeCloseTo ( maxResolution , 12 ) ;
65+ expect ( resolutions [ 1 ] ) . toBeCloseTo ( maxResolution / 2 , 12 ) ;
66+ expect ( resolutions [ 2 ] ) . toBeCloseTo ( maxResolution / 4 , 12 ) ;
67+ expect ( resolutions [ 3 ] ) . toBeCloseTo ( maxResolution / 8 , 12 ) ;
68+ } ) ;
2469} ) ;
0 commit comments