blob: c3b8caee007f6c578734db3f8bfa772b40e4c722 [file] [log] [blame]
Sean Condon1ae15802019-03-02 09:07:18 +00001/*
2 * Copyright 2019-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18import {TestBed} from '@angular/core/testing';
19import {LocMeta, MapBounds, ZoomUtils} from './zoomutils';
20
21describe('ZoomUtils', () => {
22 beforeEach(() => {
23 TestBed.configureTestingModule({
24
25 });
26 });
27
28 it('should be created', () => {
29 const zu = new ZoomUtils();
30 expect(zu).toBeTruthy();
31 });
32
33 it('should covert GEO origin to Canvas', () => {
34 const canvas = ZoomUtils.convertGeoToCanvas(<LocMeta>{
35 lng: 0, lat: 0
36 });
37
38 expect(canvas).not.toBeNull();
39 expect(canvas.x).toEqual(500);
40 expect(canvas.y).toEqual(500);
41 });
42
43 it('should covert GEO positive to Canvas', () => {
44 const canvas = ZoomUtils.convertGeoToCanvas(<LocMeta>{
45 lng: 30, lat: 30
46 });
47
48 expect(canvas).not.toBeNull();
49 expect(Math.round(canvas.x)).toEqual(667);
50 expect(canvas.y).toEqual(300);
51 });
52
53 it('should covert GEO negative to Canvas', () => {
54 const canvas = ZoomUtils.convertGeoToCanvas(<LocMeta>{
55 lng: -30, lat: -30
56 });
57
58 expect(canvas).not.toBeNull();
59 expect(Math.round(canvas.x)).toEqual(333);
60 expect(canvas.y).toEqual(700);
61 });
62
63 it('should convert XY origin to GEO', () => {
64 const geo = ZoomUtils.convertXYtoGeo(0, 0);
65 expect(geo.equivLoc.lng).toEqual(-90);
66 expect(geo.equivLoc.lat).toEqual(75);
67 });
68
69 it('should convert XY centre to GEO', () => {
70 const geo = ZoomUtils.convertXYtoGeo(500, 500);
71 expect(geo.equivLoc.lng).toEqual(0);
72 expect(geo.equivLoc.lat).toEqual(0);
73 });
74
75 it('should convert XY 1000 to GEO', () => {
76 const geo = ZoomUtils.convertXYtoGeo(1000, 1000);
77 expect(geo.equivLoc.lng).toEqual(90);
78 expect(geo.equivLoc.lat).toEqual(-75);
79 });
80
81 it('should convert XY leftmost to GEO', () => {
82 const geo = ZoomUtils.convertXYtoGeo(-500, 500);
83 expect(geo.equivLoc.lng).toEqual(-180);
84 expect(geo.equivLoc.lat).toEqual(0);
85 });
86
87 it('should convert XY rightmost to GEO', () => {
88 const geo = ZoomUtils.convertXYtoGeo(1500, 500);
89 expect(geo.equivLoc.lng).toEqual(+180);
90 expect(geo.equivLoc.lat).toEqual(0);
91 });
92
93 it('should convert MapBounds in upper left quadrant to Zoom level', () => {
94 const zoomParams = ZoomUtils.convertBoundsToZoomLevel(
95 <MapBounds>{ latMin: 40, lngMin: -40, latMax: 50, lngMax: -30 });
96
97 expect(zoomParams.sc).toEqual(11.18);
98 expect(Math.round(zoomParams.tx)).toEqual(-2916);
99 expect(Math.round(zoomParams.ty)).toEqual(-1736);
100 });
101
102 it('should convert MapBounds in lower right quadrant to Zoom level', () => {
103 const zoomParams = ZoomUtils.convertBoundsToZoomLevel(
104 <MapBounds>{ latMin: -50, lngMin: 30, latMax: -40, lngMax: 40 });
105
106 expect(zoomParams.sc).toEqual(11.18);
107 expect(Math.round(zoomParams.tx)).toEqual(-7264);
108 expect(Math.round(zoomParams.ty)).toEqual(-8444);
109 });
110
111 it('should convert MapBounds around equator to Zoom level', () => {
112 const zoomParams = ZoomUtils.convertBoundsToZoomLevel(
113 <MapBounds>{ latMin: -10, lngMin: -10, latMax: 10, lngMax: 10 });
114
115 expect(Math.round(zoomParams.sc * 100)).toEqual(644);
116 expect(Math.round(zoomParams.tx)).toEqual(-2721);
117 expect(Math.round(zoomParams.ty)).toEqual(-2721);
118 });
119});