From ecdb13df2e2cdd554fab2a8ce4cb6f5bed8d0657 Mon Sep 17 00:00:00 2001 From: AshwinNema <72392780+AshwinNema@users.noreply.github.com> Date: Sat, 1 Mar 2025 14:14:37 +0530 Subject: [PATCH] Add test for project method (#9303) Co-authored-by: Florian Bischof --- spec/suites/map/MapSpec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 3022234b4..874402bbe 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -2219,6 +2219,34 @@ describe('Map', () => { }); }); + describe('#project', () => { + const tolerance = 1 / 1000000; + + it('returns pixel coordinates relative to the top-left of the CRS extents', () => { + map.setView([40, -83], 5); + const x = latLng([40, -83]); + const a = map.project(x, 5); + expect(a.x).to.be.approximately(2207.288888, tolerance); + expect(a.y).to.be.approximately(3101.320460, tolerance); + }); + + it('test the other coordinates', () => { + map.setView([40, 83], 5); + const x = latLng([40, 83]); + const b = map.project(x, 5); + expect(b.x).to.be.approximately(5984.7111111, tolerance); + expect(b.y).to.be.approximately(3101.3204602, tolerance); + }); + + it('test the prev coordinates with different zoom', () => { + map.setView([40, 83], 5); + const x = latLng([40, 83]); + const b = map.project(x, 6); + expect(b.x).to.be.approximately(11969.422222, tolerance); + expect(b.y).to.be.approximately(6202.640920, tolerance); + }); + }); + describe('#latLngToLayerPoint', () => { it('throws if map is not set before', () => {