Browse Source

Merge branch 'ctw' of http://124.70.32.114:3100/woka/cesium-map-object into mh

# Conflicts:
#	ruoyi-ui/src/views/cesiumMap/ContextMenu.vue
#	ruoyi-ui/src/views/cesiumMap/index.vue
mh
menghao 1 month ago
parent
commit
9544fd9bb1
  1. 8
      ruoyi-ui/src/views/cesiumMap/ContextMenu.vue
  2. 164
      ruoyi-ui/src/views/cesiumMap/index.vue

8
ruoyi-ui/src/views/cesiumMap/ContextMenu.vue

@ -429,6 +429,10 @@ export default {
this.$emit('toggle-route-lock')
},
handleCopyRoute() {
this.$emit('copy-route')
},
handleEditPlatform() {
this.$emit('edit-platform')
},
@ -437,10 +441,6 @@ export default {
this.$emit('power-zone')
},
handleCopyRoute() {
this.$emit('copy-route')
},
toggleColorPicker(property) {
if (this.showColorPickerFor === property) {
this.showColorPickerFor = null

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

@ -1064,15 +1064,17 @@ export default {
* @param {string} options.heading 航向值
* @param {number} options.fontSize 字号默认 16
* @param {string} options.fontColor 属性值颜色默认黑色
* @returns {HTMLCanvasElement}
* @returns {{ canvas: HTMLCanvasElement, scale: number }} 高分屏下 scale billboard.scale 使用以保持视觉尺寸
*/
createRoundedLabelCanvas(options) {
const { name, altitude, speed, heading, fontSize = 16, fontColor = '#000000' } = options;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// billboard.scale
const dpr = Math.min(2, window.devicePixelRatio || 1);
//
//
const font = `${fontSize}px "Microsoft YaHei"`;
ctx.font = font;
@ -1089,7 +1091,7 @@ export default {
const textSpeed = speed + 'km/h';
const textHeading = Math.round(heading) + '°';
//
//
const wName = ctx.measureText(name).width;
const wLabelAlt = ctx.measureText(labelAlt).width;
@ -1101,9 +1103,7 @@ export default {
const wLabelHeading = ctx.measureText(labelHeading).width;
const wValHeading = ctx.measureText(textHeading).width;
//
//
// + +
//
const line1Width = wName;
const line2Width = wLabelAlt + wValAlt + wLabelSpeed + wValSpeed + wLabelHeading + wValHeading;
@ -1113,9 +1113,10 @@ export default {
const totalWidth = Math.max(line1Width, line2Width) + paddingX * 2;
const totalHeight = lineHeight * 2 + paddingY * 2;
// Canvas (Cesium Billboard )
canvas.width = totalWidth;
canvas.height = totalHeight;
// Canvas dpr scale
canvas.width = Math.ceil(totalWidth * dpr);
canvas.height = Math.ceil(totalHeight * dpr);
ctx.scale(dpr, dpr);
// width context
ctx.font = font;
@ -1179,7 +1180,8 @@ export default {
ctx.fillStyle = colorValue;
ctx.fillText(textHeading, currentX, line2Y);
return canvas;
// canvas billboard scale
return { canvas, scale: 1 / dpr };
},
/** 伸缩框旋转手柄图标 SVG:蓝底、白边、白色弧形箭头 */
@ -1619,7 +1621,7 @@ export default {
image: fullUrl,
width: 144,
height: 144,
color: Cesium.Color.WHITE, //
color: Cesium.Color.BLACK, // 线
verticalOrigin: Cesium.VerticalOrigin.CENTER,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
scaleByDistance: new Cesium.NearFarScalar(500, 2.0, 200000, 0.4),
@ -1633,9 +1635,7 @@ export default {
const target = this.viewer.entities.getById(platformBillboardId);
if (target && target.billboard) {
target.billboard.image = whiteImage;
// target.billboard.color WHITE
// ""
// ""
// target.billboard.color BLACK线
//
if (this.viewer.scene.requestRenderMode) {
@ -1665,8 +1665,8 @@ export default {
}
const currentStyle = this.routeLabelStyles[routeId];
// 使 Canvas
const labelCanvas = this.createRoundedLabelCanvas({
// 使 Canvas scale
const labelResult = this.createRoundedLabelCanvas({
name: (platform && platform.name) || '平台',
altitude: firstAlt,
speed: firstSpeed,
@ -1682,7 +1682,8 @@ export default {
show: labelShow,
properties: { routeId: routeId },
billboard: {
image: labelCanvas, // 使 Canvas
image: labelResult.canvas,
scale: labelResult.scale,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
pixelOffset: new Cesium.Cartesian2(0, -42),
@ -2327,60 +2328,60 @@ export default {
Object.assign(labelEntity.labelDataCache, labelData);
if (labelEntity.billboard) {
const style = this.routeLabelStyles[routeId] || { fontSize: 16, fontColor: '#000000' };
//
const displayData = {
name: labelData.name || '平台',
altitude: Math.round(Number(labelData.altitude || 0)),
speed: Math.round(Number(labelData.speed || 0)),
heading: Math.round(Number(labelData.headingDeg || 0))
};
//
const last = labelEntity._lastRenderParams;
const now = Date.now();
// 1000ms
// position
if (last &&
last.name === displayData.name &&
last.altitude === displayData.altitude &&
last.speed === displayData.speed &&
last.heading === displayData.heading &&
last.fontSize === style.fontSize &&
last.fontColor === style.fontColor) {
//
return;
}
const style = this.routeLabelStyles[routeId] || { fontSize: 16, fontColor: '#000000' };
//
const displayData = {
name: labelData.name || '平台',
altitude: Math.round(Number(labelData.altitude || 0)),
speed: Math.round(Number(labelData.speed || 0)),
heading: Math.round(Number(labelData.headingDeg || 0))
};
//
const last = labelEntity._lastRenderParams;
const now = Date.now();
// 1000ms
// position
if (last &&
last.name === displayData.name &&
last.altitude === displayData.altitude &&
last.speed === displayData.speed &&
last.heading === displayData.heading &&
last.fontSize === style.fontSize &&
last.fontColor === style.fontColor) {
//
return;
}
// 1
if (last && (now - (labelEntity._lastUpdateTime || 0) < 1000)) {
return;
}
const canvas = this.createRoundedLabelCanvas({
name: displayData.name,
altitude: displayData.altitude,
speed: displayData.speed,
heading: displayData.heading,
fontSize: style.fontSize,
fontColor: style.fontColor
});
// canvas ConstantProperty Cesium
labelEntity.billboard.image = canvas;
//
labelEntity._lastRenderParams = {
...displayData,
fontSize: style.fontSize,
fontColor: style.fontColor
};
labelEntity._lastUpdateTime = now;
// requestRenderMode
if (this.viewer.scene.requestRenderMode) {
this.viewer.scene.requestRender();
}
const labelResult = this.createRoundedLabelCanvas({
name: displayData.name,
altitude: displayData.altitude,
speed: displayData.speed,
heading: displayData.heading,
fontSize: style.fontSize,
fontColor: style.fontColor
});
labelEntity.billboard.image = labelResult.canvas;
labelEntity.billboard.scale = labelResult.scale;
//
labelEntity._lastRenderParams = {
...displayData,
fontSize: style.fontSize,
fontColor: style.fontColor
};
labelEntity._lastUpdateTime = now;
// requestRenderMode
if (this.viewer.scene.requestRenderMode) {
this.viewer.scene.requestRender();
}
} else if (labelEntity.label) {
labelEntity.label.text = this.formatPlatformLabelText(labelData);
}
@ -2407,6 +2408,8 @@ export default {
// Cesium
Cesium.buildModuleUrl.setBaseUrl(window.CESIUM_BASE_URL)
Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjN2MzMmE5OS01NGU3LTQzOGQtYjdjZi1mNGIwZTFjZjQ0NmEiLCJpZCI6MTQ0MDc2LCJpYXQiOjE2ODU3NjY1OTN9.iCmFY-5WNdvyAT-EO2j-unrFm4ZN9J6aSuB2wElQZ-I'
// 使 2
const resolutionScale = Math.min(2, window.devicePixelRatio || 1);
this.viewer = new Cesium.Viewer('cesiumViewer', {
animation: false,
fullscreenButton: false,
@ -2424,6 +2427,7 @@ export default {
imageryProvider: false,
terrainProvider: new Cesium.EllipsoidTerrainProvider(),
baseLayer: false,
resolutionScale,
requestRenderMode: true,
maximumRenderTimeChange: Infinity,
contextOptions: {
@ -5319,23 +5323,23 @@ export default {
const labelEntity = this.viewer.entities.getById(`route-platform-label-${routeId}`)
if (labelEntity) {
if (labelEntity.billboard) {
const data = labelEntity.labelDataCache || { name: '平台', altitude: 0, speed: 0, headingDeg: 0 };
const canvas = this.createRoundedLabelCanvas({
name: data.name,
altitude: data.altitude,
speed: data.speed,
heading: data.headingDeg,
fontSize: fontSize,
fontColor: fontColor
});
// 使 ConstantProperty
labelEntity.billboard.image = new Cesium.ConstantProperty(canvas);
const data = labelEntity.labelDataCache || { name: '平台', altitude: 0, speed: 0, headingDeg: 0 };
const labelResult = this.createRoundedLabelCanvas({
name: data.name,
altitude: data.altitude,
speed: data.speed,
heading: data.headingDeg,
fontSize: fontSize,
fontColor: fontColor
});
labelEntity.billboard.image = new Cesium.ConstantProperty(labelResult.canvas);
labelEntity.billboard.scale = labelResult.scale;
} else if (labelEntity.label) {
labelEntity.label.font = `${fontSize}px Microsoft YaHei`
labelEntity.label.fillColor = Cesium.Color.fromCssColorString(fontColor)
labelEntity.label.font = `${fontSize}px Microsoft YaHei`
labelEntity.label.fillColor = Cesium.Color.fromCssColorString(fontColor)
//
labelEntity.label.backgroundColor = Cesium.Color.fromCssColorString('rgba(255, 255, 255, 0.6)')
//
labelEntity.label.backgroundColor = Cesium.Color.fromCssColorString('rgba(255, 255, 255, 0.6)')
}
}

Loading…
Cancel
Save