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

Loading…
Cancel
Save