Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Undefined mercatorOrigin Check to computeMercatorFractionToDb #7269

Merged
merged 8 commits into from
Oct 21, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/core-frontend",
"comment": "",
"type": "none"
}
],
"packageName": "@itwin/core-frontend"
}
16 changes: 14 additions & 2 deletions core/frontend/src/test/BackgroundMapGeometry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
});
});
7 changes: 6 additions & 1 deletion core/frontend/src/tile/map/MapTilingScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ export abstract class MapTilingScheme {
}

/** @alpha */
private ecefToPixelFraction(point: Point3d, applyTerrain: boolean): Point3d {
private ecefToPixelFraction(point: Point3d, applyTerrain: boolean): Point3d | undefined {
const cartoGraphic = Cartographic.fromEcef(point)!;
andremig-bentley marked this conversation as resolved.
Show resolved Hide resolved
if (!cartoGraphic)
return undefined;
return Point3d.create(this.longitudeToXFraction(cartoGraphic.longitude), this.latitudeToYFraction(cartoGraphic.latitude), applyTerrain ? cartoGraphic.height : 0);
}

Expand All @@ -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));
Expand Down
Loading