|
|
|
@ -2928,11 +2928,10 @@ export default { |
|
|
|
const rawMeters = Cesium.Cartesian3.distance(leftCartesian, rightCartesian) |
|
|
|
if (rawMeters > 0) { |
|
|
|
const metersPerPx = rawMeters / barPx |
|
|
|
const scaleRatio = this.calculateScaleRatio(metersPerPx) |
|
|
|
const pixelsPerCm = this.getPixelsPerCm() |
|
|
|
const widthPx = Math.min(120, Math.max(40, Math.round(pixelsPerCm))) |
|
|
|
const text = `1:${scaleRatio}${this.currentScaleUnit}` |
|
|
|
return { text, widthPx, niceMeters: rawMeters } |
|
|
|
const niceMeters = this.niceScaleValue(rawMeters) |
|
|
|
const widthPx = Math.round((niceMeters / rawMeters) * barPx) |
|
|
|
const text = this.formatScaleText(niceMeters) |
|
|
|
return { text, widthPx, niceMeters } |
|
|
|
} |
|
|
|
} |
|
|
|
// 2D/WebMercator 备用:用整屏宽度对应的地理范围计算(四角 pick 得到视口矩形) |
|
|
|
@ -2942,11 +2941,11 @@ export default { |
|
|
|
const widthMeters = Cesium.Cartesian3.distance(leftBottom, rightBottom) |
|
|
|
if (widthMeters > 0) { |
|
|
|
const metersPerPx = widthMeters / w |
|
|
|
const scaleRatio = this.calculateScaleRatio(metersPerPx) |
|
|
|
const pixelsPerCm = this.getPixelsPerCm() |
|
|
|
const widthPx = Math.min(120, Math.max(40, Math.round(pixelsPerCm))) |
|
|
|
const text = `1:${scaleRatio}${this.currentScaleUnit}` |
|
|
|
return { text, widthPx, niceMeters: widthMeters } |
|
|
|
const rawMeters = metersPerPx * barPx |
|
|
|
const niceMeters = this.niceScaleValue(rawMeters) |
|
|
|
const widthPx = Math.round(niceMeters / metersPerPx) |
|
|
|
const text = this.formatScaleText(niceMeters) |
|
|
|
return { text, widthPx, niceMeters } |
|
|
|
} |
|
|
|
} |
|
|
|
// 最后备用:从 2D 相机视锥估算(正交宽度 -> 米) |
|
|
|
@ -2954,11 +2953,11 @@ export default { |
|
|
|
const frustumWidth = camera.frustum.right - camera.frustum.left |
|
|
|
if (frustumWidth > 0) { |
|
|
|
const metersPerPx = frustumWidth / w |
|
|
|
const scaleRatio = this.calculateScaleRatio(metersPerPx) |
|
|
|
const pixelsPerCm = this.getPixelsPerCm() |
|
|
|
const widthPx = Math.min(120, Math.max(40, Math.round(pixelsPerCm))) |
|
|
|
const text = `1:${scaleRatio}${this.currentScaleUnit}` |
|
|
|
return { text, widthPx, niceMeters: frustumWidth } |
|
|
|
const rawMeters = metersPerPx * barPx |
|
|
|
const niceMeters = this.niceScaleValue(rawMeters) |
|
|
|
const widthPx = Math.round(niceMeters / metersPerPx) |
|
|
|
const text = this.formatScaleText(niceMeters) |
|
|
|
return { text, widthPx, niceMeters } |
|
|
|
} |
|
|
|
} |
|
|
|
return null |
|
|
|
@ -2991,6 +2990,15 @@ export default { |
|
|
|
} |
|
|
|
return best |
|
|
|
}, |
|
|
|
/** 格式化比例尺文本 */ |
|
|
|
formatScaleText(meters) { |
|
|
|
if (meters >= 1000) { |
|
|
|
const kmValue = (meters / 1000).toFixed(0) |
|
|
|
return `${kmValue}km` |
|
|
|
} else { |
|
|
|
return `${meters}m` |
|
|
|
} |
|
|
|
}, |
|
|
|
updateScaleBar() { |
|
|
|
if (this.useCustomScale && this.customScaleText) { |
|
|
|
this.scaleBarText = `${this.customScaleText}${this.currentScaleUnit}` |
|
|
|
|