Browse Source

比例尺改

lbj
sd 2 months ago
parent
commit
4e14d47edc
  1. 38
      ruoyi-ui/src/views/cesiumMap/index.vue
  2. 8
      ruoyi-ui/src/views/dialogs/ScaleDialog.vue

38
ruoyi-ui/src/views/cesiumMap/index.vue

@ -2928,11 +2928,10 @@ export default {
const rawMeters = Cesium.Cartesian3.distance(leftCartesian, rightCartesian) const rawMeters = Cesium.Cartesian3.distance(leftCartesian, rightCartesian)
if (rawMeters > 0) { if (rawMeters > 0) {
const metersPerPx = rawMeters / barPx const metersPerPx = rawMeters / barPx
const scaleRatio = this.calculateScaleRatio(metersPerPx) const niceMeters = this.niceScaleValue(rawMeters)
const pixelsPerCm = this.getPixelsPerCm() const widthPx = Math.round((niceMeters / rawMeters) * barPx)
const widthPx = Math.min(120, Math.max(40, Math.round(pixelsPerCm))) const text = this.formatScaleText(niceMeters)
const text = `1:${scaleRatio}${this.currentScaleUnit}` return { text, widthPx, niceMeters }
return { text, widthPx, niceMeters: rawMeters }
} }
} }
// 2D/WebMercator pick // 2D/WebMercator pick
@ -2942,11 +2941,11 @@ export default {
const widthMeters = Cesium.Cartesian3.distance(leftBottom, rightBottom) const widthMeters = Cesium.Cartesian3.distance(leftBottom, rightBottom)
if (widthMeters > 0) { if (widthMeters > 0) {
const metersPerPx = widthMeters / w const metersPerPx = widthMeters / w
const scaleRatio = this.calculateScaleRatio(metersPerPx) const rawMeters = metersPerPx * barPx
const pixelsPerCm = this.getPixelsPerCm() const niceMeters = this.niceScaleValue(rawMeters)
const widthPx = Math.min(120, Math.max(40, Math.round(pixelsPerCm))) const widthPx = Math.round(niceMeters / metersPerPx)
const text = `1:${scaleRatio}${this.currentScaleUnit}` const text = this.formatScaleText(niceMeters)
return { text, widthPx, niceMeters: widthMeters } return { text, widthPx, niceMeters }
} }
} }
// 2D -> // 2D ->
@ -2954,11 +2953,11 @@ export default {
const frustumWidth = camera.frustum.right - camera.frustum.left const frustumWidth = camera.frustum.right - camera.frustum.left
if (frustumWidth > 0) { if (frustumWidth > 0) {
const metersPerPx = frustumWidth / w const metersPerPx = frustumWidth / w
const scaleRatio = this.calculateScaleRatio(metersPerPx) const rawMeters = metersPerPx * barPx
const pixelsPerCm = this.getPixelsPerCm() const niceMeters = this.niceScaleValue(rawMeters)
const widthPx = Math.min(120, Math.max(40, Math.round(pixelsPerCm))) const widthPx = Math.round(niceMeters / metersPerPx)
const text = `1:${scaleRatio}${this.currentScaleUnit}` const text = this.formatScaleText(niceMeters)
return { text, widthPx, niceMeters: frustumWidth } return { text, widthPx, niceMeters }
} }
} }
return null return null
@ -2991,6 +2990,15 @@ export default {
} }
return best return best
}, },
/** 格式化比例尺文本 */
formatScaleText(meters) {
if (meters >= 1000) {
const kmValue = (meters / 1000).toFixed(0)
return `${kmValue}km`
} else {
return `${meters}m`
}
},
updateScaleBar() { updateScaleBar() {
if (this.useCustomScale && this.customScaleText) { if (this.useCustomScale && this.customScaleText) {
this.scaleBarText = `${this.customScaleText}${this.currentScaleUnit}` this.scaleBarText = `${this.customScaleText}${this.currentScaleUnit}`

8
ruoyi-ui/src/views/dialogs/ScaleDialog.vue

@ -60,8 +60,8 @@ export default {
return { return {
formData: { formData: {
scaleNumerator: 1, scaleNumerator: 1,
scaleDenominator: 1000, scaleDenominator: 20,
unit: 'm' unit: 'km'
}, },
rules: { rules: {
scaleNumerator: [ scaleNumerator: [
@ -97,8 +97,8 @@ export default {
initFormData() { initFormData() {
this.formData = { this.formData = {
scaleNumerator: this.scale.scaleNumerator || 1, scaleNumerator: this.scale.scaleNumerator || 1,
scaleDenominator: this.scale.scaleDenominator || 1000, scaleDenominator: this.scale.scaleDenominator || 20,
unit: this.scale.unit || 'm' unit: this.scale.unit || 'km'
}; };
}, },
closeDialog() { closeDialog() {

Loading…
Cancel
Save