huweili-cesium 1.2.97 → 1.2.98
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/js/glbInfoBadge.js +29 -11
- package/package.json +1 -1
package/js/glbInfoBadge.js
CHANGED
|
@@ -9,7 +9,10 @@ import { getDroneLabelBatchManager } from './cardPool'
|
|
|
9
9
|
|
|
10
10
|
const STYLE_ID = 'glb-info-badge-style'
|
|
11
11
|
const DEFAULT_LABEL_OFFSET = 1
|
|
12
|
-
const DEFAULT_PIXEL_GAP =
|
|
12
|
+
const DEFAULT_PIXEL_GAP = 0
|
|
13
|
+
const DEFAULT_HEIGHT_SCALE = 0.72
|
|
14
|
+
/** 包围球半径折算到车顶的系数(中心点已在模型中部,无需再加整颗半径) */
|
|
15
|
+
const BOUNDING_SPHERE_TOP_FACTOR = 0.22
|
|
13
16
|
|
|
14
17
|
const scratchBoundingSphere = new Cesium.BoundingSphere()
|
|
15
18
|
const scratchEnu = new Cesium.Matrix4()
|
|
@@ -174,8 +177,11 @@ const resolveModelTopWorldPosition = (map, entity, basePos, fallbackOffset) => {
|
|
|
174
177
|
if (entity && dataSourceDisplay?.getBoundingSphere) {
|
|
175
178
|
const ok = dataSourceDisplay.getBoundingSphere(entity, true, scratchBoundingSphere)
|
|
176
179
|
if (ok && scratchBoundingSphere.radius > 0) {
|
|
177
|
-
Cesium.Cartesian3.
|
|
178
|
-
|
|
180
|
+
Cesium.Cartesian3.subtract(scratchBoundingSphere.center, basePos, scratchOffset)
|
|
181
|
+
const centerAlongUp = Math.max(0, Cesium.Cartesian3.dot(scratchOffset, scratchUp))
|
|
182
|
+
const topAlongUp = centerAlongUp + scratchBoundingSphere.radius * BOUNDING_SPHERE_TOP_FACTOR
|
|
183
|
+
Cesium.Cartesian3.multiplyByScalar(scratchUp, topAlongUp, scratchOffset)
|
|
184
|
+
return Cesium.Cartesian3.add(basePos, scratchOffset, scratchTop)
|
|
179
185
|
}
|
|
180
186
|
}
|
|
181
187
|
|
|
@@ -190,28 +196,37 @@ const resolveModelTopWorldPosition = (map, entity, basePos, fallbackOffset) => {
|
|
|
190
196
|
* @param {Cesium.Cartesian3} topWorldPos
|
|
191
197
|
* @param {number} minPixelSize
|
|
192
198
|
* @param {number} pixelGap
|
|
199
|
+
* @param {number} heightScale
|
|
193
200
|
* @returns {{ x: number, y: number }|null}
|
|
194
201
|
*/
|
|
195
|
-
const resolveBadgeScreenPosition = (scene, basePos, topWorldPos, minPixelSize, pixelGap) => {
|
|
202
|
+
const resolveBadgeScreenPosition = (scene, basePos, topWorldPos, minPixelSize, pixelGap, heightScale) => {
|
|
196
203
|
const anchorWin = scene.cartesianToCanvasCoordinates(basePos)
|
|
197
204
|
if (!anchorWin || Number.isNaN(anchorWin.x) || Number.isNaN(anchorWin.y)) {
|
|
198
205
|
return null
|
|
199
206
|
}
|
|
200
207
|
|
|
201
|
-
const topWin = scene.cartesianToCanvasCoordinates(topWorldPos)
|
|
208
|
+
const topWin = topWorldPos ? scene.cartesianToCanvasCoordinates(topWorldPos) : null
|
|
202
209
|
let offsetY = 0
|
|
203
210
|
|
|
204
211
|
if (topWin && !Number.isNaN(topWin.y)) {
|
|
205
|
-
offsetY = anchorWin.y - topWin.y
|
|
212
|
+
offsetY = (anchorWin.y - topWin.y) * heightScale
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 包围球常大于实际 mesh,对过大偏移做软压缩
|
|
216
|
+
if (offsetY > 0 && minPixelSize > 0 && offsetY > minPixelSize * 0.5) {
|
|
217
|
+
const base = minPixelSize * 0.3
|
|
218
|
+
offsetY = base + (offsetY - base) * 0.35
|
|
206
219
|
}
|
|
207
220
|
|
|
208
|
-
// minimumPixelSize 会让远景模型在屏幕上被抬高,仅用世界高度会产生“飘”感
|
|
209
221
|
if (minPixelSize > 0) {
|
|
210
|
-
|
|
222
|
+
const visualRoofOffset = minPixelSize * 0.28
|
|
223
|
+
if (offsetY <= 0 || offsetY < visualRoofOffset) {
|
|
224
|
+
offsetY = visualRoofOffset
|
|
225
|
+
}
|
|
211
226
|
}
|
|
212
227
|
|
|
213
228
|
if (offsetY <= 0) {
|
|
214
|
-
offsetY = minPixelSize > 0 ? minPixelSize * 0.
|
|
229
|
+
offsetY = minPixelSize > 0 ? minPixelSize * 0.28 : 16
|
|
215
230
|
}
|
|
216
231
|
|
|
217
232
|
return {
|
|
@@ -230,7 +245,8 @@ const resolveBadgeScreenPosition = (scene, basePos, topWorldPos, minPixelSize, p
|
|
|
230
245
|
* @param {Function} [options.getVisible] 是否显示信息牌
|
|
231
246
|
* @param {boolean} [options.isOffline=false] true=离线,false=在线
|
|
232
247
|
* @param {number} [options.labelOffset=1] 模型未加载完成时的兜底高度(米)
|
|
233
|
-
* @param {number} [options.pixelGap=
|
|
248
|
+
* @param {number} [options.pixelGap=0] 信息牌与车顶之间的像素间距
|
|
249
|
+
* @param {number} [options.heightScale=0.72] 屏幕偏移收紧系数(越小越贴近车顶)
|
|
234
250
|
*/
|
|
235
251
|
export function createGlbInfoBadge(options = {}) {
|
|
236
252
|
const {
|
|
@@ -242,6 +258,7 @@ export function createGlbInfoBadge(options = {}) {
|
|
|
242
258
|
isOffline = false,
|
|
243
259
|
labelOffset = DEFAULT_LABEL_OFFSET,
|
|
244
260
|
pixelGap = DEFAULT_PIXEL_GAP,
|
|
261
|
+
heightScale = DEFAULT_HEIGHT_SCALE,
|
|
245
262
|
} = options
|
|
246
263
|
|
|
247
264
|
if (!map || typeof getPosition !== 'function') {
|
|
@@ -302,7 +319,8 @@ export function createGlbInfoBadge(options = {}) {
|
|
|
302
319
|
basePos,
|
|
303
320
|
topWorldPos,
|
|
304
321
|
minPixelSize,
|
|
305
|
-
pixelGap
|
|
322
|
+
pixelGap,
|
|
323
|
+
heightScale
|
|
306
324
|
)
|
|
307
325
|
|
|
308
326
|
if (!screenPos) {
|