@itwin/core-frontend 4.1.0-dev.29 → 4.1.0-dev.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/BackgroundMapGeometry.d.ts +2 -2
- package/lib/cjs/BackgroundMapGeometry.d.ts.map +1 -1
- package/lib/cjs/BackgroundMapGeometry.js +18 -7
- package/lib/cjs/BackgroundMapGeometry.js.map +1 -1
- package/lib/cjs/GeoServices.d.ts +37 -7
- package/lib/cjs/GeoServices.d.ts.map +1 -1
- package/lib/cjs/GeoServices.js +74 -24
- package/lib/cjs/GeoServices.js.map +1 -1
- package/lib/cjs/IModelConnection.d.ts +23 -6
- package/lib/cjs/IModelConnection.d.ts.map +1 -1
- package/lib/cjs/IModelConnection.js +74 -7
- package/lib/cjs/IModelConnection.js.map +1 -1
- package/lib/cjs/ViewGlobalLocation.d.ts.map +1 -1
- package/lib/cjs/ViewGlobalLocation.js +4 -3
- package/lib/cjs/ViewGlobalLocation.js.map +1 -1
- package/lib/cjs/ViewState.d.ts +22 -4
- package/lib/cjs/ViewState.d.ts.map +1 -1
- package/lib/cjs/ViewState.js +36 -6
- package/lib/cjs/ViewState.js.map +1 -1
- package/lib/cjs/Viewport.js +1 -1
- package/lib/cjs/Viewport.js.map +1 -1
- package/lib/cjs/tile/map/MapTileTree.js +1 -1
- package/lib/cjs/tile/map/MapTileTree.js.map +1 -1
- package/lib/esm/BackgroundMapGeometry.d.ts +2 -2
- package/lib/esm/BackgroundMapGeometry.d.ts.map +1 -1
- package/lib/esm/BackgroundMapGeometry.js +18 -7
- package/lib/esm/BackgroundMapGeometry.js.map +1 -1
- package/lib/esm/GeoServices.d.ts +37 -7
- package/lib/esm/GeoServices.d.ts.map +1 -1
- package/lib/esm/GeoServices.js +74 -24
- package/lib/esm/GeoServices.js.map +1 -1
- package/lib/esm/IModelConnection.d.ts +23 -6
- package/lib/esm/IModelConnection.d.ts.map +1 -1
- package/lib/esm/IModelConnection.js +74 -7
- package/lib/esm/IModelConnection.js.map +1 -1
- package/lib/esm/ViewGlobalLocation.d.ts.map +1 -1
- package/lib/esm/ViewGlobalLocation.js +4 -3
- package/lib/esm/ViewGlobalLocation.js.map +1 -1
- package/lib/esm/ViewState.d.ts +22 -4
- package/lib/esm/ViewState.d.ts.map +1 -1
- package/lib/esm/ViewState.js +36 -6
- package/lib/esm/ViewState.js.map +1 -1
- package/lib/esm/Viewport.js +1 -1
- package/lib/esm/Viewport.js.map +1 -1
- package/lib/esm/tile/map/MapTileTree.js +1 -1
- package/lib/esm/tile/map/MapTileTree.js.map +1 -1
- package/package.json +18 -18
|
@@ -34,9 +34,9 @@ export declare class BackgroundMapGeometry {
|
|
|
34
34
|
constructor(_bimElevationBias: number, globeMode: GlobeMode, _iModel: IModelConnection);
|
|
35
35
|
static getCartesianRange(iModel: IModelConnection, result?: Range3d): Range3d;
|
|
36
36
|
static getCartesianTransitionDistance(iModel: IModelConnection): number;
|
|
37
|
-
dbToCartographicFromGcs(db: XYAndZ
|
|
37
|
+
dbToCartographicFromGcs(db: XYAndZ[]): Promise<Cartographic[]>;
|
|
38
38
|
dbToCartographic(db: XYAndZ, result?: Cartographic): Cartographic;
|
|
39
|
-
cartographicToDbFromGcs(cartographic: Cartographic
|
|
39
|
+
cartographicToDbFromGcs(cartographic: Cartographic[]): Promise<Point3d[]>;
|
|
40
40
|
cartographicToDb(cartographic: Cartographic, result?: Point3d): Point3d;
|
|
41
41
|
getEarthEllipsoid(radiusOffset?: number): Ellipsoid;
|
|
42
42
|
getPlane(offset?: number): Plane3dByOriginAndUnitNormal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackgroundMapGeometry.d.ts","sourceRoot":"","sources":["../../src/BackgroundMapGeometry.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAA2E,SAAS,EAA6C,QAAQ,EAAE,4BAA4B,EAAW,OAAO,EAAW,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE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,OAAO,GAAG,OAAO;IAwHxK,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO;CAoDvE;AAED;;;GAGG;AACH,wBAAsB,oCAAoC,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAsCtI"}
|
|
@@ -91,8 +91,12 @@ class BackgroundMapGeometry {
|
|
|
91
91
|
static getCartesianTransitionDistance(iModel) {
|
|
92
92
|
return BackgroundMapGeometry.getCartesianRange(iModel, scratchRange).diagonal().magnitudeXY() * BackgroundMapGeometry._transitionDistanceMultiplier;
|
|
93
93
|
}
|
|
94
|
-
async dbToCartographicFromGcs(db
|
|
95
|
-
|
|
94
|
+
async dbToCartographicFromGcs(db) {
|
|
95
|
+
const scratch = new core_geometry_1.Point3d();
|
|
96
|
+
const promises = db.map(async (p) => {
|
|
97
|
+
return this.cartesianRange.containsPoint(core_geometry_1.Point3d.createFrom(p, scratch)) ? this._iModel.spatialToCartographic(p) : this.dbToCartographic(p);
|
|
98
|
+
});
|
|
99
|
+
return Promise.all(promises);
|
|
96
100
|
}
|
|
97
101
|
dbToCartographic(db, result) {
|
|
98
102
|
if (undefined === result)
|
|
@@ -106,17 +110,24 @@ class BackgroundMapGeometry {
|
|
|
106
110
|
return core_common_1.Cartographic.fromEcef(ecef, result);
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
|
-
async cartographicToDbFromGcs(cartographic
|
|
113
|
+
async cartographicToDbFromGcs(cartographic) {
|
|
110
114
|
let db;
|
|
111
115
|
if (this.globeMode === core_common_1.GlobeMode.Plane) {
|
|
112
116
|
const fraction = core_geometry_1.Point2d.create(0, 0);
|
|
113
|
-
|
|
114
|
-
|
|
117
|
+
db = cartographic.map((p) => {
|
|
118
|
+
this._mercatorTilingScheme.cartographicToFraction(p.latitude, p.longitude, fraction);
|
|
119
|
+
return this._mercatorFractionToDb.multiplyXYZ(fraction.x, fraction.y, p.height);
|
|
120
|
+
});
|
|
115
121
|
}
|
|
116
122
|
else {
|
|
117
|
-
db = this._ecefToDb.multiplyPoint3d(
|
|
123
|
+
db = cartographic.map((p) => this._ecefToDb.multiplyPoint3d(p.toEcef()));
|
|
118
124
|
}
|
|
119
|
-
|
|
125
|
+
if (this._iModel.noGcsDefined)
|
|
126
|
+
return db;
|
|
127
|
+
const promises = db.map(async (p, i) => {
|
|
128
|
+
return this.cartesianRange.containsPoint(p) ? this._iModel.cartographicToSpatialFromGcs(cartographic[i]) : p;
|
|
129
|
+
});
|
|
130
|
+
return Promise.all(promises);
|
|
120
131
|
}
|
|
121
132
|
cartographicToDb(cartographic, result) {
|
|
122
133
|
if (this.globeMode === core_common_1.GlobeMode.Plane) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackgroundMapGeometry.js","sourceRoot":"","sources":["../../src/BackgroundMapGeometry.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,wDAA8R;AAC9R,oDAAyH;AAGzH,8CAA0D;AAE1D,MAAM,YAAY,GAAG,uBAAO,CAAC,UAAU,EAAE,CAAC;AAC1C,MAAM,gBAAgB,GAAG,uBAAO,CAAC,UAAU,EAAE,CAAC;AAC9C,MAAM,YAAY,GAAG,uBAAO,CAAC,MAAM,EAAE,CAAC;AACtC,MAAM,aAAa,GAAG,wBAAQ,CAAC,MAAM,EAAE,CAAC;AACxC,MAAM,kBAAkB,GAAG,uBAAO,CAAC,UAAU,EAAE,CAAC;AAChD,MAAM,mBAAmB,GAAG,qBAAK,CAAC,MAAM,CAAC,uBAAO,CAAC,MAAM,EAAE,EAAE,wBAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9E,MAAM,eAAe,GAAG,uBAAO,CAAC,UAAU,EAAE,CAAC;AAC7C,MAAM,mBAAmB,GAAG,wBAAQ,CAAC,cAAc,EAAE,CAAC;AACtD,MAAM,uBAAuB,GAAG,wBA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D,IAAI,SAAS,KAAK,OAAO,EAAE;QACzB,IAAA,qBAAM,EAAC,KAAK,CAAC,CAAC,CAAY,sBAAsB;QAChD,OAAO,SAAS,CAAC;KAClB;IACD,MAAM,MAAM,GAAG,wBAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjE,IAAI,MAAM,KAAK,SAAS;QACtB,OAAO,SAAS,CAAC;IAEnB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IACjC,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,IAAA,qBAAM,EAAC,KAAK,CAAC,CAAC,CAAe,sBAAsB;QACnD,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,yBAAS,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,OAAO,EAAG,CAAC;AACpF,CAAC;AAtCD,oFAsCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Views\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Angle, Arc3d, ClipPlane, ClipPlaneContainment, Constant, CurvePrimitive, Ellipsoid, GrowableXYZArray, LongitudeLatitudeNumber, Matrix3d, Plane3dByOriginAndUnitNormal, Point2d, Point3d, Point4d, Range1d, Range3d, Ray3d, Transform, Vector3d, XYAndZ } from \"@itwin/core-geometry\";\r\nimport { Cartographic, ColorByName, ColorDef, Frustum, GeoCoordStatus, GlobeMode, LinePixels } from \"@itwin/core-common\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { GraphicBuilder } from \"./render/GraphicBuilder\";\r\nimport { WebMercatorTilingScheme } from \"./tile/internal\";\r\n\r\nconst scratchRange = Range3d.createNull();\r\nconst scratchZeroPoint = Point3d.createZero();\r\nconst scratchPoint = Point3d.create();\r\nconst scratchVector = Vector3d.create();\r\nconst scratchCenterPoint = Point3d.createZero();\r\nconst scratchIntersectRay = Ray3d.create(Point3d.create(), Vector3d.create());\r\nconst scratchEyePoint = Point3d.createZero();\r\nconst scratchViewRotation = Matrix3d.createIdentity();\r\nconst scratchSilhouetteNormal = Vector3d.create();\r\nconst scratchCartoRectangle = new GrowableXYZArray();\r\nconst scratchWorkArray = new GrowableXYZArray();\r\n\r\nfunction accumulateDepthRange(point: Point3d, viewRotation: Matrix3d, range: Range3d) {\r\n viewRotation.multiplyXYZtoXYZ(point, scratchPoint);\r\n range.extend(scratchPoint);\r\n}\r\n\r\nfunction accumulateFrustumPlaneDepthRange(frustum: Frustum, plane: Plane3dByOriginAndUnitNormal, viewRotation: Matrix3d, range: Range3d, eyePoint?: Point3d) {\r\n let includeHorizon = false;\r\n for (let i = 0; i < 4; i++) {\r\n const frustumRay = Ray3d.createStartEnd(eyePoint ? eyePoint : frustum.points[i + 4], frustum.points[i]);\r\n const thisFraction = frustumRay.intersectionWithPlane(plane, scratchPoint);\r\n if (undefined !== thisFraction && (!eyePoint || thisFraction > 0))\r\n accumulateDepthRange(scratchPoint, viewRotation, range);\r\n else\r\n includeHorizon = true;\r\n }\r\n if (includeHorizon) {\r\n if (eyePoint !== undefined) {\r\n const eyeHeight = plane.altitude(eyePoint);\r\n if (eyeHeight < 0)\r\n accumulateDepthRange(eyePoint, viewRotation, range);\r\n else {\r\n const viewZ = viewRotation.getRow(2);\r\n const horizonDistance = Math.sqrt(eyeHeight * eyeHeight + 2 * eyeHeight * Constant.earthRadiusWGS84.equator);\r\n accumulateDepthRange(eyePoint.plusScaled(viewZ, -horizonDistance, scratchPoint), viewRotation, range);\r\n }\r\n }\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport function getFrustumPlaneIntersectionDepthRange(frustum: Frustum, plane: Plane3dByOriginAndUnitNormal): Range1d {\r\n const eyePoint = frustum.getEyePoint(scratchEyePoint);\r\n const viewRotation = frustum.getRotation(scratchViewRotation)!;\r\n const intersectRange = Range3d.createNull();\r\n accumulateFrustumPlaneDepthRange(frustum, plane, viewRotation, intersectRange, eyePoint);\r\n\r\n return intersectRange.isNull ? Range1d.createNull() : Range1d.createXX(intersectRange.low.z, intersectRange.high.z);\r\n}\r\n\r\n/** Geometry of background map - either an ellipsoid or a plane as defined by GlobeMode.\r\n * @internal\r\n */\r\nexport class BackgroundMapGeometry {\r\n public readonly globeMode: GlobeMode;\r\n public readonly geometry: Plane3dByOriginAndUnitNormal | Ellipsoid;\r\n public readonly globeOrigin: Point3d;\r\n public readonly globeMatrix: Matrix3d;\r\n public readonly cartesianRange: Range3d;\r\n public readonly cartesianTransitionRange: Range3d;\r\n public readonly cartesianPlane: Plane3dByOriginAndUnitNormal;\r\n public readonly cartesianDiagonal: number;\r\n public readonly cartesianChordHeight: number;\r\n public readonly maxGeometryChordHeight: number;\r\n private _mercatorFractionToDb: Transform;\r\n private _mercatorTilingScheme: WebMercatorTilingScheme;\r\n private _ecefToDb: Transform;\r\n public static maxCartesianDistance = 1E4; // If globe is 3D we still consider the map geometry flat within this distance of the project extents.\r\n private static _transitionDistanceMultiplier = .25; // In the transition range which extends beyond the cartesian range we interpolate between cartesian and ellipsoid.\r\n\r\n private static _scratchRayFractions = new Array<number>();\r\n private static _scratchRayAngles = new Array<LongitudeLatitudeNumber>();\r\n private static _scratchPoint = Point3d.createZero();\r\n\r\n constructor(private _bimElevationBias: number, globeMode: GlobeMode, private _iModel: IModelConnection) {\r\n this._ecefToDb = _iModel.getMapEcefToDb(_bimElevationBias);\r\n this.globeMode = globeMode;\r\n this.cartesianRange = BackgroundMapGeometry.getCartesianRange(_iModel);\r\n this.cartesianTransitionRange = this.cartesianRange.clone();\r\n this.cartesianTransitionRange.expandInPlace(BackgroundMapGeometry.getCartesianTransitionDistance(_iModel));\r\n this.cartesianDiagonal = this.cartesianRange.diagonal().magnitudeXY();\r\n const earthRadius = Constant.earthRadiusWGS84.equator;\r\n this.globeOrigin = this._ecefToDb.origin.cloneAsPoint3d();\r\n this.globeMatrix = this._ecefToDb.matrix.clone();\r\n this.cartesianChordHeight = Math.sqrt(this.cartesianDiagonal * this.cartesianDiagonal + earthRadius * earthRadius) - earthRadius; // Maximum chord height deviation of the cartesian area.\r\n const halfChordAngle = Angle.piOver2Radians / 10;\r\n this.maxGeometryChordHeight = (1 - Math.cos(halfChordAngle)) * earthRadius;\r\n this.cartesianPlane = this.getPlane();\r\n this.geometry = (globeMode === GlobeMode.Ellipsoid) ? this.getEarthEllipsoid() : this.cartesianPlane;\r\n this._mercatorTilingScheme = new WebMercatorTilingScheme();\r\n this._mercatorFractionToDb = this._mercatorTilingScheme.computeMercatorFractionToDb(this._ecefToDb, _bimElevationBias, _iModel, false);\r\n }\r\n public static getCartesianRange(iModel: IModelConnection, result?: Range3d): Range3d {\r\n const cartesianRange = Range3d.createFrom(iModel.projectExtents, result);\r\n cartesianRange.expandInPlace(BackgroundMapGeometry.maxCartesianDistance);\r\n return cartesianRange;\r\n }\r\n public static getCartesianTransitionDistance(iModel: IModelConnection): number {\r\n return BackgroundMapGeometry.getCartesianRange(iModel, scratchRange).diagonal().magnitudeXY() * BackgroundMapGeometry._transitionDistanceMultiplier;\r\n }\r\n\r\n public async dbToCartographicFromGcs(db: XYAndZ, result?: Cartographic): Promise<Cartographic> {\r\n return this.cartesianRange.containsPoint(Point3d.createFrom(db)) ? this._iModel.spatialToCartographic(db, result) : this.dbToCartographic(db, result);\r\n }\r\n\r\n public dbToCartographic(db: XYAndZ, result?: Cartographic): Cartographic {\r\n if (undefined === result)\r\n result = Cartographic.createZero();\r\n\r\n if (this.globeMode === GlobeMode.Plane) {\r\n const mercatorFraction = this._mercatorFractionToDb.multiplyInversePoint3d(db)!;\r\n return this._mercatorTilingScheme.fractionToCartographic(mercatorFraction.x, mercatorFraction.y, result, mercatorFraction.z);\r\n } else {\r\n const ecef = this._ecefToDb.multiplyInversePoint3d(db)!;\r\n return Cartographic.fromEcef(ecef, result)!;\r\n }\r\n }\r\n\r\n public async cartographicToDbFromGcs(cartographic: Cartographic, result?: Point3d): Promise<Point3d> {\r\n let db;\r\n if (this.globeMode === GlobeMode.Plane) {\r\n const fraction = Point2d.create(0, 0);\r\n this._mercatorTilingScheme.cartographicToFraction(cartographic.latitude, cartographic.longitude, fraction);\r\n db = this._mercatorFractionToDb.multiplyXYZ(fraction.x, fraction.y, cartographic.height, result);\r\n } else {\r\n db = this._ecefToDb.multiplyPoint3d(cartographic.toEcef())!;\r\n }\r\n return (!this._iModel.noGcsDefined && this.cartesianRange.containsPoint(db)) ? this._iModel.cartographicToSpatialFromGcs(cartographic) : db;\r\n }\r\n public cartographicToDb(cartographic: Cartographic, result?: Point3d): Point3d {\r\n if (this.globeMode === GlobeMode.Plane) {\r\n const fraction = Point2d.create(0, 0);\r\n this._mercatorTilingScheme.cartographicToFraction(cartographic.latitude, cartographic.longitude, fraction);\r\n return this._mercatorFractionToDb.multiplyXYZ(fraction.x, fraction.y, cartographic.height, result);\r\n } else {\r\n return this._ecefToDb.multiplyPoint3d(cartographic.toEcef())!;\r\n }\r\n }\r\n\r\n public getEarthEllipsoid(radiusOffset = 0): Ellipsoid {\r\n const equatorRadius = Constant.earthRadiusWGS84.equator + radiusOffset, polarRadius = Constant.earthRadiusWGS84.polar + radiusOffset;\r\n return Ellipsoid.createCenterMatrixRadii(this.globeOrigin, this.globeMatrix, equatorRadius, equatorRadius, polarRadius);\r\n }\r\n public getPlane(offset = 0) {\r\n return Plane3dByOriginAndUnitNormal.create(Point3d.create(0, 0, this._bimElevationBias + offset), Vector3d.create(0, 0, 1))!;\r\n }\r\n\r\n public getRayIntersection(ray: Ray3d, positiveOnly: boolean): Ray3d | undefined {\r\n let intersect;\r\n if (this.globeMode === GlobeMode.Ellipsoid) {\r\n const ellipsoid = this.geometry as Ellipsoid;\r\n BackgroundMapGeometry._scratchRayAngles.length = 0;\r\n BackgroundMapGeometry._scratchRayFractions.length = 0;\r\n\r\n const count = ellipsoid.intersectRay(ray, BackgroundMapGeometry._scratchRayFractions, undefined, BackgroundMapGeometry._scratchRayAngles);\r\n let intersectDistance;\r\n for (let i = 0; i < count; i++) {\r\n const thisFraction = BackgroundMapGeometry._scratchRayFractions[i];\r\n if ((!positiveOnly || thisFraction > 0) && (undefined === intersectDistance || thisFraction < intersectDistance)) {\r\n intersectDistance = thisFraction;\r\n intersect = scratchIntersectRay;\r\n ellipsoid.radiansToUnitNormalRay(BackgroundMapGeometry._scratchRayAngles[i].longitudeRadians, BackgroundMapGeometry._scratchRayAngles[i].latitudeRadians, intersect);\r\n if (intersect.direction.dotProduct(ray.direction) < 0) {\r\n if (this.cartesianRange.containsPoint(intersect.origin)) { // If we're in the cartesian range, correct to planar intersection.\r\n const planeFraction = ray.intersectionWithPlane(this.cartesianPlane, scratchIntersectRay.origin);\r\n if (undefined !== planeFraction && (!positiveOnly || planeFraction > 0)) {\r\n intersect.direction.setFromVector3d(this.cartesianPlane.getNormalRef());\r\n }\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n const plane = this.geometry as Plane3dByOriginAndUnitNormal;\r\n const thisFraction = ray.intersectionWithPlane(plane, scratchIntersectRay.origin);\r\n if (undefined !== thisFraction && (!positiveOnly || thisFraction > 0)) {\r\n intersect = scratchIntersectRay;\r\n intersect.direction.setFromVector3d(plane.getNormalRef());\r\n }\r\n }\r\n return intersect;\r\n }\r\n public getPointHeight(point: Point3d): number | undefined {\r\n if (this.globeMode === GlobeMode.Ellipsoid) {\r\n const ellipsoid = this.geometry as Ellipsoid;\r\n const projected = ellipsoid.projectPointToSurface(point);\r\n if (undefined === projected)\r\n return undefined;\r\n\r\n const distance = ellipsoid.radiansToPoint(projected.longitudeRadians, projected.latitudeRadians).distance(point);\r\n const ellipsePoint = ellipsoid.transformRef.multiplyInversePoint3d(point, BackgroundMapGeometry._scratchPoint)!;\r\n return ellipsePoint.magnitude() < 1 ? -distance : distance;\r\n } else {\r\n const plane = this.geometry as Plane3dByOriginAndUnitNormal;\r\n return plane.altitude(point);\r\n }\r\n }\r\n\r\n /** @internal */\r\n public getFrustumIntersectionDepthRange(frustum: Frustum, bimRange: Range3d, heightRange?: Range1d, gridPlane?: Plane3dByOriginAndUnitNormal, doGlobalScope?: boolean): Range1d {\r\n const clipPlanes = frustum.getRangePlanes(false, false, 0);\r\n const eyePoint = frustum.getEyePoint(scratchEyePoint);\r\n const viewRotation = frustum.getRotation(scratchViewRotation);\r\n if (undefined === viewRotation)\r\n return Range1d.createNull(); // Degenerate frustum...\r\n const viewZ = viewRotation.getRow(2);\r\n const cartoRange = this.cartesianTransitionRange;\r\n const intersectRange = Range3d.createNull();\r\n const doAccumulate = ((point: Point3d) => accumulateDepthRange(point, viewRotation, intersectRange));\r\n\r\n if (gridPlane)\r\n accumulateFrustumPlaneDepthRange(frustum, gridPlane, viewRotation, intersectRange, eyePoint);\r\n if (this.geometry instanceof Plane3dByOriginAndUnitNormal) {\r\n // Intersection with a planar background projection...\r\n const heights = heightRange ? [heightRange.low, heightRange.high] : [0];\r\n for (const height of heights) {\r\n accumulateFrustumPlaneDepthRange(frustum, this.getPlane(height), viewRotation, intersectRange, eyePoint);\r\n }\r\n } else {\r\n const minOffset = heightRange ? heightRange.low : 0, maxOffset = (heightRange ? heightRange.high : 0) + this.cartesianChordHeight;\r\n const radiusOffsets = [minOffset, maxOffset];\r\n\r\n // If we are doing global scope then include minimum ellipsoid that represents the chordal approximation of the low level tiles.\r\n // this substantially expands the frustum so don't do it for non-global views, but this clipping out the low level tiles.\r\n if (doGlobalScope)\r\n radiusOffsets.push(minOffset - this.maxGeometryChordHeight);\r\n\r\n const toView = Transform.createRefs(Point3d.createZero(), viewRotation);\r\n const eyePoint4d = eyePoint ? Point4d.createFromPointAndWeight(eyePoint, 1) : Point4d.createFromPointAndWeight(viewZ, 0);\r\n\r\n for (const radiusOffset of radiusOffsets) {\r\n const ellipsoid = this.getEarthEllipsoid(radiusOffset);\r\n const isInside = eyePoint && ellipsoid.worldToLocal(eyePoint)!.magnitude() < 1.0;\r\n const center = ellipsoid.localToWorld(scratchZeroPoint, scratchCenterPoint);\r\n const clipPlaneCount = clipPlanes.planes.length;\r\n\r\n // Extrema...\r\n let angles, extremaPoint;\r\n if (undefined !== (angles = ellipsoid.surfaceNormalToAngles(viewZ)) &&\r\n undefined !== (extremaPoint = ellipsoid.radiansToPoint(angles.longitudeRadians, angles.latitudeRadians)) &&\r\n (eyePoint === undefined || viewZ.dotProductStartEnd(extremaPoint, eyePoint) > 0) &&\r\n clipPlanes.classifyPointContainment([extremaPoint], false) !== ClipPlaneContainment.StronglyOutside)\r\n doAccumulate(extremaPoint);\r\n\r\n if (isInside) {\r\n if (eyePoint)\r\n doAccumulate(eyePoint);\r\n } else {\r\n const silhouette = ellipsoid.silhouetteArc(eyePoint4d);\r\n if (silhouette !== undefined) {\r\n silhouette.perpendicularVector.clone(scratchSilhouetteNormal);\r\n // Push the silhouette plane as clip so that we do not include geometry at other side of ellipsoid.\r\n // First make sure that it is pointing in the right direction.\r\n if (eyePoint) {\r\n // Clip toward eye.\r\n if (scratchSilhouetteNormal.dotProduct(viewZ) < 0)\r\n scratchSilhouetteNormal.negate(scratchSilhouetteNormal);\r\n } else {\r\n /* If parallel projection - clip toward side of ellipsoid with BIM geometry */\r\n if (Vector3d.createStartEnd(silhouette.center, bimRange.center).dotProduct(scratchSilhouetteNormal) < 0)\r\n scratchSilhouetteNormal.negate(scratchSilhouetteNormal);\r\n }\r\n clipPlanes.planes.push(ClipPlane.createNormalAndDistance(scratchSilhouetteNormal, scratchSilhouetteNormal.dotProduct(silhouette.center))!);\r\n } else {\r\n clipPlanes.planes.push(ClipPlane.createNormalAndPoint(viewZ, center)!);\r\n }\r\n }\r\n if (!isInside || radiusOffset === radiusOffsets[0]) {\r\n // Intersections of ellipsoid with frustum planes...\r\n const viewingInside = eyePoint !== undefined && viewZ.dotProduct(Vector3d.createStartEnd(center, eyePoint)) < 0;\r\n if (eyePoint === undefined || !isInside || viewingInside) {\r\n for (const clipPlane of clipPlanes.planes) {\r\n const plane = clipPlane.getPlane3d();\r\n const arc = ellipsoid.createPlaneSection(plane);\r\n if (undefined !== arc) {\r\n arc.announceClipIntervals(clipPlanes, (a0: number, a1: number, cp: CurvePrimitive) => {\r\n if (Math.abs(a1 - a0) < 1.0E-8) {\r\n doAccumulate(cp.fractionToPoint(a0)); // Tiny sweep - avoid problem with rangeMethod (not worth doing anyway).\r\n } else {\r\n const segment = cp.clonePartialCurve(a0, a1);\r\n if (segment !== undefined)\r\n segment.extendRange(intersectRange, toView);\r\n\r\n }\r\n });\r\n }\r\n }\r\n }\r\n // Intersections of the cartesian region with frustum planes.\r\n scratchCartoRectangle.resize(0);\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.low.y, z: radiusOffset });\r\n scratchCartoRectangle.push({ x: cartoRange.high.x, y: cartoRange.low.y, z: radiusOffset });\r\n scratchCartoRectangle.push({ x: cartoRange.high.x, y: cartoRange.high.y, z: radiusOffset });\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.high.y, z: radiusOffset });\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.low.y, z: radiusOffset });\r\n\r\n clipPlanes.clipConvexPolygonInPlace(scratchCartoRectangle, scratchWorkArray);\r\n for (let i = 0; i < scratchCartoRectangle.length; i++)\r\n doAccumulate(scratchCartoRectangle.getPoint3dAtUncheckedPointIndex(i));\r\n while (clipPlanes.planes.length > clipPlaneCount) // Remove pushed silhouette plane.\r\n clipPlanes.planes.pop();\r\n }\r\n }\r\n }\r\n\r\n if (intersectRange.zLength() < 5) {\r\n // For the case where the fitted depth is small (less than 5 meters) we must be viewing planar projection or the\r\n // planar portion of the iModel in plan view. In this case use a constant (arbitrarily 100 meters) depth so that the frustum\r\n // Z is doesn't change and cause nearly planar geometry to jitter in Z buffer.\r\n const zCenter = (intersectRange.low.z + intersectRange.high.z) / 2;\r\n const zExpand = 50;\r\n return Range1d.createXX(zCenter - zExpand, zCenter + zExpand);\r\n } else {\r\n const diagonal = intersectRange.diagonal(scratchVector).magnitudeXY();\r\n const expansion = diagonal * .01;\r\n return Range1d.createXX(intersectRange.low.z - expansion, intersectRange.high.z + expansion);\r\n }\r\n }\r\n\r\n public addFrustumDecorations(builder: GraphicBuilder, frustum: Frustum) {\r\n if (this.geometry instanceof Ellipsoid) {\r\n const ellipsoid = this.geometry;\r\n const clipPlanes = frustum.getRangePlanes(false, false, 0);\r\n const viewRotation = frustum.getRotation()!;\r\n const eyePoint = frustum.getEyePoint(scratchEyePoint);\r\n const viewZ = viewRotation.getRow(2);\r\n const eyePoint4d = eyePoint ? Point4d.createFromPointAndWeight(eyePoint, 1) : Point4d.createFromPointAndWeight(viewZ, 0);\r\n const isInside = eyePoint && ellipsoid.worldToLocal(eyePoint)!.magnitude() < 1.0;\r\n const center = ellipsoid.localToWorld(scratchZeroPoint, scratchCenterPoint);\r\n const cartoRange = this.cartesianTransitionRange;\r\n\r\n if (!isInside) {\r\n const silhouette = ellipsoid.silhouetteArc(eyePoint4d);\r\n if (silhouette !== undefined) {\r\n silhouette.perpendicularVector.clone(scratchSilhouetteNormal);\r\n if (scratchSilhouetteNormal.dotProduct(viewZ) < 0)\r\n scratchSilhouetteNormal.negate(scratchSilhouetteNormal);\r\n clipPlanes.planes.push(ClipPlane.createNormalAndDistance(scratchSilhouetteNormal, scratchSilhouetteNormal.dotProduct(silhouette.center))!);\r\n } else {\r\n clipPlanes.planes.push(ClipPlane.createNormalAndPoint(viewZ, center)!);\r\n }\r\n\r\n const ellipsoidColor = ColorDef.create(ColorByName.yellow);\r\n builder.setSymbology(ellipsoidColor, ellipsoidColor, 1, LinePixels.Code2);\r\n for (const clipPlane of clipPlanes.planes) {\r\n const plane = clipPlane.getPlane3d();\r\n const arc = ellipsoid.createPlaneSection(plane);\r\n if (undefined !== arc) {\r\n arc.announceClipIntervals(clipPlanes, (a0: number, a1: number, cp: CurvePrimitive) => {\r\n const segment = cp.clonePartialCurve(a0, a1);\r\n if (segment !== undefined)\r\n builder.addArc(segment as Arc3d, false, false);\r\n });\r\n }\r\n\r\n // Intersections of the cartesian region with frustum planes.\r\n scratchCartoRectangle.resize(0);\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.low.y, z: 0 });\r\n scratchCartoRectangle.push({ x: cartoRange.high.x, y: cartoRange.low.y, z: 0 });\r\n scratchCartoRectangle.push({ x: cartoRange.high.x, y: cartoRange.high.y, z: 0 });\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.high.y, z: 0 });\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.low.y, z: 0 });\r\n\r\n clipPlanes.clipConvexPolygonInPlace(scratchCartoRectangle, scratchWorkArray);\r\n if (scratchCartoRectangle.length > 0) {\r\n builder.addLineString(scratchCartoRectangle.getPoint3dArray());\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n/** Calculate the ECEF to database (IModel) coordinate transform at a provided location, using the GCS of the iModel.\r\n * The transform will exactly represent the GCS at the provided location.\r\n * @public\r\n */\r\nexport async function calculateEcefToDbTransformAtLocation(originIn: Point3d, iModel: IModelConnection): Promise<Transform | undefined> {\r\n const geoConverter = iModel.noGcsDefined ? undefined : iModel.geoServices.getConverter(\"WGS84\");\r\n if (geoConverter === undefined)\r\n return undefined;\r\n\r\n const origin = Point3d.create(originIn.x, originIn.y, 0); // Always Test at zero.\r\n const eastPoint = origin.plusXYZ(1, 0, 0);\r\n const northPoint = origin.plusXYZ(0, 1, 0);\r\n\r\n const response = await geoConverter.getGeoCoordinatesFromIModelCoordinates([origin, northPoint, eastPoint]);\r\n if (response.geoCoords[0].s !== GeoCoordStatus.Success || response.geoCoords[1].s !== GeoCoordStatus.Success || response.geoCoords[2].s !== GeoCoordStatus.Success)\r\n return undefined;\r\n\r\n const geoOrigin = Point3d.fromJSON(response.geoCoords[0].p);\r\n const geoNorth = Point3d.fromJSON(response.geoCoords[1].p);\r\n const geoEast = Point3d.fromJSON(response.geoCoords[2].p);\r\n const ecefOrigin = Cartographic.fromDegrees({ longitude: geoOrigin.x, latitude: geoOrigin.y, height: geoOrigin.z }).toEcef()!;\r\n const ecefNorth = Cartographic.fromDegrees({ longitude: geoNorth.x, latitude: geoNorth.y, height: geoNorth.z }).toEcef()!;\r\n const ecefEast = Cartographic.fromDegrees({ longitude: geoEast.x, latitude: geoEast.y, height: geoEast.z }).toEcef()!;\r\n\r\n const xVector = Vector3d.createStartEnd(ecefOrigin, ecefEast);\r\n const yVector = Vector3d.createStartEnd(ecefOrigin, ecefNorth);\r\n const zVector = xVector.unitCrossProduct(yVector);\r\n if (undefined === zVector) {\r\n assert(false); // Should never occur.\r\n return undefined;\r\n }\r\n const matrix = Matrix3d.createColumns(xVector, yVector, zVector);\r\n if (matrix === undefined)\r\n return undefined;\r\n\r\n const inverse = matrix.inverse();\r\n if (inverse === undefined) {\r\n assert(false); // Should never occur.\r\n return undefined;\r\n }\r\n\r\n return Transform.createMatrixPickupPutdown(matrix, origin, ecefOrigin).inverse()!;\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"BackgroundMapGeometry.js","sourceRoot":"","sources":["../../src/BackgroundMapGeometry.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,wDAA8R;AAC9R,oDAAyH;AAGzH,8CAA0D;AAE1D,MAAM,YAAY,GAAG,uBAAO,CAAC,UAAU,EAAE,CAAC;AAC1C,MAAM,gBAAgB,GAAG,uBAAO,CAAC,UAAU,EAAE,CAAC;AAC9C,MAAM,YAAY,GAAG,uBAAO,CAAC,MAAM,EAAE,CAAC;AACtC,MAAM,aAAa,GAAG,wBAAQ,CAAC,MAAM,EAAE,CAAC;AACxC,MAAM,kBAAkB,GAAG,uBAAO,CAAC,UAAU,EAAE,CAAC;AAChD,MAAM,mBAAmB,GAAG,qBAAK,CAAC,MAAM,CAAC,uBAAO,CAAC,MAAM,EAAE,EAAE,wBAAQ,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C;AACpF,CAAC;AAtCD,oFAsCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Views\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Angle, Arc3d, ClipPlane, ClipPlaneContainment, Constant, CurvePrimitive, Ellipsoid, GrowableXYZArray, LongitudeLatitudeNumber, Matrix3d, Plane3dByOriginAndUnitNormal, Point2d, Point3d, Point4d, Range1d, Range3d, Ray3d, Transform, Vector3d, XYAndZ } from \"@itwin/core-geometry\";\r\nimport { Cartographic, ColorByName, ColorDef, Frustum, GeoCoordStatus, GlobeMode, LinePixels } from \"@itwin/core-common\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { GraphicBuilder } from \"./render/GraphicBuilder\";\r\nimport { WebMercatorTilingScheme } from \"./tile/internal\";\r\n\r\nconst scratchRange = Range3d.createNull();\r\nconst scratchZeroPoint = Point3d.createZero();\r\nconst scratchPoint = Point3d.create();\r\nconst scratchVector = Vector3d.create();\r\nconst scratchCenterPoint = Point3d.createZero();\r\nconst scratchIntersectRay = Ray3d.create(Point3d.create(), Vector3d.create());\r\nconst scratchEyePoint = Point3d.createZero();\r\nconst scratchViewRotation = Matrix3d.createIdentity();\r\nconst scratchSilhouetteNormal = Vector3d.create();\r\nconst scratchCartoRectangle = new GrowableXYZArray();\r\nconst scratchWorkArray = new GrowableXYZArray();\r\n\r\nfunction accumulateDepthRange(point: Point3d, viewRotation: Matrix3d, range: Range3d) {\r\n viewRotation.multiplyXYZtoXYZ(point, scratchPoint);\r\n range.extend(scratchPoint);\r\n}\r\n\r\nfunction accumulateFrustumPlaneDepthRange(frustum: Frustum, plane: Plane3dByOriginAndUnitNormal, viewRotation: Matrix3d, range: Range3d, eyePoint?: Point3d) {\r\n let includeHorizon = false;\r\n for (let i = 0; i < 4; i++) {\r\n const frustumRay = Ray3d.createStartEnd(eyePoint ? eyePoint : frustum.points[i + 4], frustum.points[i]);\r\n const thisFraction = frustumRay.intersectionWithPlane(plane, scratchPoint);\r\n if (undefined !== thisFraction && (!eyePoint || thisFraction > 0))\r\n accumulateDepthRange(scratchPoint, viewRotation, range);\r\n else\r\n includeHorizon = true;\r\n }\r\n if (includeHorizon) {\r\n if (eyePoint !== undefined) {\r\n const eyeHeight = plane.altitude(eyePoint);\r\n if (eyeHeight < 0)\r\n accumulateDepthRange(eyePoint, viewRotation, range);\r\n else {\r\n const viewZ = viewRotation.getRow(2);\r\n const horizonDistance = Math.sqrt(eyeHeight * eyeHeight + 2 * eyeHeight * Constant.earthRadiusWGS84.equator);\r\n accumulateDepthRange(eyePoint.plusScaled(viewZ, -horizonDistance, scratchPoint), viewRotation, range);\r\n }\r\n }\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport function getFrustumPlaneIntersectionDepthRange(frustum: Frustum, plane: Plane3dByOriginAndUnitNormal): Range1d {\r\n const eyePoint = frustum.getEyePoint(scratchEyePoint);\r\n const viewRotation = frustum.getRotation(scratchViewRotation)!;\r\n const intersectRange = Range3d.createNull();\r\n accumulateFrustumPlaneDepthRange(frustum, plane, viewRotation, intersectRange, eyePoint);\r\n\r\n return intersectRange.isNull ? Range1d.createNull() : Range1d.createXX(intersectRange.low.z, intersectRange.high.z);\r\n}\r\n\r\n/** Geometry of background map - either an ellipsoid or a plane as defined by GlobeMode.\r\n * @internal\r\n */\r\nexport class BackgroundMapGeometry {\r\n public readonly globeMode: GlobeMode;\r\n public readonly geometry: Plane3dByOriginAndUnitNormal | Ellipsoid;\r\n public readonly globeOrigin: Point3d;\r\n public readonly globeMatrix: Matrix3d;\r\n public readonly cartesianRange: Range3d;\r\n public readonly cartesianTransitionRange: Range3d;\r\n public readonly cartesianPlane: Plane3dByOriginAndUnitNormal;\r\n public readonly cartesianDiagonal: number;\r\n public readonly cartesianChordHeight: number;\r\n public readonly maxGeometryChordHeight: number;\r\n private _mercatorFractionToDb: Transform;\r\n private _mercatorTilingScheme: WebMercatorTilingScheme;\r\n private _ecefToDb: Transform;\r\n public static maxCartesianDistance = 1E4; // If globe is 3D we still consider the map geometry flat within this distance of the project extents.\r\n private static _transitionDistanceMultiplier = .25; // In the transition range which extends beyond the cartesian range we interpolate between cartesian and ellipsoid.\r\n\r\n private static _scratchRayFractions = new Array<number>();\r\n private static _scratchRayAngles = new Array<LongitudeLatitudeNumber>();\r\n private static _scratchPoint = Point3d.createZero();\r\n\r\n constructor(private _bimElevationBias: number, globeMode: GlobeMode, private _iModel: IModelConnection) {\r\n this._ecefToDb = _iModel.getMapEcefToDb(_bimElevationBias);\r\n this.globeMode = globeMode;\r\n this.cartesianRange = BackgroundMapGeometry.getCartesianRange(_iModel);\r\n this.cartesianTransitionRange = this.cartesianRange.clone();\r\n this.cartesianTransitionRange.expandInPlace(BackgroundMapGeometry.getCartesianTransitionDistance(_iModel));\r\n this.cartesianDiagonal = this.cartesianRange.diagonal().magnitudeXY();\r\n const earthRadius = Constant.earthRadiusWGS84.equator;\r\n this.globeOrigin = this._ecefToDb.origin.cloneAsPoint3d();\r\n this.globeMatrix = this._ecefToDb.matrix.clone();\r\n this.cartesianChordHeight = Math.sqrt(this.cartesianDiagonal * this.cartesianDiagonal + earthRadius * earthRadius) - earthRadius; // Maximum chord height deviation of the cartesian area.\r\n const halfChordAngle = Angle.piOver2Radians / 10;\r\n this.maxGeometryChordHeight = (1 - Math.cos(halfChordAngle)) * earthRadius;\r\n this.cartesianPlane = this.getPlane();\r\n this.geometry = (globeMode === GlobeMode.Ellipsoid) ? this.getEarthEllipsoid() : this.cartesianPlane;\r\n this._mercatorTilingScheme = new WebMercatorTilingScheme();\r\n this._mercatorFractionToDb = this._mercatorTilingScheme.computeMercatorFractionToDb(this._ecefToDb, _bimElevationBias, _iModel, false);\r\n }\r\n public static getCartesianRange(iModel: IModelConnection, result?: Range3d): Range3d {\r\n const cartesianRange = Range3d.createFrom(iModel.projectExtents, result);\r\n cartesianRange.expandInPlace(BackgroundMapGeometry.maxCartesianDistance);\r\n return cartesianRange;\r\n }\r\n public static getCartesianTransitionDistance(iModel: IModelConnection): number {\r\n return BackgroundMapGeometry.getCartesianRange(iModel, scratchRange).diagonal().magnitudeXY() * BackgroundMapGeometry._transitionDistanceMultiplier;\r\n }\r\n\r\n public async dbToCartographicFromGcs(db: XYAndZ[]): Promise<Cartographic[]> {\r\n const scratch = new Point3d();\r\n const promises = db.map(async (p) => {\r\n return this.cartesianRange.containsPoint(Point3d.createFrom(p, scratch)) ? this._iModel.spatialToCartographic(p) : this.dbToCartographic(p);\r\n });\r\n\r\n return Promise.all(promises);\r\n }\r\n\r\n public dbToCartographic(db: XYAndZ, result?: Cartographic): Cartographic {\r\n if (undefined === result)\r\n result = Cartographic.createZero();\r\n\r\n if (this.globeMode === GlobeMode.Plane) {\r\n const mercatorFraction = this._mercatorFractionToDb.multiplyInversePoint3d(db)!;\r\n return this._mercatorTilingScheme.fractionToCartographic(mercatorFraction.x, mercatorFraction.y, result, mercatorFraction.z);\r\n } else {\r\n const ecef = this._ecefToDb.multiplyInversePoint3d(db)!;\r\n return Cartographic.fromEcef(ecef, result)!;\r\n }\r\n }\r\n\r\n public async cartographicToDbFromGcs(cartographic: Cartographic[]): Promise<Point3d[]> {\r\n let db;\r\n if (this.globeMode === GlobeMode.Plane) {\r\n const fraction = Point2d.create(0, 0);\r\n db = cartographic.map((p) => {\r\n this._mercatorTilingScheme.cartographicToFraction(p.latitude, p.longitude, fraction);\r\n return this._mercatorFractionToDb.multiplyXYZ(fraction.x, fraction.y, p.height);\r\n });\r\n } else {\r\n db = cartographic.map((p) => this._ecefToDb.multiplyPoint3d(p.toEcef())!);\r\n }\r\n\r\n if (this._iModel.noGcsDefined)\r\n return db;\r\n\r\n const promises = db.map(async (p, i) => {\r\n return this.cartesianRange.containsPoint(p) ? this._iModel.cartographicToSpatialFromGcs(cartographic[i]) : p;\r\n });\r\n\r\n return Promise.all(promises);\r\n }\r\n\r\n public cartographicToDb(cartographic: Cartographic, result?: Point3d): Point3d {\r\n if (this.globeMode === GlobeMode.Plane) {\r\n const fraction = Point2d.create(0, 0);\r\n this._mercatorTilingScheme.cartographicToFraction(cartographic.latitude, cartographic.longitude, fraction);\r\n return this._mercatorFractionToDb.multiplyXYZ(fraction.x, fraction.y, cartographic.height, result);\r\n } else {\r\n return this._ecefToDb.multiplyPoint3d(cartographic.toEcef())!;\r\n }\r\n }\r\n\r\n public getEarthEllipsoid(radiusOffset = 0): Ellipsoid {\r\n const equatorRadius = Constant.earthRadiusWGS84.equator + radiusOffset, polarRadius = Constant.earthRadiusWGS84.polar + radiusOffset;\r\n return Ellipsoid.createCenterMatrixRadii(this.globeOrigin, this.globeMatrix, equatorRadius, equatorRadius, polarRadius);\r\n }\r\n\r\n public getPlane(offset = 0) {\r\n return Plane3dByOriginAndUnitNormal.create(Point3d.create(0, 0, this._bimElevationBias + offset), Vector3d.create(0, 0, 1))!;\r\n }\r\n\r\n public getRayIntersection(ray: Ray3d, positiveOnly: boolean): Ray3d | undefined {\r\n let intersect;\r\n if (this.globeMode === GlobeMode.Ellipsoid) {\r\n const ellipsoid = this.geometry as Ellipsoid;\r\n BackgroundMapGeometry._scratchRayAngles.length = 0;\r\n BackgroundMapGeometry._scratchRayFractions.length = 0;\r\n\r\n const count = ellipsoid.intersectRay(ray, BackgroundMapGeometry._scratchRayFractions, undefined, BackgroundMapGeometry._scratchRayAngles);\r\n let intersectDistance;\r\n for (let i = 0; i < count; i++) {\r\n const thisFraction = BackgroundMapGeometry._scratchRayFractions[i];\r\n if ((!positiveOnly || thisFraction > 0) && (undefined === intersectDistance || thisFraction < intersectDistance)) {\r\n intersectDistance = thisFraction;\r\n intersect = scratchIntersectRay;\r\n ellipsoid.radiansToUnitNormalRay(BackgroundMapGeometry._scratchRayAngles[i].longitudeRadians, BackgroundMapGeometry._scratchRayAngles[i].latitudeRadians, intersect);\r\n if (intersect.direction.dotProduct(ray.direction) < 0) {\r\n if (this.cartesianRange.containsPoint(intersect.origin)) { // If we're in the cartesian range, correct to planar intersection.\r\n const planeFraction = ray.intersectionWithPlane(this.cartesianPlane, scratchIntersectRay.origin);\r\n if (undefined !== planeFraction && (!positiveOnly || planeFraction > 0)) {\r\n intersect.direction.setFromVector3d(this.cartesianPlane.getNormalRef());\r\n }\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n const plane = this.geometry as Plane3dByOriginAndUnitNormal;\r\n const thisFraction = ray.intersectionWithPlane(plane, scratchIntersectRay.origin);\r\n if (undefined !== thisFraction && (!positiveOnly || thisFraction > 0)) {\r\n intersect = scratchIntersectRay;\r\n intersect.direction.setFromVector3d(plane.getNormalRef());\r\n }\r\n }\r\n return intersect;\r\n }\r\n public getPointHeight(point: Point3d): number | undefined {\r\n if (this.globeMode === GlobeMode.Ellipsoid) {\r\n const ellipsoid = this.geometry as Ellipsoid;\r\n const projected = ellipsoid.projectPointToSurface(point);\r\n if (undefined === projected)\r\n return undefined;\r\n\r\n const distance = ellipsoid.radiansToPoint(projected.longitudeRadians, projected.latitudeRadians).distance(point);\r\n const ellipsePoint = ellipsoid.transformRef.multiplyInversePoint3d(point, BackgroundMapGeometry._scratchPoint)!;\r\n return ellipsePoint.magnitude() < 1 ? -distance : distance;\r\n } else {\r\n const plane = this.geometry as Plane3dByOriginAndUnitNormal;\r\n return plane.altitude(point);\r\n }\r\n }\r\n\r\n /** @internal */\r\n public getFrustumIntersectionDepthRange(frustum: Frustum, bimRange: Range3d, heightRange?: Range1d, gridPlane?: Plane3dByOriginAndUnitNormal, doGlobalScope?: boolean): Range1d {\r\n const clipPlanes = frustum.getRangePlanes(false, false, 0);\r\n const eyePoint = frustum.getEyePoint(scratchEyePoint);\r\n const viewRotation = frustum.getRotation(scratchViewRotation);\r\n if (undefined === viewRotation)\r\n return Range1d.createNull(); // Degenerate frustum...\r\n const viewZ = viewRotation.getRow(2);\r\n const cartoRange = this.cartesianTransitionRange;\r\n const intersectRange = Range3d.createNull();\r\n const doAccumulate = ((point: Point3d) => accumulateDepthRange(point, viewRotation, intersectRange));\r\n\r\n if (gridPlane)\r\n accumulateFrustumPlaneDepthRange(frustum, gridPlane, viewRotation, intersectRange, eyePoint);\r\n if (this.geometry instanceof Plane3dByOriginAndUnitNormal) {\r\n // Intersection with a planar background projection...\r\n const heights = heightRange ? [heightRange.low, heightRange.high] : [0];\r\n for (const height of heights) {\r\n accumulateFrustumPlaneDepthRange(frustum, this.getPlane(height), viewRotation, intersectRange, eyePoint);\r\n }\r\n } else {\r\n const minOffset = heightRange ? heightRange.low : 0, maxOffset = (heightRange ? heightRange.high : 0) + this.cartesianChordHeight;\r\n const radiusOffsets = [minOffset, maxOffset];\r\n\r\n // If we are doing global scope then include minimum ellipsoid that represents the chordal approximation of the low level tiles.\r\n // this substantially expands the frustum so don't do it for non-global views, but this clipping out the low level tiles.\r\n if (doGlobalScope)\r\n radiusOffsets.push(minOffset - this.maxGeometryChordHeight);\r\n\r\n const toView = Transform.createRefs(Point3d.createZero(), viewRotation);\r\n const eyePoint4d = eyePoint ? Point4d.createFromPointAndWeight(eyePoint, 1) : Point4d.createFromPointAndWeight(viewZ, 0);\r\n\r\n for (const radiusOffset of radiusOffsets) {\r\n const ellipsoid = this.getEarthEllipsoid(radiusOffset);\r\n const isInside = eyePoint && ellipsoid.worldToLocal(eyePoint)!.magnitude() < 1.0;\r\n const center = ellipsoid.localToWorld(scratchZeroPoint, scratchCenterPoint);\r\n const clipPlaneCount = clipPlanes.planes.length;\r\n\r\n // Extrema...\r\n let angles, extremaPoint;\r\n if (undefined !== (angles = ellipsoid.surfaceNormalToAngles(viewZ)) &&\r\n undefined !== (extremaPoint = ellipsoid.radiansToPoint(angles.longitudeRadians, angles.latitudeRadians)) &&\r\n (eyePoint === undefined || viewZ.dotProductStartEnd(extremaPoint, eyePoint) > 0) &&\r\n clipPlanes.classifyPointContainment([extremaPoint], false) !== ClipPlaneContainment.StronglyOutside)\r\n doAccumulate(extremaPoint);\r\n\r\n if (isInside) {\r\n if (eyePoint)\r\n doAccumulate(eyePoint);\r\n } else {\r\n const silhouette = ellipsoid.silhouetteArc(eyePoint4d);\r\n if (silhouette !== undefined) {\r\n silhouette.perpendicularVector.clone(scratchSilhouetteNormal);\r\n // Push the silhouette plane as clip so that we do not include geometry at other side of ellipsoid.\r\n // First make sure that it is pointing in the right direction.\r\n if (eyePoint) {\r\n // Clip toward eye.\r\n if (scratchSilhouetteNormal.dotProduct(viewZ) < 0)\r\n scratchSilhouetteNormal.negate(scratchSilhouetteNormal);\r\n } else {\r\n /* If parallel projection - clip toward side of ellipsoid with BIM geometry */\r\n if (Vector3d.createStartEnd(silhouette.center, bimRange.center).dotProduct(scratchSilhouetteNormal) < 0)\r\n scratchSilhouetteNormal.negate(scratchSilhouetteNormal);\r\n }\r\n clipPlanes.planes.push(ClipPlane.createNormalAndDistance(scratchSilhouetteNormal, scratchSilhouetteNormal.dotProduct(silhouette.center))!);\r\n } else {\r\n clipPlanes.planes.push(ClipPlane.createNormalAndPoint(viewZ, center)!);\r\n }\r\n }\r\n if (!isInside || radiusOffset === radiusOffsets[0]) {\r\n // Intersections of ellipsoid with frustum planes...\r\n const viewingInside = eyePoint !== undefined && viewZ.dotProduct(Vector3d.createStartEnd(center, eyePoint)) < 0;\r\n if (eyePoint === undefined || !isInside || viewingInside) {\r\n for (const clipPlane of clipPlanes.planes) {\r\n const plane = clipPlane.getPlane3d();\r\n const arc = ellipsoid.createPlaneSection(plane);\r\n if (undefined !== arc) {\r\n arc.announceClipIntervals(clipPlanes, (a0: number, a1: number, cp: CurvePrimitive) => {\r\n if (Math.abs(a1 - a0) < 1.0E-8) {\r\n doAccumulate(cp.fractionToPoint(a0)); // Tiny sweep - avoid problem with rangeMethod (not worth doing anyway).\r\n } else {\r\n const segment = cp.clonePartialCurve(a0, a1);\r\n if (segment !== undefined)\r\n segment.extendRange(intersectRange, toView);\r\n\r\n }\r\n });\r\n }\r\n }\r\n }\r\n // Intersections of the cartesian region with frustum planes.\r\n scratchCartoRectangle.resize(0);\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.low.y, z: radiusOffset });\r\n scratchCartoRectangle.push({ x: cartoRange.high.x, y: cartoRange.low.y, z: radiusOffset });\r\n scratchCartoRectangle.push({ x: cartoRange.high.x, y: cartoRange.high.y, z: radiusOffset });\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.high.y, z: radiusOffset });\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.low.y, z: radiusOffset });\r\n\r\n clipPlanes.clipConvexPolygonInPlace(scratchCartoRectangle, scratchWorkArray);\r\n for (let i = 0; i < scratchCartoRectangle.length; i++)\r\n doAccumulate(scratchCartoRectangle.getPoint3dAtUncheckedPointIndex(i));\r\n while (clipPlanes.planes.length > clipPlaneCount) // Remove pushed silhouette plane.\r\n clipPlanes.planes.pop();\r\n }\r\n }\r\n }\r\n\r\n if (intersectRange.zLength() < 5) {\r\n // For the case where the fitted depth is small (less than 5 meters) we must be viewing planar projection or the\r\n // planar portion of the iModel in plan view. In this case use a constant (arbitrarily 100 meters) depth so that the frustum\r\n // Z is doesn't change and cause nearly planar geometry to jitter in Z buffer.\r\n const zCenter = (intersectRange.low.z + intersectRange.high.z) / 2;\r\n const zExpand = 50;\r\n return Range1d.createXX(zCenter - zExpand, zCenter + zExpand);\r\n } else {\r\n const diagonal = intersectRange.diagonal(scratchVector).magnitudeXY();\r\n const expansion = diagonal * .01;\r\n return Range1d.createXX(intersectRange.low.z - expansion, intersectRange.high.z + expansion);\r\n }\r\n }\r\n\r\n public addFrustumDecorations(builder: GraphicBuilder, frustum: Frustum) {\r\n if (this.geometry instanceof Ellipsoid) {\r\n const ellipsoid = this.geometry;\r\n const clipPlanes = frustum.getRangePlanes(false, false, 0);\r\n const viewRotation = frustum.getRotation()!;\r\n const eyePoint = frustum.getEyePoint(scratchEyePoint);\r\n const viewZ = viewRotation.getRow(2);\r\n const eyePoint4d = eyePoint ? Point4d.createFromPointAndWeight(eyePoint, 1) : Point4d.createFromPointAndWeight(viewZ, 0);\r\n const isInside = eyePoint && ellipsoid.worldToLocal(eyePoint)!.magnitude() < 1.0;\r\n const center = ellipsoid.localToWorld(scratchZeroPoint, scratchCenterPoint);\r\n const cartoRange = this.cartesianTransitionRange;\r\n\r\n if (!isInside) {\r\n const silhouette = ellipsoid.silhouetteArc(eyePoint4d);\r\n if (silhouette !== undefined) {\r\n silhouette.perpendicularVector.clone(scratchSilhouetteNormal);\r\n if (scratchSilhouetteNormal.dotProduct(viewZ) < 0)\r\n scratchSilhouetteNormal.negate(scratchSilhouetteNormal);\r\n clipPlanes.planes.push(ClipPlane.createNormalAndDistance(scratchSilhouetteNormal, scratchSilhouetteNormal.dotProduct(silhouette.center))!);\r\n } else {\r\n clipPlanes.planes.push(ClipPlane.createNormalAndPoint(viewZ, center)!);\r\n }\r\n\r\n const ellipsoidColor = ColorDef.create(ColorByName.yellow);\r\n builder.setSymbology(ellipsoidColor, ellipsoidColor, 1, LinePixels.Code2);\r\n for (const clipPlane of clipPlanes.planes) {\r\n const plane = clipPlane.getPlane3d();\r\n const arc = ellipsoid.createPlaneSection(plane);\r\n if (undefined !== arc) {\r\n arc.announceClipIntervals(clipPlanes, (a0: number, a1: number, cp: CurvePrimitive) => {\r\n const segment = cp.clonePartialCurve(a0, a1);\r\n if (segment !== undefined)\r\n builder.addArc(segment as Arc3d, false, false);\r\n });\r\n }\r\n\r\n // Intersections of the cartesian region with frustum planes.\r\n scratchCartoRectangle.resize(0);\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.low.y, z: 0 });\r\n scratchCartoRectangle.push({ x: cartoRange.high.x, y: cartoRange.low.y, z: 0 });\r\n scratchCartoRectangle.push({ x: cartoRange.high.x, y: cartoRange.high.y, z: 0 });\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.high.y, z: 0 });\r\n scratchCartoRectangle.push({ x: cartoRange.low.x, y: cartoRange.low.y, z: 0 });\r\n\r\n clipPlanes.clipConvexPolygonInPlace(scratchCartoRectangle, scratchWorkArray);\r\n if (scratchCartoRectangle.length > 0) {\r\n builder.addLineString(scratchCartoRectangle.getPoint3dArray());\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\n/** Calculate the ECEF to database (IModel) coordinate transform at a provided location, using the GCS of the iModel.\r\n * The transform will exactly represent the GCS at the provided location.\r\n * @public\r\n */\r\nexport async function calculateEcefToDbTransformAtLocation(originIn: Point3d, iModel: IModelConnection): Promise<Transform | undefined> {\r\n const geoConverter = iModel.noGcsDefined ? undefined : iModel.geoServices.getConverter(\"WGS84\");\r\n if (geoConverter === undefined)\r\n return undefined;\r\n\r\n const origin = Point3d.create(originIn.x, originIn.y, 0); // Always Test at zero.\r\n const eastPoint = origin.plusXYZ(1, 0, 0);\r\n const northPoint = origin.plusXYZ(0, 1, 0);\r\n\r\n const response = await geoConverter.getGeoCoordinatesFromIModelCoordinates([origin, northPoint, eastPoint]);\r\n if (response.geoCoords[0].s !== GeoCoordStatus.Success || response.geoCoords[1].s !== GeoCoordStatus.Success || response.geoCoords[2].s !== GeoCoordStatus.Success)\r\n return undefined;\r\n\r\n const geoOrigin = Point3d.fromJSON(response.geoCoords[0].p);\r\n const geoNorth = Point3d.fromJSON(response.geoCoords[1].p);\r\n const geoEast = Point3d.fromJSON(response.geoCoords[2].p);\r\n const ecefOrigin = Cartographic.fromDegrees({ longitude: geoOrigin.x, latitude: geoOrigin.y, height: geoOrigin.z }).toEcef()!;\r\n const ecefNorth = Cartographic.fromDegrees({ longitude: geoNorth.x, latitude: geoNorth.y, height: geoNorth.z }).toEcef()!;\r\n const ecefEast = Cartographic.fromDegrees({ longitude: geoEast.x, latitude: geoEast.y, height: geoEast.z }).toEcef()!;\r\n\r\n const xVector = Vector3d.createStartEnd(ecefOrigin, ecefEast);\r\n const yVector = Vector3d.createStartEnd(ecefOrigin, ecefNorth);\r\n const zVector = xVector.unitCrossProduct(yVector);\r\n if (undefined === zVector) {\r\n assert(false); // Should never occur.\r\n return undefined;\r\n }\r\n const matrix = Matrix3d.createColumns(xVector, yVector, zVector);\r\n if (matrix === undefined)\r\n return undefined;\r\n\r\n const inverse = matrix.inverse();\r\n if (inverse === undefined) {\r\n assert(false); // Should never occur.\r\n return undefined;\r\n }\r\n\r\n return Transform.createMatrixPickupPutdown(matrix, origin, ecefOrigin).inverse()!;\r\n}\r\n\r\n"]}
|
package/lib/cjs/GeoServices.d.ts
CHANGED
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { BeEvent, Dictionary, SortedArray } from "@itwin/core-bentley";
|
|
5
5
|
import { WritableXYAndZ, XYAndZ, XYZProps } from "@itwin/core-geometry";
|
|
6
|
-
import { GeoCoordinatesResponseProps, GeographicCRSProps, IModelCoordinatesResponseProps, PointWithStatus } from "@itwin/core-common";
|
|
6
|
+
import { GeoCoordinatesRequestProps, GeoCoordinatesResponseProps, GeographicCRSProps, IModelCoordinatesRequestProps, IModelCoordinatesResponseProps, PointWithStatus } from "@itwin/core-common";
|
|
7
7
|
import { IModelConnection } from "./IModelConnection";
|
|
8
8
|
/** Options used to create a [[CoordinateConverter]].
|
|
9
9
|
* @internal exported strictly for tests.
|
|
10
10
|
*/
|
|
11
11
|
export interface CoordinateConverterOptions {
|
|
12
|
-
|
|
13
|
-
iModel: IModelConnection;
|
|
12
|
+
isIModelClosed: () => boolean;
|
|
14
13
|
/** Asynchronously convert each point. The resultant array should have the same number and order of points as the input. */
|
|
15
14
|
requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;
|
|
16
15
|
/** Maximum number of points to include in each request. Default: 300. */
|
|
@@ -42,8 +41,10 @@ export declare class CoordinateConverter {
|
|
|
42
41
|
z: number;
|
|
43
42
|
};
|
|
44
43
|
protected readonly _maxPointsPerRequest: number;
|
|
45
|
-
protected readonly
|
|
44
|
+
protected readonly _isIModelClosed: () => boolean;
|
|
46
45
|
protected readonly _requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;
|
|
46
|
+
protected _redispatchOnCompletion: boolean;
|
|
47
|
+
get isIdle(): boolean;
|
|
47
48
|
protected toXYAndZ(input: XYZProps, output: WritableXYAndZ): XYAndZ;
|
|
48
49
|
constructor(opts: CoordinateConverterOptions);
|
|
49
50
|
protected dispatch(): Promise<void>;
|
|
@@ -65,6 +66,15 @@ export interface CachedIModelCoordinatesResponseProps {
|
|
|
65
66
|
/** An array of points in the input array which were not found in the cache, or undefined if all points were found in the cache. */
|
|
66
67
|
missing?: XYZProps[];
|
|
67
68
|
}
|
|
69
|
+
/** Options used to create a [[GeoConverter]].
|
|
70
|
+
* @internal exported strictly for tests.
|
|
71
|
+
*/
|
|
72
|
+
export interface GeoConverterOptions {
|
|
73
|
+
readonly datum: string;
|
|
74
|
+
isIModelClosed: () => boolean;
|
|
75
|
+
toIModelCoords: (request: IModelCoordinatesRequestProps) => Promise<PointWithStatus[]>;
|
|
76
|
+
fromIModelCoords: (request: GeoCoordinatesRequestProps) => Promise<PointWithStatus[]>;
|
|
77
|
+
}
|
|
68
78
|
/** An object capable of communicating with the backend to convert between coordinates in a geographic coordinate system and coordinates in an [[IModelConnection]]'s own coordinate system.
|
|
69
79
|
* @see [[GeoServices.getConverter]] to obtain a converter.
|
|
70
80
|
* @see [GeographicCRS]($common) for more information about geographic coordinate reference systems.
|
|
@@ -73,8 +83,12 @@ export interface CachedIModelCoordinatesResponseProps {
|
|
|
73
83
|
export declare class GeoConverter {
|
|
74
84
|
private readonly _geoToIModel;
|
|
75
85
|
private readonly _iModelToGeo;
|
|
86
|
+
/** Used for removing this converter from GeoServices' cache after all requests are completed.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
readonly onAllRequestsCompleted: BeEvent<() => void>;
|
|
76
90
|
/** @internal */
|
|
77
|
-
constructor(
|
|
91
|
+
constructor(opts: GeoConverterOptions);
|
|
78
92
|
/** Convert the specified geographic coordinates into iModel coordinates. */
|
|
79
93
|
convertToIModelCoords(geoPoints: XYZProps[]): Promise<PointWithStatus[]>;
|
|
80
94
|
/** Convert the specified iModel coordinates into geographic coordinates. */
|
|
@@ -83,17 +97,33 @@ export declare class GeoConverter {
|
|
|
83
97
|
getIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): Promise<IModelCoordinatesResponseProps>;
|
|
84
98
|
/** @internal */
|
|
85
99
|
getGeoCoordinatesFromIModelCoordinates(iModelPoints: XYZProps[]): Promise<GeoCoordinatesResponseProps>;
|
|
100
|
+
private checkCompletion;
|
|
86
101
|
/** @internal */
|
|
87
102
|
getCachedIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): CachedIModelCoordinatesResponseProps;
|
|
88
103
|
}
|
|
104
|
+
/** @internal */
|
|
105
|
+
export type GeoServicesOptions = Omit<GeoConverterOptions, "datum">;
|
|
89
106
|
/** The Geographic Services available for an [[IModelConnection]].
|
|
90
107
|
* @see [[IModelConnection.geoServices]] to obtain the GeoServices for a specific iModel.
|
|
91
108
|
* @public
|
|
92
109
|
*/
|
|
93
110
|
export declare class GeoServices {
|
|
94
|
-
private
|
|
111
|
+
private readonly _options;
|
|
112
|
+
/** Each GeoConverter has its own independent request queue and cache of previously-converted points.
|
|
113
|
+
* Some callers like RealityTileTree obtain a single GeoConverter and reuse it throughout their own lifetime. Therefore they benefit from both batching and caching, and
|
|
114
|
+
* the cache gets deleted once the RealityTileTree becomes disused.
|
|
115
|
+
*
|
|
116
|
+
* Other callers like IModelConnection.spatialToCartographic obtain a new GeoConverter every time they need one, use it to convert a single point(!), and then discard the converter.
|
|
117
|
+
* This entirely prevents batching - e.g., calling spatialToCartographic 20 times in one frame results in 20 http requests.
|
|
118
|
+
* To address that, we cache each GeoConverter returned by getConverter until it has converted at least one point and has no further outstanding conversion requests.
|
|
119
|
+
* In this way, the converter lives for as long as (and no longer than) any caller is awaiting conversion to/from its datum - it and its cache are deleted once it becomes disused.
|
|
120
|
+
* This makes the coordinate caching generally less useful, but at least bounded - and maximizes batching of requests.
|
|
121
|
+
*/
|
|
122
|
+
private readonly _cache;
|
|
123
|
+
/** @internal */
|
|
124
|
+
constructor(options: GeoServicesOptions);
|
|
95
125
|
/** @internal */
|
|
96
|
-
|
|
126
|
+
static createForIModel(iModel: IModelConnection): GeoServices;
|
|
97
127
|
/** Obtain a converter that can convert between a geographic coordinate system and the iModel's own coordinate system.
|
|
98
128
|
* @param datumOrGCRS The name or JSON representation of the geographic coordinate system datum - for example, "WGS84".
|
|
99
129
|
* @returns a converter, or `undefined` if the iModel is not open.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeoServices.d.ts","sourceRoot":"","sources":["../../src/GeoServices.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EACG,OAAO,EAAE,UAAU,EAAU,WAAW,EACjD,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,2BAA2B,EAAkB,kBAAkB,EAAE,8BAA8B,
|
|
1
|
+
{"version":3,"file":"GeoServices.d.ts","sourceRoot":"","sources":["../../src/GeoServices.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EACG,OAAO,EAAE,UAAU,EAAU,WAAW,EACjD,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,0BAA0B,EAAE,2BAA2B,EAAkB,kBAAkB,EAAE,6BAA6B,EAAE,8BAA8B,EAClI,eAAe,EACxC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,MAAM,OAAO,CAAC;IAC9B,2HAA2H;IAC3H,aAAa,EAAE,CAAC,MAAM,EAAE,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E,QAAQ,EAAE,GAAG,OAAO,CAAC,2BAA2B,CAAC;IASnH,OAAO,CAAC,eAAe;IAKvB,gBAAgB;IACT,4CAA4C,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,oCAAoC;CAGjH;AAED,gBAAgB;AAChB,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;AAEpE;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAE1D,gBAAgB;gBACG,OAAO,EAAE,kBAAkB;IAI9C,gBAAgB;WACF,eAAe,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW;IAgBpE;;;;OAIG;IACI,YAAY,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,YAAY,GAAG,SAAS;CAmBzF"}
|
package/lib/cjs/GeoServices.js
CHANGED
|
@@ -32,6 +32,9 @@ function cloneXYAndZ(xyz) {
|
|
|
32
32
|
* @internal exported strictly for tests.
|
|
33
33
|
*/
|
|
34
34
|
class CoordinateConverter {
|
|
35
|
+
get isIdle() {
|
|
36
|
+
return "idle" === this._state;
|
|
37
|
+
}
|
|
35
38
|
toXYAndZ(input, output) {
|
|
36
39
|
if (Array.isArray(input)) {
|
|
37
40
|
output.x = input[0] ?? 0;
|
|
@@ -51,8 +54,12 @@ class CoordinateConverter {
|
|
|
51
54
|
this._onCompleted = new core_bentley_1.BeEvent();
|
|
52
55
|
// Used for creating cache keys (XYAndZ) from XYZProps without having to allocate temporary objects.
|
|
53
56
|
this._scratchXYZ = { x: 0, y: 0, z: 0 };
|
|
57
|
+
// If true, [[dispatch]] will schedule another dispatch after it receives a response.
|
|
58
|
+
// This is needed when all the points requested after the most recent dispatch were included in the currently-in-flight request -
|
|
59
|
+
// _pending will be empty but new callers will be awaiting the results of the in-flight request.
|
|
60
|
+
this._redispatchOnCompletion = false;
|
|
54
61
|
this._maxPointsPerRequest = Math.max(1, opts.maxPointsPerRequest ?? 300);
|
|
55
|
-
this.
|
|
62
|
+
this._isIModelClosed = opts.isIModelClosed;
|
|
56
63
|
this._requestPoints = opts.requestPoints;
|
|
57
64
|
this._cache = new core_bentley_1.Dictionary(compareXYAndZ, cloneXYAndZ);
|
|
58
65
|
this._pending = new core_bentley_1.SortedArray(compareXYAndZ, false, cloneXYAndZ);
|
|
@@ -60,7 +67,7 @@ class CoordinateConverter {
|
|
|
60
67
|
}
|
|
61
68
|
async dispatch() {
|
|
62
69
|
(0, core_bentley_1.assert)(this._state === "scheduled");
|
|
63
|
-
if (this.
|
|
70
|
+
if (this._isIModelClosed() || this._pending.isEmpty) {
|
|
64
71
|
this._state = "idle";
|
|
65
72
|
this._onCompleted.raiseEvent();
|
|
66
73
|
return;
|
|
@@ -79,7 +86,7 @@ class CoordinateConverter {
|
|
|
79
86
|
for (let i = 0; i < inflight.length; i += this._maxPointsPerRequest) {
|
|
80
87
|
const requests = inflight.slice(i, i + this._maxPointsPerRequest).extractArray();
|
|
81
88
|
const promise = this._requestPoints(requests).then((results) => {
|
|
82
|
-
if (this.
|
|
89
|
+
if (this._isIModelClosed())
|
|
83
90
|
return;
|
|
84
91
|
if (results.length !== requests.length)
|
|
85
92
|
core_bentley_1.Logger.logError(`${FrontendLoggerCategory_1.FrontendLoggerCategory.Package}.geoservices`, `requested conversion of ${requests.length} points, but received ${results.length} points`);
|
|
@@ -97,8 +104,10 @@ class CoordinateConverter {
|
|
|
97
104
|
this._state = "idle";
|
|
98
105
|
this._inflight.clear();
|
|
99
106
|
// If any more pending conversions arrived while awaiting this request, schedule another request.
|
|
100
|
-
if (!this._pending.isEmpty)
|
|
107
|
+
if (!this._pending.isEmpty || this._redispatchOnCompletion) {
|
|
108
|
+
this._redispatchOnCompletion = false;
|
|
101
109
|
this.scheduleDispatch(); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
110
|
+
}
|
|
102
111
|
// Resolve promises of all callers who were awaiting this request.
|
|
103
112
|
onCompleted.raiseEvent();
|
|
104
113
|
}
|
|
@@ -110,7 +119,9 @@ class CoordinateConverter {
|
|
|
110
119
|
const xyz = this.toXYAndZ(point, this._scratchXYZ);
|
|
111
120
|
if (this._cache.get(xyz))
|
|
112
121
|
++numInCache;
|
|
113
|
-
else if (
|
|
122
|
+
else if (this._inflight.contains(xyz))
|
|
123
|
+
this._redispatchOnCompletion = true;
|
|
124
|
+
else
|
|
114
125
|
this._pending.insert(xyz);
|
|
115
126
|
}
|
|
116
127
|
return numInCache;
|
|
@@ -172,25 +183,19 @@ exports.CoordinateConverter = CoordinateConverter;
|
|
|
172
183
|
*/
|
|
173
184
|
class GeoConverter {
|
|
174
185
|
/** @internal */
|
|
175
|
-
constructor(
|
|
176
|
-
|
|
186
|
+
constructor(opts) {
|
|
187
|
+
/** Used for removing this converter from GeoServices' cache after all requests are completed.
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
this.onAllRequestsCompleted = new core_bentley_1.BeEvent();
|
|
191
|
+
const isIModelClosed = opts.isIModelClosed;
|
|
177
192
|
this._geoToIModel = new CoordinateConverter({
|
|
178
|
-
|
|
179
|
-
requestPoints: async (geoCoords) => {
|
|
180
|
-
const request = { source: datum, geoCoords };
|
|
181
|
-
const rpc = core_common_1.IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);
|
|
182
|
-
const response = await rpc.getIModelCoordinatesFromGeoCoordinates(iModel.getRpcProps(), request);
|
|
183
|
-
return response.iModelCoords;
|
|
184
|
-
},
|
|
193
|
+
isIModelClosed,
|
|
194
|
+
requestPoints: async (geoCoords) => opts.toIModelCoords({ source: opts.datum, geoCoords }),
|
|
185
195
|
});
|
|
186
196
|
this._iModelToGeo = new CoordinateConverter({
|
|
187
|
-
|
|
188
|
-
requestPoints: async (iModelCoords) => {
|
|
189
|
-
const request = { target: datum, iModelCoords };
|
|
190
|
-
const rpc = core_common_1.IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);
|
|
191
|
-
const response = await rpc.getGeoCoordinatesFromIModelCoordinates(iModel.getRpcProps(), request);
|
|
192
|
-
return response.geoCoords;
|
|
193
|
-
},
|
|
197
|
+
isIModelClosed,
|
|
198
|
+
requestPoints: async (iModelCoords) => opts.fromIModelCoords({ target: opts.datum, iModelCoords }),
|
|
194
199
|
});
|
|
195
200
|
}
|
|
196
201
|
/** Convert the specified geographic coordinates into iModel coordinates. */
|
|
@@ -206,6 +211,7 @@ class GeoConverter {
|
|
|
206
211
|
/** @internal */
|
|
207
212
|
async getIModelCoordinatesFromGeoCoordinates(geoPoints) {
|
|
208
213
|
const result = await this._geoToIModel.convert(geoPoints);
|
|
214
|
+
this.checkCompletion();
|
|
209
215
|
return {
|
|
210
216
|
iModelCoords: result.points,
|
|
211
217
|
fromCache: result.fromCache,
|
|
@@ -214,11 +220,16 @@ class GeoConverter {
|
|
|
214
220
|
/** @internal */
|
|
215
221
|
async getGeoCoordinatesFromIModelCoordinates(iModelPoints) {
|
|
216
222
|
const result = await this._iModelToGeo.convert(iModelPoints);
|
|
223
|
+
this.checkCompletion();
|
|
217
224
|
return {
|
|
218
225
|
geoCoords: result.points,
|
|
219
226
|
fromCache: result.fromCache,
|
|
220
227
|
};
|
|
221
228
|
}
|
|
229
|
+
checkCompletion() {
|
|
230
|
+
if (this._geoToIModel.isIdle && this._iModelToGeo.isIdle)
|
|
231
|
+
this.onAllRequestsCompleted.raiseEvent();
|
|
232
|
+
}
|
|
222
233
|
/** @internal */
|
|
223
234
|
getCachedIModelCoordinatesFromGeoCoordinates(geoPoints) {
|
|
224
235
|
return this._geoToIModel.findCached(geoPoints);
|
|
@@ -231,8 +242,35 @@ exports.GeoConverter = GeoConverter;
|
|
|
231
242
|
*/
|
|
232
243
|
class GeoServices {
|
|
233
244
|
/** @internal */
|
|
234
|
-
constructor(
|
|
235
|
-
|
|
245
|
+
constructor(options) {
|
|
246
|
+
/** Each GeoConverter has its own independent request queue and cache of previously-converted points.
|
|
247
|
+
* Some callers like RealityTileTree obtain a single GeoConverter and reuse it throughout their own lifetime. Therefore they benefit from both batching and caching, and
|
|
248
|
+
* the cache gets deleted once the RealityTileTree becomes disused.
|
|
249
|
+
*
|
|
250
|
+
* Other callers like IModelConnection.spatialToCartographic obtain a new GeoConverter every time they need one, use it to convert a single point(!), and then discard the converter.
|
|
251
|
+
* This entirely prevents batching - e.g., calling spatialToCartographic 20 times in one frame results in 20 http requests.
|
|
252
|
+
* To address that, we cache each GeoConverter returned by getConverter until it has converted at least one point and has no further outstanding conversion requests.
|
|
253
|
+
* In this way, the converter lives for as long as (and no longer than) any caller is awaiting conversion to/from its datum - it and its cache are deleted once it becomes disused.
|
|
254
|
+
* This makes the coordinate caching generally less useful, but at least bounded - and maximizes batching of requests.
|
|
255
|
+
*/
|
|
256
|
+
this._cache = new Map();
|
|
257
|
+
this._options = options;
|
|
258
|
+
}
|
|
259
|
+
/** @internal */
|
|
260
|
+
static createForIModel(iModel) {
|
|
261
|
+
return new GeoServices({
|
|
262
|
+
isIModelClosed: () => iModel.isClosed,
|
|
263
|
+
toIModelCoords: async (request) => {
|
|
264
|
+
const rpc = core_common_1.IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);
|
|
265
|
+
const response = await rpc.getIModelCoordinatesFromGeoCoordinates(iModel.getRpcProps(), request);
|
|
266
|
+
return response.iModelCoords;
|
|
267
|
+
},
|
|
268
|
+
fromIModelCoords: async (request) => {
|
|
269
|
+
const rpc = core_common_1.IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);
|
|
270
|
+
const response = await rpc.getGeoCoordinatesFromIModelCoordinates(iModel.getRpcProps(), request);
|
|
271
|
+
return response.geoCoords;
|
|
272
|
+
},
|
|
273
|
+
});
|
|
236
274
|
}
|
|
237
275
|
/** Obtain a converter that can convert between a geographic coordinate system and the iModel's own coordinate system.
|
|
238
276
|
* @param datumOrGCRS The name or JSON representation of the geographic coordinate system datum - for example, "WGS84".
|
|
@@ -240,7 +278,19 @@ class GeoServices {
|
|
|
240
278
|
* @note A [[BlankConnection]] has no connection to a backend, so it is never "open"; therefore it always returns `undefined`.
|
|
241
279
|
*/
|
|
242
280
|
getConverter(datumOrGCRS) {
|
|
243
|
-
|
|
281
|
+
if (this._options.isIModelClosed())
|
|
282
|
+
return undefined;
|
|
283
|
+
const datum = (typeof datumOrGCRS === "object" ? JSON.stringify(datumOrGCRS) : datumOrGCRS) ?? "";
|
|
284
|
+
let converter = this._cache.get(datum);
|
|
285
|
+
if (!converter) {
|
|
286
|
+
converter = new GeoConverter({ ...this._options, datum });
|
|
287
|
+
this._cache.set(datum, converter);
|
|
288
|
+
converter.onAllRequestsCompleted.addOnce(() => {
|
|
289
|
+
if (converter === this._cache.get(datum))
|
|
290
|
+
this._cache.delete(datum);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return converter;
|
|
244
294
|
}
|
|
245
295
|
}
|
|
246
296
|
exports.GeoServices = GeoServices;
|