Browse Source

平台初始颜色

master
cuitw 1 month ago
parent
commit
b76509a1fe
  1. 50
      ruoyi-ui/src/views/cesiumMap/index.vue

50
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),
@ -2358,7 +2359,7 @@ export default {
return;
}
const canvas = this.createRoundedLabelCanvas({
const labelResult = this.createRoundedLabelCanvas({
name: displayData.name,
altitude: displayData.altitude,
speed: displayData.speed,
@ -2366,8 +2367,8 @@ export default {
fontSize: style.fontSize,
fontColor: style.fontColor
});
// canvas ConstantProperty Cesium
labelEntity.billboard.image = canvas;
labelEntity.billboard.image = labelResult.canvas;
labelEntity.billboard.scale = labelResult.scale;
//
labelEntity._lastRenderParams = {
@ -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: {
@ -5320,7 +5324,7 @@ export default {
if (labelEntity) {
if (labelEntity.billboard) {
const data = labelEntity.labelDataCache || { name: '平台', altitude: 0, speed: 0, headingDeg: 0 };
const canvas = this.createRoundedLabelCanvas({
const labelResult = this.createRoundedLabelCanvas({
name: data.name,
altitude: data.altitude,
speed: data.speed,
@ -5328,8 +5332,8 @@ export default {
fontSize: fontSize,
fontColor: fontColor
});
// 使 ConstantProperty
labelEntity.billboard.image = new Cesium.ConstantProperty(canvas);
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)

Loading…
Cancel
Save