VideoOn.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!-- eslint-disable prettier/prettier -->
  2. <template>
  3. <el-card style="overflow: auto">
  4. <el-input style="margin-top: 10px" v-model="videoUrl">
  5. <template #prepend> 视频地址 </template>
  6. </el-input>
  7. <el-button-group>
  8. <el-button type="primary" text :icon="Edit" @click="videoClick"
  9. >视频融合</el-button
  10. >
  11. <el-button type="primary" text :icon="Delete" @click="clearVideoClick"
  12. >清除</el-button
  13. >
  14. </el-button-group>
  15. </el-card>
  16. <video id="myVideo" muted="" autoplay="" loop="" crossorigin="" controls="">
  17. <source :src="videoUrl" type="video/webm" />
  18. </video>
  19. </template>
  20. <script lang="ts" setup>
  21. import { Delete, Edit } from "@element-plus/icons-vue";
  22. import { ref, onMounted } from "vue";
  23. import emitter from "@/mitt";
  24. import { Rectangle } from "../../plot/graphicsDraw/areaDraw";
  25. import { VideoSynchronizer } from "cesium";
  26. const videoUrl = ref(
  27. "http://localhost:8091/Videos/big-buck-bunny-trailer-small.webm"
  28. );
  29. var rect: Rectangle | null = new Rectangle();
  30. let videoEntity;
  31. function videoClick() {
  32. rect = new Rectangle();
  33. rect.startDraw();
  34. emitter.on("drawEnd", VideoOn);
  35. }
  36. function clearVideoClick() {
  37. window.Viewer.entities.remove(videoEntity);
  38. rect.disable();
  39. rect = null;
  40. videoEntity = null;
  41. emitter.off("drawEnd", VideoOn);
  42. }
  43. let videoElement;
  44. onMounted(() => {
  45. videoElement = document.getElementById("myVideo");
  46. videoElement.style.display = "none";
  47. new VideoSynchronizer({
  48. clock: window.Viewer.clock,
  49. element: videoElement,
  50. });
  51. });
  52. function VideoOn() {
  53. setTimeout(() => {
  54. videoEntity = window.Viewer.entities.add({
  55. rectangle: {
  56. coordinates: rect.areaPrimitive.geometryInstances.geometry.rectangle,
  57. material: videoElement,
  58. },
  59. });
  60. if (rect.areaPrimitive) {
  61. window.Viewer.scene.groundPrimitives.remove(rect.areaPrimitive);
  62. }
  63. window.Viewer.clock.shouldAnimate = true;
  64. }, 300);
  65. }
  66. </script>
  67. <style lang="scss" scoped></style>