menghao 1 month ago
parent
commit
f63b8d16a6
  1. 212
      ruoyi-ui/src/views/cesiumMap/index.vue

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

@ -40,14 +40,11 @@
@show-transform-box="showPlatformIconTransformBox"
@toggle-route-label="toggleRouteLabelVisibility"
@toggle-route-lock="toggleRouteLock"
<<<<<<< HEAD
@edit-platform="openEditPlatformDialog"
@power-zone="openPowerZoneDialog"
=======
@start-route-before-platform="handleStartRouteBeforePlatform"
@start-route-after-platform="handleStartRouteAfterPlatform"
@copy-route="handleCopyRouteFromMenu"
>>>>>>> 9363256d79ba1d213479769fa0a97c737d179e32
@edit-platform="openEditPlatformDialog"
@power-zone="openPowerZoneDialog"
/>
<!-- 定位弹窗 -->
@ -136,7 +133,7 @@
/>
</el-form-item>
<el-form-item label="填充颜色">
<el-color-picker v-model="powerZoneForm.color" show-alpha size="small" />
<el-color-picker v-model="powerZoneForm.color" show-alpha size="small" />
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
@ -291,16 +288,13 @@ export default {
},
// 线routeId -> true / false
routeLabelVisible: {},
<<<<<<< HEAD
// 线routeId -> { fontSize, fontColor }
routeLabelStyles: {},
// 线routeId -> true / false
routeLocked: {},
=======
// 线 prop routeLocked
// 线{ platformInfo: { platformId, platform }, mode: 'before'|'after' }
platformRouteDrawing: null,
>>>>>>> 9363256d79ba1d213479769fa0a97c737d179e32
//
defaultStyles: {
point: { color: '#FF0000', size: 12 },
@ -1031,11 +1025,11 @@ export default {
canvas.height = img.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
//
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const data = imageData.data;
//
for(let i = 0; i < data.length; i += 4) {
// Alpha > 0
@ -1046,7 +1040,7 @@ export default {
// Alpha
}
}
ctx.putImageData(imageData, 0, 0);
resolve(canvas); // Cesium 使 Canvas
} catch (e) {
@ -1074,19 +1068,19 @@ export default {
*/
createRoundedLabelCanvas(options) {
const { name, altitude, speed, heading, fontSize = 16, fontColor = '#000000' } = options;
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
//
const font = `${fontSize}px "Microsoft YaHei"`;
ctx.font = font;
//
const colorName = '#0078FF'; //
const colorLabel = '#888888'; //
const colorValue = fontColor; //
//
const labelAlt = '高度: ';
const labelSpeed = ' 速度: ';
@ -1097,13 +1091,13 @@ export default {
//
const wName = ctx.measureText(name).width;
const wLabelAlt = ctx.measureText(labelAlt).width;
const wValAlt = ctx.measureText(textAlt).width;
const wLabelSpeed = ctx.measureText(labelSpeed).width;
const wValSpeed = ctx.measureText(textSpeed).width;
const wLabelHeading = ctx.measureText(labelHeading).width;
const wValHeading = ctx.measureText(textHeading).width;
@ -1112,7 +1106,7 @@ export default {
// + +
const line1Width = wName;
const line2Width = wLabelAlt + wValAlt + wLabelSpeed + wValSpeed + wLabelHeading + wValHeading;
const paddingX = 12;
const paddingY = 8;
const lineHeight = fontSize * 1.4;
@ -1122,7 +1116,7 @@ export default {
// Canvas (Cesium Billboard )
canvas.width = totalWidth;
canvas.height = totalHeight;
// width context
ctx.font = font;
ctx.textBaseline = 'top';
@ -1142,7 +1136,7 @@ export default {
ctx.quadraticCurveTo(0, 0, r, 0);
ctx.closePath();
ctx.fill();
//
ctx.strokeStyle = '#e0e0e0';
ctx.lineWidth = 1;
@ -1163,7 +1157,7 @@ export default {
ctx.fillStyle = colorLabel;
ctx.fillText(labelAlt, currentX, line2Y);
currentX += wLabelAlt;
ctx.fillStyle = colorValue;
ctx.fillText(textAlt, currentX, line2Y);
currentX += wValAlt;
@ -1172,7 +1166,7 @@ export default {
ctx.fillStyle = colorLabel;
ctx.fillText(labelSpeed, currentX, line2Y);
currentX += wLabelSpeed;
ctx.fillStyle = colorValue;
ctx.fillText(textSpeed, currentX, line2Y);
currentX += wValSpeed;
@ -1181,7 +1175,7 @@ export default {
ctx.fillStyle = colorLabel;
ctx.fillText(labelHeading, currentX, line2Y);
currentX += wLabelHeading;
ctx.fillStyle = colorValue;
ctx.fillText(textHeading, currentX, line2Y);
@ -1642,7 +1636,7 @@ export default {
// target.billboard.color WHITE
// ""
// ""
//
if (this.viewer.scene.requestRenderMode) {
this.viewer.scene.requestRender();
@ -1664,10 +1658,10 @@ export default {
headingDeg: initialHeadingDeg
});
const labelShow = this.routeLabelVisible[routeId] !== false
//
if (!this.routeLabelStyles[routeId]) {
this.$set(this.routeLabelStyles, routeId, { fontSize: 16, fontColor: '#000000' });
this.$set(this.routeLabelStyles, routeId, { fontSize: 16, fontColor: '#000000' });
}
const currentStyle = this.routeLabelStyles[routeId];
@ -1698,10 +1692,10 @@ export default {
});
// 使
labelEntity.labelDataCache = {
name: (platform && platform.name) || '平台',
altitude: firstAlt,
speed: firstSpeed,
headingDeg: initialHeadingDeg
name: (platform && platform.name) || '平台',
altitude: firstAlt,
speed: firstSpeed,
headingDeg: initialHeadingDeg
};
}
// 线
@ -2333,62 +2327,62 @@ 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;
}
// 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 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();
}
} else if (labelEntity.label) {
labelEntity.label.text = this.formatPlatformLabelText(labelData);
labelEntity.label.text = this.formatPlatformLabelText(labelData);
}
}
}
@ -5245,15 +5239,15 @@ export default {
return
}
const routeId = ed.routeId
//
const labelEntity = this.viewer.entities.getById(`route-platform-label-${routeId}`)
let fontSize = 16
let fontColor = '#333333'
if (this.routeLabelStyles[routeId]) {
fontSize = this.routeLabelStyles[routeId].fontSize;
fontColor = this.routeLabelStyles[routeId].fontColor;
fontSize = this.routeLabelStyles[routeId].fontSize;
fontColor = this.routeLabelStyles[routeId].fontColor;
} else if (labelEntity && labelEntity.label) {
const now = Cesium.JulianDate.now()
const fontValue = labelEntity.label.font && labelEntity.label.font.getValue
@ -5296,7 +5290,7 @@ export default {
this.editPlatformForm.fontColor = fontColor
this.editPlatformForm.iconSize = iconSize
this.editPlatformForm.iconColor = iconColor
this.contextMenu.visible = false
this.editPlatformDialogVisible = true
},
@ -5315,7 +5309,7 @@ export default {
this.editPlatformDialogVisible = false
return
}
//
const fontSize = Math.max(10, Math.min(32, Number(this.editPlatformForm.fontSize) || 16));
const fontColor = this.editPlatformForm.fontColor || '#333333';
@ -5325,23 +5319,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 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);
} else if (labelEntity.label) {
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.font = `${fontSize}px Microsoft YaHei`
labelEntity.label.fillColor = Cesium.Color.fromCssColorString(fontColor)
//
labelEntity.label.backgroundColor = Cesium.Color.fromCssColorString('rgba(255, 255, 255, 0.6)')
}
}
@ -5394,7 +5388,7 @@ export default {
this.powerZoneDialogVisible = false
return
}
//
const oldZoneId = `power-zone-${routeId}`
this.viewer.entities.removeById(oldZoneId)

Loading…
Cancel
Save