index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <pannel class="fence-location-container">
  3. <template v-slot:title>
  4. 围栏闯禁
  5. </template>
  6. <template v-slot:action>
  7. <i
  8. class="el-icon-plus"
  9. title="清空所有轨迹"
  10. @click="clearAll"
  11. />
  12. </template>
  13. <template v-slot:content>
  14. <template v-if="!editState">
  15. <div>
  16. </div>
  17. </template>
  18. </template>
  19. </pannel>
  20. </template>
  21. <script>
  22. import Pannel from '@/views/bd/pannel/index.vue';
  23. // this.drawtool = new BDLayers.Lib.Tools.CBDrawTool('mytool', this.mapView, 'Rectangle', true); // 绘制矩形,参数1:id,参数2:地图,参数3:绘制类型,参数4:是否可拖拽编辑
  24. // this.drawtool.enable(); // 开始绘制
  25. // this.drawtool.disable(); // 结束绘制
  26. // this.drawtool.clear(); // 清除绘制内容
  27. // this.drawtool.setDrawMode(type); // 设置绘制类型
  28. // this.drawtool.on('drawend', (geom) => {}) // 绘制结束事件
  29. // this.drawtool.on('selectDraw', geom => {}) // 绘制完毕后选择绘制图形
  30. export default {
  31. name: 'fence',
  32. components: { Pannel },
  33. data() {
  34. return {
  35. playItem: {},
  36. editState: false,
  37. editPolyInfo: {},
  38. };
  39. },
  40. // 组件卸载前清空图层信息
  41. beforeDestroy() {
  42. },
  43. created() {
  44. },
  45. mounted() {
  46. this.getFenceList();
  47. },
  48. methods: {
  49. getFenceList() {
  50. const vlayer = new BDLayers.Lib.Layer.CBVectorLayer('vl');
  51. window.map.addCustomLayers(vlayer);
  52. const polygon = new BDLayers.Lib.Overlays.Polygon('p1', {
  53. coordinates: [
  54. [
  55. [118.86318437, 31.52265586],
  56. [118.86265566, 31.52228823],
  57. [118.86086721, 31.52109704],
  58. [118.85828955, 31.51855584],
  59. [118.85609438, 31.51526213],
  60. [118.8532821, 31.5110545],
  61. [118.85176272, 31.5086165],
  62. [118.85066095, 31.50684702],
  63. [118.8475185, 31.50462126],
  64. [118.84380357, 31.50436705],
  65. [118.84167739, 31.50515526],
  66. [118.84092182, 31.50623378],
  67. [118.84056598, 31.50775093],
  68. [118.84080926, 31.51001804],
  69. [118.84122597, 31.5112316],
  70. [118.84243213, 31.51333141],
  71. [118.84423733, 31.51633511],
  72. [118.84663359, 31.5190328],
  73. [118.84861203, 31.52112279],
  74. [118.85080872, 31.52367],
  75. [118.85279596, 31.52591382],
  76. [118.85515677, 31.52739321],
  77. [118.85829864, 31.52901656],
  78. [118.86102371, 31.52928225],
  79. [118.86335805, 31.52894132],
  80. [118.86548497, 31.52815403],
  81. [118.86624005, 31.52693407],
  82. [118.86620514, 31.52541921],
  83. [118.86520697, 31.52406319],
  84. [118.86318437, 31.52265586],
  85. ],
  86. ],
  87. symbol: {
  88. lineColor: '#34495e',
  89. lineWidth: 2,
  90. polygonFill: '#1bbc9b',
  91. polygonOpacity: 0.4,
  92. },
  93. labelSymbol: {
  94. labelText: '多边形',
  95. labelTextSize: 10,
  96. },
  97. bizAttr: {
  98. name: '围栏名称',
  99. },
  100. });
  101. // 地图绘制工具
  102. const drawtool = new BDLayers.Lib.Tools.CBDrawTool('myTool', window.map, 'Polygon', true);
  103. let editingDrawGeom = null;
  104. //多边形的点击事件
  105. polygon.on('click', (data) => {
  106. console.log(data.target.options);
  107. if (this.editState) {
  108. return;
  109. }
  110. editingDrawGeom = data.target.geometry ? data.target.geometry : data.target.geom
  111. ? data.target.geom
  112. : data.target;
  113. this.$confirm('检测到选中了围栏,请选择操作类型?', '提示', {
  114. confirmButtonText: '编辑围栏',
  115. cancelButtonText: '删除围栏',
  116. type: 'warning',
  117. }).then(() => {
  118. // 开始编辑围栏
  119. this.editState = true;
  120. editingDrawGeom.startEdit();
  121. }).catch(() => {
  122. editingDrawGeom.remove();
  123. this.editState = false;
  124. editingDrawGeom = null;
  125. this.$message({
  126. type: 'info',
  127. message: '删除围栏',
  128. });
  129. });
  130. // 点击地图 图形取消编辑状态
  131. window.map.map.once('click', () => {
  132. editingDrawGeom.endEdit();
  133. this.$confirm('检测到未保存的内容,是否保存修改?', '提示', {
  134. confirmButtonText: '保存',
  135. cancelButtonText: '放弃修改',
  136. type: 'warning',
  137. }).then(() => {
  138. debugger
  139. this.$message({
  140. type: 'success',
  141. message: '保存!',
  142. });
  143. editingDrawGeom = null;
  144. this.editState = false;
  145. }).catch(() => {
  146. });
  147. });
  148. });
  149. vlayer.addGeometry(polygon);
  150. vlayer.addGeometry(polygon1);
  151. window.map.flyToPoint([118.86318437, 31.52265586], {
  152. zoom: 13,
  153. pitch: 0,
  154. bearing: 20,
  155. duration: 5000,
  156. });
  157. // 监听图形编辑
  158. // drawtool.on('selectDraw', geom => {
  159. // editingDrawGeom = geom.target.geometry ? geom.target.geometry : geom.target.geom
  160. // ? geom.target.geom
  161. // : geom.target;
  162. // if (editingDrawGeom.isEditing && editingDrawGeom.isEditing()) {
  163. // // 点击地图 图形取消编辑状态
  164. // window.map.map.once('click', function () {
  165. // editingDrawGeom.endEdit();
  166. // editingDrawGeom = null;
  167. // });
  168. // } else {
  169. // window.map.map.once('click', function () {
  170. // editingDrawGeom = null;
  171. // });
  172. // }
  173. // });
  174. },
  175. clearAll() {
  176. },
  177. },
  178. };
  179. </script>
  180. <style lang="scss" src="./index.scss" />