From e734242cd2265fbd77b2d0a998a4cbc33fa4d0c3 Mon Sep 17 00:00:00 2001 From: andremig-bentley <101671244+andremig-bentley@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:54:19 -0600 Subject: [PATCH] Add Undefined mercatorOrigin Check to computeMercatorFractionToDb (#7269) Co-authored-by: andremig-bentley Co-authored-by: Paul Connelly <22944042+pmconne@users.noreply.github.com> (cherry picked from commit a05e3b6aa83db16717f699fee40290f7619acd79) --- .../andremig-map_2024-10-15-19-56.json | 10 ++++++++++ .../src/test/BackgroundMapGeometry.test.ts | 16 ++++++++++++++-- core/frontend/src/tile/map/MapTilingScheme.ts | 9 +++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 common/changes/@itwin/core-frontend/andremig-map_2024-10-15-19-56.json diff --git a/common/changes/@itwin/core-frontend/andremig-map_2024-10-15-19-56.json b/common/changes/@itwin/core-frontend/andremig-map_2024-10-15-19-56.json new file mode 100644 index 000000000000..ac11a63efe7e --- /dev/null +++ b/common/changes/@itwin/core-frontend/andremig-map_2024-10-15-19-56.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@itwin/core-frontend", + "comment": "", + "type": "none" + } + ], + "packageName": "@itwin/core-frontend" +} \ No newline at end of file diff --git a/core/frontend/src/test/BackgroundMapGeometry.test.ts b/core/frontend/src/test/BackgroundMapGeometry.test.ts index f647ca8443db..0055583c4fe2 100644 --- a/core/frontend/src/test/BackgroundMapGeometry.test.ts +++ b/core/frontend/src/test/BackgroundMapGeometry.test.ts @@ -7,10 +7,11 @@ import { expect } from "chai"; import sinon from "sinon"; import { IModelApp } from "../IModelApp"; import { Cartographic, EmptyLocalization, GlobeMode } from "@itwin/core-common"; -import { IModelConnection } from "../IModelConnection"; -import { Range3d, XYAndZ } from "@itwin/core-geometry"; +import { BlankConnection, IModelConnection } from "../IModelConnection"; +import { Point3d, Range3d, XYAndZ } from "@itwin/core-geometry"; import { BackgroundMapGeometry } from "../BackgroundMapGeometry"; import { createBlankConnection } from "./createBlankConnection"; +import { Guid } from "@itwin/core-bentley"; describe("BackgroundMapGeometry", () => { const sandbox = sinon.createSandbox(); @@ -53,4 +54,15 @@ describe("BackgroundMapGeometry", () => { expect(dataset[i].z).to.eq(result[i].height); } }); + + it("creates new background map geometry when the origin is (0, 0, 0)", async () => { + const name = "test-blank-connection"; + const extents = new Range3d(-2500, -2500, -1000, 2500, 2500, 1000); + const globalOrigin = new Point3d(0, 0, 0); + const iTwinId = Guid.createValue(); + const imodel = BlankConnection.create({ name, location: { origin: [0, 0, 0], orientation: { yaw: 0, pitch: 0, roll: 0 } }, extents, iTwinId, globalOrigin }); + + const geometry = new BackgroundMapGeometry(0, 0, imodel); + expect(geometry).to.not.be.undefined; + }); }); diff --git a/core/frontend/src/tile/map/MapTilingScheme.ts b/core/frontend/src/tile/map/MapTilingScheme.ts index 6ee2f3d59686..9d64caf4b247 100644 --- a/core/frontend/src/tile/map/MapTilingScheme.ts +++ b/core/frontend/src/tile/map/MapTilingScheme.ts @@ -188,8 +188,10 @@ export abstract class MapTilingScheme { } /** @alpha */ - private ecefToPixelFraction(point: Point3d, applyTerrain: boolean): Point3d { - const cartoGraphic = Cartographic.fromEcef(point)!; + private ecefToPixelFraction(point: Point3d, applyTerrain: boolean): Point3d | undefined { + const cartoGraphic = Cartographic.fromEcef(point); + if (!cartoGraphic) + return undefined; return Point3d.create(this.longitudeToXFraction(cartoGraphic.longitude), this.latitudeToYFraction(cartoGraphic.latitude), applyTerrain ? cartoGraphic.height : 0); } @@ -205,6 +207,9 @@ export abstract class MapTilingScheme { const mercatorX = this.ecefToPixelFraction(dbToEcef.multiplyPoint3d(projectEast), applyTerrain); const mercatorY = this.ecefToPixelFraction(dbToEcef.multiplyPoint3d(projectNorth), applyTerrain); + if (!mercatorOrigin || !mercatorX || !mercatorY) + return Transform.createIdentity(); + const deltaX = Vector3d.createStartEnd(mercatorOrigin, mercatorX); const deltaY = Vector3d.createStartEnd(mercatorOrigin, mercatorY); const matrix = Matrix3d.createColumns(deltaX, deltaY, Vector3d.create(0, 0, 1));