mapSetting.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <tlbs-map ref="mapRef" api-key="KFEBZ-P2GKZ-A5PX4-7Q6Y7-KXOBF-XCB4C" :center="center" :zoom="zoom"
  3. :control="control" @click="handleClick" @map_inited="onMapInited">
  4. <div style="position: absolute;top: 0;left: 0;z-index: 2000;">
  5. <button @click.stop="mode = 'draw'">
  6. 设置绘制模式
  7. </button>
  8. <button @click.stop="mode = 'edit'">
  9. 设置编辑模式
  10. </button>
  11. <button @click.stop="activeId = 'polygon'">
  12. 设置画多边形
  13. </button>
  14. <button @click.stop="activeId = 'circle'">
  15. 设置画圆形
  16. </button>
  17. <button @click.stop="getOverlayList">
  18. 获取图层列表
  19. </button>
  20. <button @click.stop="onSelectGeometry">
  21. 选中图形
  22. </button>
  23. <button @click.stop="onGetSelectedList">
  24. 获取选中集合图形
  25. </button>
  26. <button @click.stop="onClear">
  27. 清空选中
  28. </button>
  29. </div>
  30. <!--vue2使用:active-overlay-id.sync="activeId" -->
  31. <tlbs-geometry-editor ref="editorRef" v-model:active-overlay-id="activeId" :action-mode="mode"
  32. polygon-id="polygon" :default-polygon-geometries="geometries" :polygon-styles="styles" selectable
  33. @select="onSelect" @draw_complete="onDrowComplet" @adjust_complete="onAdjustComplete"
  34. @draw_error="onDrawError" />
  35. </tlbs-map>
  36. </template>
  37. <script setup>
  38. import { ref, watch } from 'vue';
  39. import { onMounted } from 'vue';
  40. import { getMapCoder } from '@/api/map';
  41. const paths = [
  42. { lat: 40.041117253378246, lng: 116.2722415837743 },
  43. { lat: 40.03942536171407, lng: 116.2726277820093 },
  44. { lat: 40.03970460886076, lng: 116.27483769345417 },
  45. { lat: 40.041404706498625, lng: 116.27443003983899 },
  46. ];
  47. const mapRef = ref(null);
  48. const center = ref({ lat: 40.040452, lng: 116.273486 });
  49. const zoom = ref(17);
  50. const editorRef = ref(null);
  51. const mode = ref('edit');
  52. const activeId = ref('polygon');
  53. const onToggleMode = () => {
  54. mode.value = mode.value === 'draw' ? 'edit' : 'draw';
  55. };
  56. const onSelect = (e) => {
  57. console.log('select', e);
  58. };
  59. const onDrowComplet = (geomeytry) => {
  60. console.log(geomeytry);
  61. };
  62. const onAdjustComplete = (geomeytry) => {
  63. console.log(geomeytry);
  64. };
  65. const onDrawError = (e) => {
  66. console.log(e);
  67. };
  68. const getOverlayList = () => {
  69. console.log(editorRef.value.editor.getOverlayList());
  70. };
  71. const onMapInited = () => {
  72. // 地图加载完成后,可以获取地图实例,调用地图实例方法
  73. console.log(mapRef.value.map);
  74. };
  75. const control = {
  76. scale: {},
  77. zoom: {
  78. position: 'topRight',
  79. },
  80. }
  81. const geometries = [
  82. {
  83. id: 'firstPolygon',
  84. styleId: 'polygon', // 样式id
  85. paths, // 多边形的位置信息
  86. properties: {
  87. // 多边形的属性数据
  88. title: 'polygon',
  89. },
  90. },
  91. ]
  92. const styles = {
  93. polygon: {
  94. color: '#3777FF', // 面填充色
  95. showBorder: false, // 是否显示拔起面的边线
  96. borderColor: '#00FFFF', // 边线颜色
  97. },
  98. }
  99. function handleClick(e) {
  100. console.log(e);
  101. }
  102. function onClear() {
  103. editorRef.value.editor.select([]);
  104. }
  105. function onSelectGeometry() {
  106. editorRef.value.editor.select(['firstPolygon']);
  107. }
  108. function onGetSelectedList() {
  109. console.log(editorRef.value.editor.getSelectedList());
  110. }
  111. </script>
  112. <style>
  113. .map-container {
  114. width: 100%;
  115. height: 100%;
  116. }
  117. </style>
  118. <style scoped>
  119. .control-container {
  120. position: absolute;
  121. top: 0;
  122. left: 0;
  123. z-index: 1001;
  124. display: flex;
  125. align-items: center;
  126. }
  127. button {
  128. padding: 4px;
  129. background-color: #fff;
  130. margin-right: 5px;
  131. border: 1px solid #ddd;
  132. }
  133. </style>