DrawMap.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="tool-bar glass">
  3. <button @click="startDraw('point')">🟢 绘点</button>
  4. <button @click="startDraw('line')">📏 绘线</button>
  5. <button @click="startDraw('polygon')">🔷 绘面</button>
  6. <button @click="startDraw('circle')">⭕ 绘圆</button>
  7. <button @click="startDraw('rectangle')"><span style="display: inline-block; transform: rotate(45deg);">🔷</span> 矩形</button>
  8. <button @click="startDraw('distance')">📏 测距</button>
  9. <button @click="startDraw('area')">🔷 测面</button>
  10. <!-- <button @click="toggleEditMode" :class="{ active: isEditMode }" :disabled="isEditDisabled">✏️ 编辑</button> -->
  11. <button @click="clearAll">🗑️ 清空</button>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. name: "DrawMap",
  17. components: {
  18. },
  19. data() {
  20. return {
  21. mapDraw: null,
  22. isEditDisabled: false, // 是否禁用编辑功能
  23. isEditMode: false, // 编辑模式
  24. };
  25. },
  26. mounted() {
  27. let that = this;
  28. that.initData();
  29. },
  30. methods: {
  31. initData() {
  32. let that = this;
  33. window.mapboxMap.on('load', function() {
  34. // 初始化
  35. // that.mapDraw = new MapDraw.init(window.mapboxMap, {
  36. // 编辑完成 → 自动接收最新图形
  37. // onEditComplete: (data) => {
  38. // console.log("返回数据:", data);
  39. // // 你可以在这里提交后端接口,将数据保存到数据库
  40. // that.updateContent(data);
  41. // },
  42. // });
  43. // console.log("mapDraw:", that.mapDraw);
  44. that.mapDraw = window.mapEditDraw;
  45. })
  46. },
  47. // 开始绘制
  48. startDraw(type) {
  49. let that = this;
  50. that.mapDraw.startDraw(type);
  51. },
  52. // 切换编辑模式
  53. toggleEditMode() {
  54. let that = this;
  55. that.isEditMode = !that.isEditMode;
  56. that.mapDraw.isEditDrawTool(that.isEditMode);
  57. },
  58. // 清空所有图形
  59. clearAll() {
  60. let that = this;
  61. that.mapDraw.clearAll();
  62. },
  63. }
  64. };
  65. </script>
  66. <style lang="less" scoped>
  67. /* 工具栏 + 玻璃样式 */
  68. .tool-bar {
  69. position: absolute;
  70. top: 60px;
  71. right: 0px;
  72. z-index: 999;
  73. padding: 12px 10px;
  74. display: grid;
  75. gap: 5px;
  76. width: 80px;
  77. }
  78. .tool-bar button {
  79. padding: 8px;
  80. background: rgba(255,255,255,1);
  81. border: 1px solid rgba(255,255,255,0.3);
  82. border-radius: 8px;
  83. color: #222;
  84. cursor: pointer;
  85. transition: all 0.2s;
  86. -webkit-backdrop-filter: blur(10px);
  87. backdrop-filter: blur(10px);
  88. }
  89. .tool-bar button:hover {
  90. background: rgba(255,255,255,0.8);
  91. }
  92. .tool-bar button.active {
  93. background: rgba(0,102,255,0.8);
  94. color: white;
  95. }
  96. .tool-bar button:disabled {
  97. opacity: 0.5;
  98. cursor: not-allowed;
  99. }
  100. </style>
  101. <style>
  102. /*节点标签样式 */
  103. .marker-label-tips {
  104. position: absolute;
  105. background: #0066ff;
  106. color: white;
  107. padding: 4px 10px;
  108. border-radius: 4px;
  109. font-size: 14px;
  110. pointer-events: none; /* 不影响鼠标悬浮 */
  111. transform: translate(-50%, -50%);
  112. white-space: nowrap;
  113. }
  114. /* 编辑标记样式 */
  115. .edit-marker {
  116. z-index: 2;
  117. cursor: pointer;
  118. }
  119. </style>